I am working on a project where I need to solve a maze using the minimum number of right turns and no left turns.
The distance travelled is irrelevant as long as right turns are minimized. We are asked to implement our program using both a backtracking algorithm and an optimal (time) one.
For the backtracking algorithm I was going use a stack. My algorithm would be something like:
- Push all four possible starting directions on the stack.
- Follow a path, going straight whenever possible.
- If we reach the end of the maze return the current path length as the best.
- If we reach a dead end backtrack to the last possible right turn and take it.
- If the current path length is greater than the current best, backtrack to the last possible right turn and take it.
I was wondering if anyone could point me in the direction of an optimal algorithm for this.
I'm having a tough time thinking of anything better than the backtracking one.