Maze generation algorithms
Appearance
Two common maze generation techniques, see http://www.mazeworks.com/mazegen/ for more techniques and an excellent Java applet which demonstrates some of these.
Depth first search:
- Start with a rectangular array of the proper width and height with all the cells marked as unvisited, and all walls up between the cells.
- Start at a particular cell.
- Mark the current cell as visited, and get a list of its neighbors. For each neighbor:
- If that neighbor hasn't been visited, remove the wall between this cell and that neighbor, and then recurse to step 3 with that neighbor as the current cell.
Kruskal's algorithm:
- Start with a rectangular array of the proper width and height, with all the cells given a different number, and all walls up between the cells.
- For each wall in some random order:
- See if the cells on each side of the current wall have the same number, and if their numbers are different:
- Remove the current wall.
- Then find all the cells in the array with the higher of the two cell numbers and replace them with the lower of the two cell numbers.