Random maze/dungeon generator

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Random maze/dungeon generator

Post by Jasoco »

I had created a mage generation program a while ago and posted code for it last time someone asked about maze generation.

viewtopic.php?f=4&t=7126&p=46241&hilit= ... ion#p46241

My method was more "depth first search" algorithm and was used for a compact grid "room" style maze where each grid square is a room. Basically..

1) It starts by taking a starting point.
2) Draw a path starting from that point off in random directions. Pick a random direction and if it's not already taken, move into it. If it is taken, choose another direction.
3) Continue doing this until you reach a square that has no empty sides. i.e. there is no where to go.
4) If there is no where to go, choose a square at random that is A) part of an existing path and B) has at least one empty side and go to step 2.
5) Do this until all empty squares are taken.

As you go along and mark a square, set some flags in the squares data to tell the game which sides are open. (i.e. which walls would have doors)

This method would make sure the maze is solvable and would also not require backtracking. The only part you have to figure out is the method for figuring where to put the next start point after the first path is finished. That's pretty easy. Either choose a random square until you find a valid one, or loop through each path and randomly stop on a square if it is valid.

If you were to use a grid but wanted to have a block buffer between each path, you'd modify it so instead of flags for doors you'd just dig through an extra layer by setting it as open after setting the current square as open before moving on to the next one. Quite simple.

I plan on rewriting my maze generation algorithm for use in my 3D Raycaster engine and will probably use that method and will modify it to add things like rooms.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Random maze/dungeon generator

Post by kikito »

When I write def I mean function.
MrTP
Prole
Posts: 2
Joined: Mon Jun 04, 2012 1:31 pm

Re: Random maze/dungeon generator

Post by MrTP »

Im working on a Dungeon Crawler/RPG at the moment where I use a completely different Technique which gives a feeling of random Room placement while preventing overlapping rooms

Simplified these are the Steps:
Create a large, filled grid
Split this grid recursively until it consists of many smaller rooms that have roughly the desired size
Select the desired amount of rooms at random and clear them
Create Corridors between those rooms until all are connected

Some Screens of an early Version with rectangular Rooms/Corridors:
https://dl.dropbox.com/u/18461302/Love/Screen1.png
https://dl.dropbox.com/u/18461302/Love/Screen2.png
https://dl.dropbox.com/u/18461302/Love/Screen3.png
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests