Graph Traversal¶
🎯 Find your way out of the maze.
maze = """
############
# # ##S#
### # #
### ###### #
### # ## #
# ## ## ## #
# # #
#X##########""".strip().split('\n')
x, y = (10, 1)
target = (1, 7)
Write a function that will walk the maze (the graph) until the exit
(X) is reached.
Hints¶
You can proceed according to the graph traversal algorithm:
create a stack of the nodes to visit
create a stack of already visited nodes
take the next node from the stack
check whether the node is the exit, if yes, finish
if the node is a wall, continue to 3.
add the neighbours of the node to the nodes to visit
Try out what changes when you replace the stack by a queue.
Translated with www.DeepL.com