Exemple #1
0
    def test_invalid_inputs(self):
        """ There are several errors that should be thrown from the master Maze class,
        if the inputs given are invalid.  Let's just verify some of those.
        """
        m = Maze()

        # should not be able to generate or solve if neither algorithm was set
        self.assertRaises(AssertionError, m.generate)
        self.assertRaises(AssertionError, m.solve)

        # even if the generator algorithm is set, you have to run it
        m.generator = Prims(3, 3)
        self.assertRaises(AssertionError, m.solve)

        # the pretty-print, sring formats should fail gracefully
        m.start = (1, 1)
        m.end = (3, 3)
        self.assertEqual(str(m), '')
        self.assertEqual(repr(m), '')

        # the Monte Carlo method has a special zero-to-one input scalar
        self.assertRaises(AssertionError, m.generate_monte_carlo, True, 3,
                          -1.0)
        self.assertRaises(AssertionError, m.generate_monte_carlo, True, 3,
                          10.0)
Exemple #2
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))
    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 #4
0
    def test_cellular_automaton(self):
        m = Maze()
        m.generator = CellularAutomaton(4, 5)
        m.generate()

        self.assertTrue(boundary_is_solid(m.grid))
        self.assertTrue(all_passages_open(m.grid))
    def testCellularAutomaton(self):
        m = Maze()
        m.generator = CellularAutomaton(4, 5)
        m.generate()

        self.assertTrue(self.boundary_is_solid(m.grid))
        self.assertTrue(self.all_passages_open(m.grid))
Exemple #6
0
    def testHuntAndKill(self):
        m = Maze()
        m.generator = HuntAndKill(4, 5)
        m.generate()

        self.assertTrue(self.boundary_is_solid(m.grid))
        self.assertTrue(self.all_passages_open(m.grid))
        self.assertTrue(self.all_corners_complete(m.grid))
Exemple #7
0
    def testWilsons(self):
        m = Maze()
        m.generator = Wilsons(4, 5)
        m.generate()

        self.assertTrue(self.boundary_is_solid(m.grid))
        self.assertTrue(self.all_passages_open(m.grid))
        self.assertTrue(self.all_corners_complete(m.grid))
Exemple #8
0
    def test_hunt_and_kill_serpentine_order(self):
        m = Maze()
        m.generator = HuntAndKill(4, 5, 'serpentine')
        m.generate()

        self.assertTrue(boundary_is_solid(m.grid))
        self.assertTrue(all_passages_open(m.grid))
        self.assertTrue(all_corners_complete(m.grid))
Exemple #9
0
    def test_division(self):
        m = Maze()
        m.generator = Division(4, 5)
        m.generate()

        self.assertTrue(boundary_is_solid(m.grid))
        self.assertTrue(all_passages_open(m.grid))
        self.assertTrue(all_corners_complete(m.grid))
    def testHuntAndKill(self):
        m = Maze()
        m.generator = HuntAndKill(4, 5)
        m.generate()

        self.assertTrue(self.boundary_is_solid(m.grid))
        self.assertTrue(self.all_passages_open(m.grid))
        self.assertTrue(self.all_corners_complete(m.grid))
Exemple #11
0
    def testCellularAutomaton(self):
        m = Maze()
        m.generator = CellularAutomaton(4, 5)
        m.generate()

        self.assertTrue(self.boundary_is_solid(m.grid))
        self.assertTrue(self.all_passages_open(m.grid))
        self.assertTrue(self.all_corners_complete(m.grid))
    def testAldousBroder(self):
        m = Maze()
        m.generator = AldousBroder(4, 5)
        m.generate()

        self.assertTrue(self.boundary_is_solid(m.grid))
        self.assertTrue(self.all_passages_open(m.grid))
        self.assertTrue(self.all_corners_complete(m.grid))
Exemple #13
0
    def test_aldous_broder(self):
        m = Maze()
        m.generator = AldousBroder(4, 5)
        m.generate()

        self.assertTrue(boundary_is_solid(m.grid))
        self.assertTrue(all_passages_open(m.grid))
        self.assertTrue(all_corners_complete(m.grid))
Exemple #14
0
    def test_binary_tree(self):
        m = Maze()
        m.generator = BinaryTree(4, 5)
        m.generate()

        self.assertTrue(boundary_is_solid(m.grid))
        self.assertTrue(all_passages_open(m.grid))
        self.assertTrue(all_corners_complete(m.grid))
Exemple #15
0
    def test_backtracking_generator(self):
        m = Maze()
        m.generator = BacktrackingGenerator(4, 5)
        m.generate()

        self.assertTrue(boundary_is_solid(m.grid))
        self.assertTrue(all_passages_open(m.grid))
        self.assertTrue(all_corners_complete(m.grid))
