Example #1
0
 def testSolveMazeAStarShortestPossibleMazeShouldBeOneExploredTile(self):
     maze = Maze('mazes/shortest_possible_maze.txt', AStarFrontier())
     maze._solve_maze()
     expected_maze = [['#', '#', '#'], ['#', 'B', '#'], ['#', 'A', '#'],
                      ['#', '#', '#']]
     self.assertEqual(expected_maze, maze._maze)
     self.assertEqual(1, maze._number_explored_tiles)
Example #2
0
 def testSolveMazeAStarVeryShortMazeShouldBeTwoExploredTiles(self):
     maze = Maze('mazes/very_short_maze.txt', AStarFrontier())
     maze._solve_maze()
     expected_maze = [['#', '#', '#'], ['#', 'B', '#'], ['#', 'O', '#'],
                      ['#', 'A', '#'], ['#', '#', '#']]
     self.assertEqual(expected_maze, maze._maze)
     self.assertEqual(2, maze._number_explored_tiles)
Example #3
0
 def testSolveMazeStackVeryShortMazeShouldHaveThreeExploredTiles(self):
     maze = Maze('mazes/very_short_maze.txt', StackFrontier())
     maze._solve_maze()
     expected_maze = [['#', '#', '#'], ['#', 'B', '#'], ['#', 'O', '#'],
                      ['#', 'A', '#'], ['#', '#', '#']]
     self.assertEqual(expected_maze, maze._maze)
     self.assertEqual(3, maze._number_explored_tiles)
Example #4
0
 def testSolveMazeAStarLinearMazeShouldHaveFourExploredTiles(self):
     maze = Maze('mazes/linear_maze.txt', AStarFrontier())
     maze._solve_maze()
     expected_maze = [['#', '#', '#'], ['#', 'B', '#'], ['#', 'O', '#'],
                      ['#', 'O', '#'], ['#', 'O', '#'], ['#', 'A', '#'],
                      ['#', '#', '#']]
     self.assertEqual(expected_maze, maze._maze)
     self.assertEqual(4, maze._number_explored_tiles)
Example #5
0
 def testSolveMazeAStarMazeWithDeadEndShouldHaveSixExploredTiles(self):
     maze = Maze('mazes/maze_with_dead_end.txt', AStarFrontier())
     maze._solve_maze()
     expected_maze = [['#', '#', '#', '#', '#'], ['#', ' ', '#', 'B', '#'],
                      ['#', ' ', '#', 'O', '#'], ['#', ' ', 'O', 'O', '#'],
                      ['#', '#', 'O', '#', '#'], ['#', '#', 'O', '#', '#'],
                      ['#', '#', 'A', '#', '#'], ['#', '#', '#', '#', '#']]
     self.assertEqual(expected_maze, maze._maze)
     self.assertEqual(6, maze._number_explored_tiles)
Example #6
0
 def testSolveMazeAStarMazeWithTurnShouldHaveEightExploredTiles(self):
     maze = Maze('mazes/maze_with_turn.txt', AStarFrontier())
     maze._solve_maze()
     expected_maze = [['#', '#', '#', '#', '#'], ['#', '#', '#', 'B', '#'],
                      ['#', '#', '#', 'O', '#'], ['#', '#', '#', 'O', '#'],
                      ['#', 'O', 'O', 'O', '#'], ['#', 'O', '#', '#', '#'],
                      ['#', 'O', '#', '#', '#'], ['#', 'A', '#', '#', '#'],
                      ['#', '#', '#', '#', '#']]
     self.assertEqual(expected_maze, maze._maze)
     self.assertEqual(8, maze._number_explored_tiles)
Example #7
0
 def testSolveMazeAStarMazeWithCycleShouldHaveTwelveExploredTiles(self):
     maze = Maze('mazes/maze_with_cycle.txt', AStarFrontier())
     maze._solve_maze()
     expected_maze = [['#', '#', '#', '#', '#'], ['#', '#', 'B', '#', '#'],
                      ['#', '#', 'O', '#', '#'], ['#', 'O', 'O', 'X', '#'],
                      ['#', 'O', '#', 'X', '#'], ['#', 'O', 'O', 'X', '#'],
                      ['#', '#', 'O', '#', '#'], ['#', '#', 'A', '#', '#'],
                      ['#', '#', '#', '#', '#']]
     self.assertEqual(expected_maze, maze._maze)
     self.assertEqual(12, maze._number_explored_tiles)
Example #8
0
 def testSolveMazeGreedyMazeWithMultipleSolutionsShouldHaveFiveExploredTiles(
         self):
     maze = Maze('mazes/maze_with_multiple_solutions.txt', GreedyFrontier())
     maze._solve_maze()
     expected_maze = [['#', '#', '#', '#', '#'], ['#', ' ', ' ', ' ', '#'],
                      ['#', ' ', '#', 'B', '#'], ['#', ' ', '#', 'O', '#'],
                      ['#', ' ', 'O', 'O', '#'], ['#', '#', 'O', '#', '#'],
                      ['#', '#', 'A', '#', '#'], ['#', '#', '#', '#', '#']]
     self.assertEqual(expected_maze, maze._maze)
     self.assertEqual(5, maze._number_explored_tiles)
Example #9
0
 def testSolveMazeGreedyMazeWithCycleShouldHaveEightExploredTiles(self):
     maze = Maze('mazes/maze_with_cycle.txt', GreedyFrontier())
     maze._solve_maze()
     expected_maze = [['#', '#', '#', '#', '#'], ['#', '#', 'B', '#', '#'],
                      ['#', '#', 'O', '#', '#'], ['#', 'O', 'O', ' ', '#'],
                      ['#', 'O', '#', ' ', '#'], ['#', 'O', 'O', ' ', '#'],
                      ['#', '#', 'O', '#', '#'], ['#', '#', 'A', '#', '#'],
                      ['#', '#', '#', '#', '#']]
     self.assertEqual(expected_maze, maze._maze)
     self.assertEqual(8, maze._number_explored_tiles)
Example #10
0
 def testSolveMazeStackMazeWithDeadEndOnRightShouldHaveTenExploredTiles(
         self):
     maze = Maze('mazes/maze_with_dead_end_on_right.txt', StackFrontier())
     maze._solve_maze()
     expected_maze = [['#', '#', '#', '#', '#'], ['#', 'B', '#', 'X', '#'],
                      ['#', 'O', '#', 'X', '#'], ['#', 'O', 'O', 'X', '#'],
                      ['#', '#', 'O', '#', '#'], ['#', '#', 'O', '#', '#'],
                      ['#', '#', 'A', '#', '#'], ['#', '#', '#', '#', '#']]
     self.assertEqual(expected_maze, maze._maze)
     self.assertEqual(10, maze._number_explored_tiles)
Example #11
0
 def testSolveMazeAStarMazeWithMultipleSolutionsGoalOnLeftShouldHaveFiveExploredTiles(
         self):
     maze = Maze('mazes/maze_with_multiple_solutions_goal_on_left.txt',
                 AStarFrontier())
     maze._solve_maze()
     expected_maze = [['#', '#', '#', '#', '#'], ['#', ' ', ' ', ' ', '#'],
                      ['#', 'B', '#', ' ', '#'], ['#', 'O', '#', ' ', '#'],
                      ['#', 'O', 'O', ' ', '#'], ['#', '#', 'O', '#', '#'],
                      ['#', '#', 'A', '#', '#'], ['#', '#', '#', '#', '#']]
     self.assertEqual(expected_maze, maze._maze)
     self.assertEqual(5, maze._number_explored_tiles)