[Home]Maze generation algorithms

HomePage | Recent Changes | Preferences

Showing revision 1
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:

  1. 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.
  2. Start at a particular cell.
  3. Mark the current cell as visited, and get a list of its neighbors. For each neighbor:
    1. 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:

  1. 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.
  2. For each wall in some random order:
    1. See if the cells on each side of the current wall have the same number, and if their numbers are different:
      1. Remove the current wall.
      2. 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.

HomePage | Recent Changes | Preferences
This page is read-only | View other revisions | View current revision
Edited October 3, 2001 7:53 pm by NickelKnowledge (diff)
Search: