MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / find_path

Function find_path

projects/BFS visualizer/main.py:45–81  ·  view source on GitHub ↗
(maze_1, stdscr)

Source from the content-addressed store, hash-verified

43
44
45def 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
84def find_neighbour(maze_1, row, col):

Callers 1

mainFunction · 0.85

Calls 3

start_locationFunction · 0.85
print_mazeFunction · 0.85
find_neighbourFunction · 0.85

Tested by

no test coverage detected