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]))
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]))
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)
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))
def testMonteCarloReducer(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, reducer=self._num_turns) # 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))
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 test_monte_carlo_reducer(self): """ Test that the reducer functionality on the Monte Carlo maze generator """ 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, reducer=self._num_turns) # grid size assert m.grid.shape[0] == H assert m.grid.shape[1] == W # test entrances are outer assert self._on_edge(m.grid, m.start) assert self._on_edge(m.grid, m.end)
def test_monte_carlo(self): """ Test that the basic Monte Carlo maze generator """ 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 assert m.grid.shape[0] == H assert m.grid.shape[1] == W # test entrances are outer assert self._on_edge(m.grid, m.start) assert self._on_edge(m.grid, m.end)