Beispiel #1
0
 def test_alpha(self):
     text_file = Maze.open_map('Tests/test_alpha.txt')
     lb = Maze(None, text_file)
     path = solve_maze(lb, 0)  # ALPHA = 0
     bombs_used = path.pop(0)
     self.assertEqual(bombs_used, lb.bombs)
     self.assertEqual(len(path), 38)  # Used all bombs, shorter path
     path = solve_maze(lb, 100)  # ALPHA = 100
     bombs_used = path.pop(0)
     self.assertEqual(bombs_used, 0)  # 0 bombs used, longest path
     self.assertEqual(len(path), 44)
Beispiel #2
0
    def test_2_finishes(self):
        text_file = Maze.open_map(wall_maze)
        lb = Maze(None, text_file)
        lb.finishes = [(1, 1), (38, 1)]

        lb.start = (20, 1)
        path = solve_maze(lb, 0)
        path.pop(0)
        self.assertEqual(path[-1], (38, 1))  # second finish is closer

        lb.start = (15, 1)
        path = solve_maze(lb, 0)
        path.pop(0)
        self.assertEqual(path[-1], (1, 1))  # first finish is closer
Beispiel #3
0
 def test_simple_map(self):
     text_file = Maze.open_map('Tests/simple_test.txt')
     lb = Maze(None, text_file)
     path = solve_maze(lb, 0)
     bombs_used = path.pop(0)
     self.assertEqual(bombs_used, 1)
     self.assertEqual(len(path), 9)
Beispiel #4
0
 def test_incorrect_maze_params(self):
     text_file = Maze.open_map(straight_maze)
     lb = Maze(None, text_file)
     lb.start = None
     lb.finishes = [None]
     lb.bombs = -1
     self.assertRaises(ValueError, lambda: solve_maze(lb, 0))
Beispiel #5
0
 def run(self):
     try:
         maze = self.queue.get()
         alpha = self.queue.get()
         res = solve_maze(maze, alpha, self.solver_window.signal)
         self.queue.put(res)
     except Exception as e:
         self.queue.put('Solver exception: {}'.format(e))
Beispiel #6
0
 def test_portals(self):
     text_file = Maze.open_map(wall_maze)
     lb = Maze(None, text_file)
     lb.portals = [[(4, 1), (34, 1)]]
     lb.bombs = 0
     path = solve_maze(lb, 0)
     path.pop(0)
     self.assertEqual(len(path), 7)
Beispiel #7
0
 def test_one_way_walls(self):
     text_file = Maze.open_map(wall_maze)
     lb = Maze(None, text_file)
     #  instead of wall we have one-way wall
     lb[5][1] = lb.EMPTY
     lb.one_way_walls.append((5, 1, Directions.right))
     path = solve_maze(lb, 0)
     bombs_used = path.pop(0)
     self.assertEqual(bombs_used, 1)  # we have wall, but don't use bombs
     self.assertEqual(len(path), 38)
Beispiel #8
0
 def test_maze_wall(self):
     text_file = Maze.open_map(wall_maze)
     lb = Maze(None, text_file)
     path = solve_maze(lb, 0)
     path.pop(0)
     self.assertEqual(len(path), 38)
Beispiel #9
0
 def test_maze_wall_no_bombs(self):
     text_file = Maze.open_map(no_bombs_maze)
     lb = Maze(None, text_file)
     path = solve_maze(lb, 0)
     self.assertEqual(None, path)
Beispiel #10
0
 def test_maze_straight_line(self):
     text_file = Maze.open_map(straight_maze)
     lb = Maze(None, text_file)
     path = solve_maze(lb, 0)
     path.pop(0)
     self.assertEqual(len(path), 38)