Maze Generator (Recursive Backtracking Algorithm)

See inside

This program uses the "recursive backtracking algorithm" for generating a maze. A description of this algorithm can be found here:

After the maze is done, use the arrow keys to move the cat to the cheesy puffs. To make maze generation faster, shift-click the green flag to enable turbo mode. After the maze is done, shift-click the green flag again to turn off turbo mode so you can walk around the maze. (You can also set the BACKTRACK DELAY variable in the code to 0 to make the maze-making faster.)

Notes and Credits

Learn to program games with this free online Scratch course:

The algorithm is pretty simple:
1) Randomly move around to cells you haven't visited before.
2) When you reach a dead end, backtrack until you get next to a cell you haven't visited before. Keep moving in that direction.
3) If you've backtracked all the way to the start, you're done.

Shared: 1 Feb 2014 Modified: 29 Jul 2018
Favorite this project 153
Love this project 173
Total views 8111
View the remix tree  60
More projects by AlSweigart