Exemple #1
0
    def testDungeonRoomsRooms(self):
        m = Maze()
        m.generator = DungeonRooms(4, 4, rooms=[[(1, 1), (3, 3)]])
        m.generate()

        self.assertTrue(self.boundary_is_solid(m.grid))
        self.assertTrue(self.all_passages_open(m.grid))
Exemple #2
0
    def test_dungeon_rooms_serpentine_rooms(self):
        m = Maze()
        m.generator = DungeonRooms(4,
                                   4,
                                   rooms=[[(1, 1), (3, 3)]],
                                   hunt_order='serpentine')
        m.generate()

        self.assertTrue(boundary_is_solid(m.grid))
        self.assertTrue(all_passages_open(m.grid))
    def test_dungeon_rooms_serpentine_rooms(self):
        """ test DungeonRooms mazes are reasonably when generating some random rooms in a serpentine fashion """
        m = Maze()
        m.generator = DungeonRooms(4,
                                   4,
                                   rooms=[[(1, 1), (3, 3)]],
                                   hunt_order='serpentine')
        m.generate()

        assert boundary_is_solid(m.grid)
        assert all_passages_open(m.grid)
    def test_dungeon_rooms_random_rooms(self):
        """ test Dungeon Rooms maze-creation mazes a reasonably sane maze when generating some random rooms """
        m = Maze()
        m.generator = DungeonRooms(4,
                                   4,
                                   rooms=[[(1, 1), (3, 3)]],
                                   hunt_order='random')
        m.generate()

        assert boundary_is_solid(m.grid)
        assert all_passages_open(m.grid)
Exemple #5
0
    def test_dungeon_rooms_grid(self):
        g = np.ones((7, 7), dtype=np.int8)
        g[1] = [1, 1, 1, 1, 1, 1, 1]
        g[2] = [1, 1, 1, 1, 1, 1, 1]
        g[3] = [1, 1, 0, 0, 0, 1, 1]
        g[4] = [1, 1, 0, 0, 0, 1, 1]
        g[5] = [1, 1, 0, 0, 0, 1, 1]

        m = Maze()
        m.generator = DungeonRooms(4, 4, grid=g)
        m.generate()

        self.assertTrue(boundary_is_solid(m.grid))
        self.assertTrue(all_passages_open(m.grid))
    def test_dungeon_rooms_grid(self):
        """ test Dungeon Rooms maze-creation mazes a reasonably sane maze """
        g = np.ones((7, 7), dtype=np.int8)
        g[1] = [1, 1, 1, 1, 1, 1, 1]
        g[2] = [1, 1, 1, 1, 1, 1, 1]
        g[3] = [1, 1, 0, 0, 0, 1, 1]
        g[4] = [1, 1, 0, 0, 0, 1, 1]
        g[5] = [1, 1, 0, 0, 0, 1, 1]

        m = Maze()
        m.generator = DungeonRooms(4, 4, grid=g)
        m.generate()

        assert boundary_is_solid(m.grid)
        assert all_passages_open(m.grid)
Exemple #7
0
    def generate(self,method = ["dungeon"],rooms = None,width = None,height = None):

        if width is None: width = self.width
        if height is None: width = self.height

        width = width // 2
        height = height // 2

        if method == "dungeon":
            self.maze.generator = DungeonRooms(width,height, rooms=rooms)
        elif method == "prims":
            self.maze.generator = Prims(width,height)
        else:
            raise Exception(f"Maze generation method must be in {self.options}")

        self.maze.generate()
    def __init__(self,
                 n=10,
                 cycles=3,
                 seed=np.random.randint(0, 10000),
                 state_representation='integer'):
        '''
        Initialize a maze 

        parameters : 
            n : (int) Maze has diameter 2n+1
            cycles : (int) number of blocks to remove to create cycles
            seed : (int) seed for random initialization
            state_representation : (str) how state ought to be represented for the agent
        '''

        Maze.set_seed(seed)
        m = Maze()
        m.generator = DungeonRooms(n, n)
        m.generate()
        self.grid = m.grid

        # remove some walls to create cycles
        walls = np.argwhere(self.grid[1:(2 * n), 1:(2 * n)])
        np.random.shuffle(walls)
        for i in range(cycles):
            row, col = walls[i]
            row += 1
            col += 1
            self.grid[row, col] = 0

        corners = [[1, 1], [1, 2 * n - 1], [2 * n - 1, 1],
                   [2 * n - 1, 2 * n - 1]]

        self.start = random.choice(corners)
        corners.remove(self.start)
        self.end = random.choice(corners)

        self.loc = self.start  # location of agent

        self.action_space = spaces.Discrete(4)
        if state_representation == 'integer':
            self.gen_state = self.gen_integer_state
            self.observation_space = spaces.Discrete(np.prod(self.grid.shape))
        elif state_representation == 'one_hot':
            self.gen_state = self.gen_one_hot_state
            self.observation_space = spaces.Discrete(np.prod(self.grid.shape))
            self.observation_space = spaces.Box(low=0,
                                                high=1,
                                                shape=(np.prod(
                                                    self.grid.shape), ),
                                                dtype=np.int8)
        elif state_representation == 'flat_grid':
            self.gen_state = self.gen_flat_grid_state
            self.observation_space = spaces.Box(
                low=0,
                high=5,
                shape=(np.prod(self.grid.shape), ),
                dtype=np.int8)  # not sure if this is right?
        else:
            raise NotImplementedError  # add other ways to represent state here

        self.episode_length = 0
        self.MAX_LENGTH = 1000  # episodes are cut off at this length