Exemple #16
0
    def test_sidewinder(self):
        m = Maze()
        m.generator = Sidewinder(4, 5)
        m.generate()

        self.assertTrue(boundary_is_solid(m.grid))
        self.assertTrue(all_passages_open(m.grid))
        self.assertTrue(all_corners_complete(m.grid))
    def testBacktrackingGenerator(self):
        m = Maze()
        m.generator = BacktrackingGenerator(4, 5)
        m.generate()

        self.assertTrue(self.boundary_is_solid(m.grid))
        self.assertTrue(self.all_passages_open(m.grid))
        self.assertTrue(self.all_corners_complete(m.grid))
    def testGrowingTree(self):
        m = Maze()
        m.generator = GrowingTree(4, 5)
        m.generate()

        self.assertTrue(self.boundary_is_solid(m.grid))
        self.assertTrue(self.all_passages_open(m.grid))
        self.assertTrue(self.all_corners_complete(m.grid))
    def testDivision(self):
        m = Maze()
        m.generator = Division(4, 5)
        m.generate()

        self.assertTrue(self.boundary_is_solid(m.grid))
        self.assertTrue(self.all_passages_open(m.grid))
        self.assertTrue(self.all_corners_complete(m.grid))
Exemple #20
0
    def test_wilsons_serpentine_order(self):
        m = Maze()
        m.generator = Wilsons(4, 5, hunt_order='serpentine')
        m.generate()

        self.assertTrue(boundary_is_solid(m.grid))
        self.assertTrue(all_passages_open(m.grid))
        self.assertTrue(all_corners_complete(m.grid))
Exemple #21
0
    def test_cellular_automaton(self):
        """ test the Cellulator Automaton method generates a reasonably sane maze """
        m = Maze()
        m.generator = CellularAutomaton(4, 5)
        m.generate()

        assert boundary_is_solid(m.grid)
        assert all_passages_open(m.grid)
Exemple #22
0
    def test_kruskal(self):
        """ test the Kruskal method generates a reasonably sane maze """
        m = Maze()
        m.generator = Kruskal(4, 5)
        m.generate()

        assert boundary_is_solid(m.grid)
        assert all_passages_open(m.grid)
        assert all_corners_complete(m.grid)
Exemple #23
0
    def test_backtracking_generator(self):
        """ test the Backtracking method generates a reasonably sane maze """
        m = Maze()
        m.generator = BacktrackingGenerator(4, 5)
        m.generate()

        assert boundary_is_solid(m.grid)
        assert all_passages_open(m.grid)
        assert all_corners_complete(m.grid)
Exemple #24
0
    def test_aldous_broder(self):
        """ test the AlgousBroder method generates a reasonably sane maze """
        m = Maze()
        m.generator = AldousBroder(4, 5)
        m.generate()

        assert boundary_is_solid(m.grid)
        assert all_passages_open(m.grid)
        assert all_corners_complete(m.grid)
Exemple #25
0
    def test_wilsons_serpentine_order(self):
        """ test the Wilson method generates a reasonably sane maze, using the serpentine pathway """
        m = Maze()
        m.generator = Wilsons(4, 5, hunt_order='serpentine')
        m.generate()

        assert boundary_is_solid(m.grid)
        assert all_passages_open(m.grid)
        assert all_corners_complete(m.grid)
Exemple #26
0
    def test_sidewinder(self):
        """ test the Sidewinder method generates a reasonably sane maze """
        m = Maze()
        m.generator = Sidewinder(4, 5)
        m.generate()

        assert boundary_is_solid(m.grid)
        assert all_passages_open(m.grid)
        assert all_corners_complete(m.grid)
Exemple #27
0
    def test_binary_tree(self):
        """ test the Binary Tree method generates a reasonably sane maze """
        m = Maze()
        m.generator = BinaryTree(4, 5)
        m.generate()

        assert boundary_is_solid(m.grid)
        assert all_passages_open(m.grid)
        assert all_corners_complete(m.grid)
Exemple #28
0
    def test_hunt_and_kill_serpentine_order(self):
        """ test the Hunt and Kill method generates a reasonably sane maze, using the serpentine pathway """
        m = Maze()
        m.generator = HuntAndKill(4, 5, 'serpentine')
        m.generate()

        assert boundary_is_solid(m.grid)
        assert all_passages_open(m.grid)
        assert all_corners_complete(m.grid)
Exemple #29
0
    def test_division(self):
        """ test the Division method generates a reasonably sane maze """
        m = Maze()
        m.generator = Division(4, 5)
        m.generate()

        assert boundary_is_solid(m.grid)
        assert all_passages_open(m.grid)
        assert all_corners_complete(m.grid)
