What algorithm have you used in the past to generate a simple 2d maze?
There are a lot of various ways of making mazes. There's a huge list of them and their descriptions here: http://www.astrolog.org/labyrnth/algrithm.htm I think I used the one described under "Perfect". |
|||||||||
|
I have used a depth first search one time to good effect. It generates a good, random-looking maze. Also available is a method where you recursively subdivide rectangles, which produces long corridors. This is called the recursive division method. |
||||
|
Wikipedia has a great resource on maze generation. I've use randomized prims algorithm with great results. The division algorithm looks looks interesting but I've never used it. Here is wikipedia example of prim's at work. |
|||
|
One easy way is to make a list of north walls and west walls, then permute them. Give each room a number. Then blow up one of the walls in the list, as long as the two rooms don't have the same number, then propagate one of the numbers to all the other rooms with the same number. Keep going until you run out of walls. This works for rectangular mazes or, really, any other maze where you can give a list of "potentially connected rooms". Plus, it's pretty straightforward to program. |
|||
|
I prefer the tightly wound mazes that Kruskal's Algorithm creates. The standard description of Kruskal's Algorithm is inappropriate in that it fails to distinguish locations in the graph from location groups, while relying on a pun about datastructure choice, leading to description ambiguities that confuse novices. Therefore I reject Kruskal's termonology. I will use the following terms:
And from those, we get:
|
|||||
|
I would also take a look at some of the algorithms used in Roguelike development. There's a good starting resource at Rogue Basin |
|||
|
You asked which one I used, so I will make sure to answer that. I used the Recursive Backtracker Algorithm in my maze game on Rootbeer Games. This is evidence that I used the algorithm, please don't view it as an advertisement of my work. |
|||
|