def test_bfs_with_the_given_boards(self): solvable_maze_numbers = ['1', '2', '3', '4'] for num in solvable_maze_numbers: with open('mazesolver/tests/boards/board-2-' + num + '.txt') as f: ms = TerrainMazeSolver(f.read()) ms.solve(method='BFS') assert ms.success
def test_closed_set(self): maze = 'Aw\ngB\n' ms = TerrainMazeSolver(maze) ms.solve() # Non-deterministic ordering assert (ms.closed_set == ((0, 0), (1, 0))) \ or (ms.closed_set == ((1, 0), (0, 0)))
def test_distance_between_adjacent_nodes(self): maze = 'Aw\ngB\n' ms = TerrainMazeSolver(maze) water_cost = ms.distance_between( (0, 0), (0, 1), ) assert water_cost == 100 grasslands_cost = ms.distance_between( (1, 0), (1, 0), ) assert grasslands_cost == 5
def test_open_set(self): maze = 'Aw\ngB\n' ms = TerrainMazeSolver(maze) ms.solve() assert ms.open_set == ((0, 1),)
from mazesolver import MazeSolver, TerrainMazeSolver if argv[1] == '1': board_paths = 'mazesolver/tests/boards/board-1-' for board_number in [1, 2, 3, 4]: with open(board_paths + str(board_number) + '.txt') as board_file: maze_solver = MazeSolver(board_file.read()) maze_solver.visualize() if argv[1] == '2': board_paths = 'mazesolver/tests/boards/board-2-' for board_number in [1, 2, 3, 4]: with open(board_paths + str(board_number) + '.txt') as board_file: maze_solver = TerrainMazeSolver(board_file.read()) maze_solver.visualize() if argv[1] == '3': base_path = 'mazesolver/tests/boards/' board_names = ( ('board-1-1.txt', MazeSolver), ('board-2-1.txt', TerrainMazeSolver), ) methods = ('Astar', 'Dijkstra', 'BFS',) for board_name, Solver in board_names: for method in methods: with open(base_path + board_name) as board_file: maze_solver = Solver(board_file.read()) maze_solver.solve(method=method)