Recursive Backtracking
Recursive backtracking a depth-first search technique for finding a path from a starting location to the goal. Although the algorithm does not necessarily find the shortest path, it will find a path (if it exists), and does not require full knowledge of the maze.
Setup
- The robot starts at the start. This square is marked as part of the path.
First Step
- The robot can't move North.
- The robot can move East. It moves east and marks the new square as part of the path.
Continue East
- The robot can't move North.
- The robot can move East (again). It moves east and marks the new square as part of the path.
First Backtrack
- The robot can't move North.
- The robot can't move East.
- The robot can't move South.
- The robot can move West, but that is already on the path.
- The robot has explored all directions and not found a new free square.
- Therefore the current square is not on the path.
- The robot moves West.
Continue Moving
- Robot resumes from its previous time at this square.
- Robot has already tried moving North and East, and that failed.
- The Robot can move South, so it does so.
Go South!
- The robot can move North, but it's been there before.
- The robot can't move East.
- The robot can move South, and does so.
Eastward Bound
- The robot can't move North, but it can move east.
- Repeat one more time.
Final Backtrack
- The robot cannot move in any direction without visiting an unexplored square, so it backtracks by one square.
- The new location has the same problem, so the robot backtracks again.
Almost Home
- The robot has already explored North and East.
- The robot cannot go South.
- The robot can move West, so it does so.
Goal!!!!!!!
- The Robot cannot move North.
- The Robot has already explored the East.
- The robot can move south, that is the goal!
- The robot also has a path from the start to the goal.