(maze_1, stdscr)
| 43 | |
| 44 | |
| 45 | def find_path(maze_1, stdscr): |
| 46 | start = "O" |
| 47 | end = "X" |
| 48 | |
| 49 | start_pos = start_location(maze_1, start) |
| 50 | |
| 51 | q = queue.Queue() |
| 52 | q.put((start_pos, [start_pos])) |
| 53 | |
| 54 | visited = set() |
| 55 | |
| 56 | while not q.empty(): |
| 57 | current_pos, path = q.get() |
| 58 | row, col = current_pos |
| 59 | |
| 60 | stdscr.clear() |
| 61 | print_maze(maze_1, stdscr, path) |
| 62 | time.sleep(0.2) |
| 63 | stdscr.refresh() |
| 64 | |
| 65 | if maze_1[row][col] == end: |
| 66 | return path |
| 67 | |
| 68 | neighbours = find_neighbour(maze_1, row, col) |
| 69 | |
| 70 | for neighbour in neighbours: |
| 71 | if neighbour in visited: |
| 72 | continue |
| 73 | |
| 74 | r, c = neighbour |
| 75 | |
| 76 | if maze[r][c] == "#": |
| 77 | continue |
| 78 | |
| 79 | new_path = path + [neighbour] |
| 80 | q.put((neighbour, new_path)) |
| 81 | visited.add(neighbour) |
| 82 | |
| 83 | |
| 84 | def find_neighbour(maze_1, row, col): |
no test coverage detected