Exemple #30
0
    def test_trivial_maze_spiral(self):
        m = Maze()
        m.generator = TrivialMaze(4, 5)
        m.generate()

        self.assertTrue(boundary_is_solid(m.grid))
        self.assertTrue(all_passages_open(m.grid))
        self.assertTrue(all_corners_complete(m.grid))
        self.assertTrue(all_corners_complete(m.grid))
Exemple #31
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))
Exemple #32
0
    def test_trivial_maze_spiral(self):
        """ test that the trivial/spiral maze is reasonably sane """
        m = Maze()
        m.generator = TrivialMaze(4, 5)
        m.generate()

        assert boundary_is_solid(m.grid)
        assert all_passages_open(m.grid)
        assert all_corners_complete(m.grid)
        assert all_corners_complete(m.grid)
Exemple #33
0
    def test_trivial_maze_serpentine(self):
        # run this test enough times to trip the different skewness parameters
        for _ in range(10):
            m = Maze()
            m.generator = TrivialMaze(4, 5, 'serpentine')
            m.generate()

            self.assertTrue(boundary_is_solid(m.grid))
            self.assertTrue(all_passages_open(m.grid))
            self.assertTrue(all_corners_complete(m.grid))
Exemple #34
0
    def test_prune_solution(self):
        """ test the solution-pruning helper method """
        # build a test Maze and solver, just as placeholders
        m = Maze()
        m.solver = RandomMouse()
        m.solver.start = (0, 1)
        m.solver.end = (0, 5)

        # test the pruner does nothing if nothing needs to be done
        sol = [(1, 1), (1, 2), (1, 3), (1, 4), (1, 5)]
        assert sol == m.solver._prune_solution(sol)

        # test the pruner correctly prunes one duplicate
        sol1 = [(1, 1), (1, 2), (1, 3), (1, 4), (2, 4), (3, 4), (2, 4), (1, 4),
                (1, 5)]
        assert sol == m.solver._prune_solution(sol1)

        # test the pruner correctly prunes two duplicates
        sol2 = [(1, 1), (1, 2), (1, 3), (1, 4), (2, 4), (3, 4), (2, 4), (1, 4),
                (2, 4), (3, 4), (2, 4), (1, 4), (1, 5)]
        assert sol == m.solver._prune_solution(sol2)

        # test the pruner correctly prunes the end point from the solution
        sol3 = [(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (0, 5)]
        assert sol == m.solver._prune_solution(sol3)

        # test the pruner correctly prunes the start point from the solution
        sol4 = [(0, 1), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5)]
        assert sol == m.solver._prune_solution(sol4)

        # test the pruner correctly prunes the start points and end points from the solution
        sol5 = [(0, 1), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (0, 5)]
        assert sol == m.solver._prune_solution(sol5)

        # test the pruner correctly prunes multiple start points and end points from the solution
        sol6 = [(0, 1), (0, 1), (0, 1), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5),
                (0, 5), (0, 5)]
        assert sol == m.solver._prune_solution(sol6)

        # test the pruner correctly prunes a complex mess of a solution
        sol7 = [(0, 1), (0, 1), (0, 1), (1, 1), (1, 2), (1, 3), (1, 4), (2, 4),
                (3, 4), (2, 4), (1, 4), (1, 5), (0, 5), (0, 5)]
        assert sol == m.solver._prune_solution(sol7)
        # bonus: let's tests a long, and heavily redundant, solution
        assert sol == m.solver._prune_solution(sol7 * 100)

        # let's also test a couple edge cases
        sol = []
        assert sol == m.solver._prune_solution(sol)
        sol = [(1, 1)]
        assert sol == m.solver._prune_solution(sol)
        sol = [(1, 1), (1, 2)]
        assert sol == m.solver._prune_solution(sol)
        sol = [(1, 1), (1, 2)]
        assert sol == m.solver._prune_solution(sol * 100)
Exemple #35
0
    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 #36
0
    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)
Exemple #37
0
    def testGridSize(self):
        h = 4
        w = 5
        H = 2 * h + 1
        W = 2 * w + 1

        m = Maze()
        m.generator = Prims(h, w)
        m.generate()

        self.assertEqual(m.grid.shape[0], H)
        self.assertEqual(m.grid.shape[1], W)
Exemple #38
0
    def testGridSize(self):
        h = 4
        w = 5
        H = 2 * h + 1
        W = 2 * w + 1

        m = Maze()
        m.generator = Prims(h, w)
        m.generate()

        self.assertEqual(m.grid.height, H)
        self.assertEqual(m.grid.width, W)
