MCS 275 Spring 2022
Emily Dumas
Course bulletins:
How do you solve a maze?
How do you solve a maze?
We'll solve a maze like this using recursion with backtracking.
We make a function that takes:
Its goal is to add one more step to the path, never backtracking, and call itself to finish the rest of the path.
But if it hits a dead end, it needs to notice that and backtrack.
Backtracking is implemented through the return value of a recursive call.
Recursive call may return:
None
, indicating that only dead ends were found.If we ever receive a solution from a recursive call, we return it immediately.
depth_first_maze_solution
:
Input: a maze and a path under consideration (partial progress toward solution).
None
, continue the loop.)None
.This method is also called a depth first search for a path through the maze.
Here, depth first means that we always add a new step to the path before considering any other changes (e.g. going back and modifying an earlier step).
Same suggested references as Lecture 13.