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 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:
- the maze itself.
- a location in the maze. On a square maze, this is a square cell.
- the connection between two nodes. On a square maze, this is a 1-length bar.
- Tree Group
- a set of nodes, which may be empty, arranged as a tree
And from those, we get:
- Create a group GTG, for the Graph Tree Group, containing tree groups
- Populate GTG with one tree group containing one node, for every location in your maze
- Create an edge set E
- Populate E with every valid edge in your maze
- While there is more than one group in GTG, and while E is not empty:
- Pick a random edge rE from E
- Identify endpoints p1 and p2 of rE
- Remove rE from E
- Check which groups p1 and p2 belong to (p1g and p2g respectively).
- If p1g and p2g are different, join tree group p1g and p2g at p1 -> p2, and rewrite all group ownership of one tree to the other, thus joining the trees.
- Return to step 5.
- If you have no edges left, but more than one tree, either the graph is not connected or there's a bug.
- If you have just one tree, you have a complete no-loop maze.
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 would also take a look at some of the algorithms used in Roguelike development. There's a good starting resource at Rogue Basin
There's a good run-though here: https://journal.stuffwithstuff.com/2014/12/21/rooms-and-mazes/
Basic steps were:
- Place rooms
- Fill empty space with maze
- Connect rooms to the maze
- Carve out dead-ends