A random maze generator. Based on the Recursive Backtracker algorithm.
- The maze begins as a grid of cells, with an empty stack.
- Choose a random initial cell from the grid:
- Set this as the current cell and mark it as visited.
- While there are unvisited cells in the grid:
- If the current cell has any unvisited neighbour cells:
- Choose a random unvisited neighbour cell.
- Remove the wall between the current cell and the chosen neighbour cell.
- Push the current cell onto the stack.
- Set the chosen neighbour cell as the current cell and mark it as visited.
- Repeat step 3, with the new current cell.
- Else the current cell has no unvisited neighbour cells:
- Pop a cell from the stack, and set it as the current cell.
- Repeat step 3, with the new current cell.
- If the current cell has any unvisited neighbour cells:
A random maze is generated, with start and end locations.
For more information: https://en.wikipedia.org/wiki/Maze_generation_algorithm#Recursive_backtracker http://weblog.jamisbuck.org/2010/12/27/maze-generation-recursive-backtracking