Exemple #39
0
    def testGridSize(self):
        h = 4
        w = 5
        H = 2 * h + 1
        W = 2 * w + 1

        m = Maze()
        m.generator = Prims(h, w)
        m.generate()

        self.assertEqual(m.grid.shape[0], H)
        self.assertEqual(m.grid.shape[1], W)
    def testDungeonRoomsGrid(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(self.boundary_is_solid(m.grid))
        self.assertTrue(self.all_passages_open(m.grid))
    def testDungeonRoomsGrid(self):
        g = MazeArray(7, 7)
        g[1] = array('b', [1,1,1,1,1,1,1])
        g[2] = array('b', [1,1,1,1,1,1,1])
        g[3] = array('b', [1,1,0,0,0,1,1])
        g[4] = array('b', [1,1,0,0,0,1,1])
        g[5] = array('b', [1,1,0,0,0,1,1])

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

        self.assertTrue(self.boundary_is_solid(m.grid))
        self.assertTrue(self.all_passages_open(m.grid))
Exemple #42
0
    def testMonteCarlo(self):
        h = 4
        w = 5
        H = 2 * h + 1
        W = 2 * w + 1

        m = Maze()
        m.generator = Prims(h, w)
        m.solver = Collision()
        m.generate_monte_carlo(3)

        # grid size
        self.assertEqual(m.grid.shape[0], H)
        self.assertEqual(m.grid.shape[1], W)

        # test entrances are outer
        self.assertTrue(self._on_edge(m.grid, m.start))
        self.assertTrue(self._on_edge(m.grid, m.end))
Exemple #43
0
    def testMonteCarlo(self):
        h = 4
        w = 5
        H = 2 * h + 1
        W = 2 * w + 1

        m = Maze()
        m.generator = Prims(h, w)
        m.solver = WallFollower()
        m.generate_monte_carlo(3)

        # grid size
        self.assertEqual(m.grid.height, H)
        self.assertEqual(m.grid.width, W)

        # test entrances are outer
        self.assertTrue(self._on_edge(m.grid, m.start))
        self.assertTrue(self._on_edge(m.grid, m.end))
    def testPerturbation(self):
        m1 = Maze()
        m1.generator = TrivialMaze(4, 5)
        m1.generate()

        m = Maze()
        m.generator = Perturbation(m1.grid)
        m.generate()

        self.assertTrue(self.boundary_is_solid(m.grid))
        self.assertTrue(self.all_passages_open(m.grid))
        self.assertTrue(self.all_corners_complete(m.grid))
Exemple #45
0
    def testGeneratorWipe(self):
        h = 4
        w = 5

        m = Maze()
        m.generator = Prims(h, w)
        m.generate()
        m.generate_entrances()
        m.generate()

        self.assertTrue(m.start is None)
        self.assertTrue(m.end is None)
        self.assertTrue(m.solutions is None)
Exemple #46
0
    def testInnerEntrances(self):
        h = 4
        w = 5

        m = Maze()
        m.generator = Prims(h, w)
        m.generate()
        m.generate_entrances(False, False)

        self.assertFalse(self._on_edge(m.grid, m.start))
        self.assertFalse(self._on_edge(m.grid, m.end))
Exemple #47
0
    def testOuterEntrances(self):
        h = 4
        w = 5

        m = Maze()
        m.generator = Prims(h, w)
        m.generate()
        m.generate_entrances()

        self.assertTrue(self._on_edge(m.grid, m.start))
        self.assertTrue(self._on_edge(m.grid, m.end))
Exemple #48
0
    def testCuldeSacFiller(self):
        """test against a maze with outer/inner entraces"""
        starts = [True, False]
        ends = [True, False]

        g = self._example_cul_de_sac_maze()

        for s in starts:
            for e in ends:
                m = Maze()
                m.generator = Prims(3, 3)
                m.grid = g

                if s and e:
                    m.start = (1, 0)
                    m.end = (5, 6)
                elif not s and not e:
                    m.start = (1, 1)
                    m.end = (5, 5)
                else:
                    if s:
                        m.start = (1, 1)
                        m.end = (5, 5)
                    else:
                        m.start = (1, 1)
                        m.end = (5, 6)

                m.solver = CuldeSacFiller()
                m.solve()

                for sol in m.solutions:
                    self.assertFalse(self._duplicates_in_solution(sol))
                    self.assertTrue(self._one_away(m.start, sol[0]))
                    self.assertTrue(self._one_away(m.end, sol[-1]))
Exemple #49
0
    def _create_maze_with_varied_entrances(self, start_outer=True, end_outer=True):
        """create a maze with entrances inside/outside"""
        m = Maze()
        m.generator = Prims(4, 5)
        m.generate()

        if start_outer and end_outer:
            m.generate_entrances()
        elif not start_outer and not end_outer:
            m.generate_entrances(False, False)
        elif start_outer:
             m.generate_entrances(True, False)
        else:
             m.generate_entrances(False, True)

        return m