Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Cavern-type dungeon generation

1,223 views
Skip to first unread message

Mike_aka_MD

unread,
Apr 13, 2002, 5:47:57 PM4/13/02
to
I personally favor organic caverns to roomed dungeons, and plan to use
caverns in my roguelike. I have created an algorithm for this; sample
results follow. The problem with my algorithm is that there is no way
to ensure that all dungeon areas are accessable. If anyone has any
ideas how i can connect the separate dungeon segments and still
maintain the cavern-like appearance of the dungeon id appreciate it.
also if you have any questions about my algorithm id be glad to answer
them.

###############################################################################
##############.........######....##...........#######..################.....###
#############...........######.................##..................###......###
#############............######....................................###.....####
#############............#######...................................###....#####
############..............######...................................##.....#####
###########.......................................................###.....#####
###########......................................................###.......####
###########.....................................................###.........###
###########..................#.................................####..........##
############................###...............................#####..........##
############................###..............................#######.........##
############...............###......#...........##..........#########........##
###########...............###......##.........#####........###########.......##
##########...............###.................#######....##############.......##
####..####...............###................##########################.......##
####...##.......####.....###...............##########################........##
####...........######....####.............###########################........##
#####.........########..######............###########################.......###
######.......##################..........#############################.....####
########....######################.......######################################
####################################....#######################################
###############################################################################


###############################################################################
#####..#######....###############################....##........#########....###
####...............########..######.......######...................####......##
####...............#######....####........#####....................####......##
###................######.....####........#####...................####.......##
###............##########......##.........#####..................#####........#
###...........###########................######.............#...######........#
####..........############...............#####.............###..#####.........#
#####.........############..............####...............##########.........#
#####.........############..............####...............###########........#
#####.........############..............####..............############.......##
#####.........############..............#####............############.......###
#####.........############..............#####............###########........###
#####..........############..............###..............##########........###
####...........#############.......................####...##########.......####
####...........#############......................######..#########......######
####..........##############............##.......#######..#########.....#######
####.........###############........#######.....###################....########
#####.....##################........#######...#####################...#########
############################........#######..#####################....#########
#############################.......#######..####################....##########
##################################################################..###########
###############################################################################

Dave Slutzkin

unread,
Apr 13, 2002, 8:52:42 PM4/13/02
to
On 13 Apr 2002, Mike_aka_MD wrote:

> I personally favor organic caverns to roomed dungeons, and plan to use
> caverns in my roguelike. I have created an algorithm for this; sample
> results follow. The problem with my algorithm is that there is no way
> to ensure that all dungeon areas are accessable.

<snip dungeons>

(They look good.)

It looks like they're always connected vertically, and it's just
horizontally that you've got the problem. So maybe do some sort of
horizontal flooding? Start at the leftmost square, then keep moving
right until you can move no more. Do the same from the right. If they
haven't reached each other then one can drill through a wall to make a
passage.

Or, for gameplay, you could just make sure that the two sets of stairs are
connected? Or you could avoid the whole issue by allowing the player to
tunnel a lot? ;-)

later,

Dave Slutzkin.

Ville Heikkilä

unread,
Apr 14, 2002, 11:45:18 AM4/14/02
to

Mike_aka_MD wrote:

> I personally favor organic caverns to roomed dungeons, and plan to use
> caverns in my roguelike. I have created an algorithm for this; sample
> results follow. The problem with my algorithm is that there is no way
> to ensure that all dungeon areas are accessable. If anyone has any
> ideas how i can connect the separate dungeon segments and still
> maintain the cavern-like appearance of the dungeon id appreciate it.
> also if you have any questions about my algorithm id be glad to answer
> them.


I got very similar results playing around with an algorith wich used
game-of-life style rules repeatedly to semi-randomly created starting
position.

If your algorithm is anything like that, you could check for
accessibility at some very early stage of generation. If the algorithm
then finds enough large areas that are seperated from each other it can
find the shortest possible tunnel to connect these two areas and create
the tunnel. The rest steps of the algorithm probably take care of making
the tunneled area look like rest of the level.

--
VTT

Jesse Welton

unread,
Apr 14, 2002, 12:51:25 PM4/14/02
to
In article <9d3a89d7.02041...@posting.google.com>,
MDS...@hotmail.com (Mike_aka_MD) wrote:

> I personally favor organic caverns to roomed dungeons, and plan to use
> caverns in my roguelike. I have created an algorithm for this; sample
> results follow. The problem with my algorithm is that there is no way
> to ensure that all dungeon areas are accessable. If anyone has any
> ideas how i can connect the separate dungeon segments and still
> maintain the cavern-like appearance of the dungeon id appreciate it.

Use a flood-fill to identify each separate region. Use A* to find
the shortest connecting paths between them, then cut tunnels of an
appropriate width along those paths. I'll give some possible results
for your example maps, using a digging pattern like this:

:
:!:
:

(That is, the shortest path is marked as '!', and I'm also digging out
the nearest neightbors, marking them as ':'.)

###############################################################################
##############.........######....##...........#######..################.....###
#############...........######.................##..................###......###
#############............######....................................###.....####
#############............#######...................................::#....#####
############..............######...................................!!.....#####
###########.......................................................#::.....#####


###########......................................................###.......####
###########.....................................................###.........###
###########..................#.................................####..........##
############................###...............................#####..........##
############................###..............................#######.........##
############...............###......#...........##..........#########........##
###########...............###......##.........#####........###########.......##
##########...............###.................#######....##############.......##
####..####...............###................##########################.......##
####...##.......####.....###...............##########################........##
####...........######....####.............###########################........##
#####.........########..######............###########################.......###
######.......##################..........#############################.....####
########....######################.......######################################
####################################....#######################################
###############################################################################


###############################################################################
#####..#######....###############################....##........#########....###
####...............########..######.......######...................:::#......##
####...............::::::#....####........#####....................!!!:......##
###................!!!!!!.....####........#####...................#:::.......##
###............####::::::......##.........#####..................#####........#


###...........###########................######.............#...######........#
####..........############...............#####.............###..#####.........#
#####.........############..............####...............##########.........#
#####.........############..............####...............###########........#
#####.........############..............####..............############.......##
#####.........############..............#####............############.......###
#####.........############..............#####............###########........###
#####..........############..............###..............##########........###
####...........#############.......................####...##########.......####
####...........#############......................######..#########......######
####..........##############............##.......#######..#########.....#######
####.........###############........#######.....###################....########
#####.....##################........#######...#####################...#########
############################........#######..#####################....#########
#############################.......#######..####################....##########
##################################################################..###########
###############################################################################


It might not produce very satisfying results (too straight) if the cavern
sections are ever much farther apart than this, though.

Does that help?

-Jesse

Jesse Welton

unread,
Apr 14, 2002, 1:06:10 PM4/14/02
to
In article <Pine.LNX.4.33.02041...@genghis.demon>, Dave

Slutzkin <da...@labyrinth.net.au> wrote:
>
> It looks like they're always connected vertically, and it's just
> horizontally that you've got the problem.

I suspect that this is entirely due to the fact that the map is almost
4 times as wide as it is tall, so that this property is likely, but not
guaranteed. I would avoid any solution that depended on it.

-Jesse

Mystran the Dark-Elf

unread,
Apr 14, 2002, 8:33:22 PM4/14/02
to

"Mike_aka_MD" <MDS...@hotmail.com> wrote in message
news:9d3a89d7.02041...@posting.google.com...

> I personally favor organic caverns to roomed dungeons, and plan to use
> caverns in my roguelike. I have created an algorithm for this; sample
> results follow. The problem with my algorithm is that there is no way
> to ensure that all dungeon areas are accessable. If anyone has any
> ideas how i can connect the separate dungeon segments and still
> maintain the cavern-like appearance of the dungeon id appreciate it.
> also if you have any questions about my algorithm id be glad to answer
> them.

I did some caverns with a system as follows:

1. set i = 0 and fill the map with wall
2. clear random spot
3. move to a random direction from that spot (N, E, W, S)
4. clear that spot
5. substract 1 from i
6. jump to 3 if i < imax

imax value depends on how much you want to clear but try something
like 1/4 of the blocks on the map first..

improved version check whether a spot is already cleared, and if it is
doesn't decrement i. This gives you better control of the size of the
cave and a bit better games..

Yes, these caves are much more random than yours, but.. well.. I like
them more fun also... try.. for you might be surprised on the results.

You want a good LOS system that highlights the visible are with this though
as otherwise it is quite hard to figure out what's really happening around.

- Mystran

Mike_aka_MD

unread,
Apr 14, 2002, 9:00:13 PM4/14/02
to
Ville Heikkilä <keb...@hotmail.com> wrote in message news:<3CB9A40E...@hotmail.com>...

> I got very similar results playing around with an algorith wich used
> game-of-life style rules repeatedly to semi-randomly created starting
> position.
>
> If your algorithm is anything like that, you could check for
> accessibility at some very early stage of generation. If the algorithm
> then finds enough large areas that are seperated from each other it can
> find the shortest possible tunnel to connect these two areas and create
> the tunnel. The rest steps of the algorithm probably take care of making
> the tunneled area look like rest of the level.

sounds good, make sure the cavern is continuous first and then smooth
it over to make it look right. Now how would i go about checking for
continuousness and correcting a lack of it?
Thanks~ Mike

Ville Heikkilä

unread,
Apr 15, 2002, 4:25:09 PM4/15/02
to

Mike_aka_MD wrote:

> Ville Heikkilä <keb...@hotmail.com> wrote in message news:<3CB9A40E...@hotmail.com>...

[clipped algorithm description]


> sounds good, make sure the cavern is continuous first and then smooth
> it over to make it look right. Now how would i go about checking for
> continuousness and correcting a lack of it?


There are good articles writen on that topic and newsgroup search with
google will probably give you some answers too.

--
VTT

Bru, Pierre

unread,
Apr 16, 2002, 6:18:32 AM4/16/02
to
hi,

I used a Diffusion-Limited Aggregation [search DLA, fractal, or go
directly to http://www.oche.de/~ecotopia/dla/index.html] to generate
caves looking like the attached screenshot. I did not posted the
programm yet as it is desperately slow (I do all my testings on my old
i486-DX12: if the speed is fair on that machine, it will burst on
every other)

Pierre.
---

###.###.....#############...#..##..######....########..#........##............
#######..#..##############....###.###.####..#####.###.....###.################
#.#.####...#####..###########.#...##..###..######.##..#######...##############
#...######..##..#.#########...#..###.####.#######..#..#.###.#.################
##..######.####...###########.....##.####.########.#........##################
...#######..####..###############....####.#####.##...###.##.##################
##....#####...#.#.##################......#####.##.#..#####.##################
##.##....##.#.........###############.#########....##.#####....###############
########....###.#.###....#.##########..#######..##.###########################
#####.##.#.###..########.........#####.#####.#..##.###########################
##.......#.####.########.#####.#.#####..##.#.#....############################
##.##.#########.##############.#.####...........##############################
#..############.##########.###.#...........###....######.#..##################
....###########.#########...######.#.###.#..##.#...#####...###################
##.########################........#.#########.##..##......#..######.....#####
###########################..###..#..########...##.#..####.#..##..#..#########
######################.#####.###.##.#######.....##...#####...###.#...#########
###################....#########.##.#########.#.###....###.#.........###.####.
.##################.....#######..#...########.#.####.#.#######.#.###...#.#.#..
#######################..####....###..#######...####.#..#####..#..####.....#..
########################.......####...#####.....##...#########.##..#######....
#####################....#.#.#.####.#.#######.######.#########.##......###.###
################.......###.###.####.#.#######.######..########..#.##..##...###
#####################..###..#..######...##########...########..##..#######...#

MDS...@hotmail.com (Mike_aka_MD) wrote in message news:<9d3a89d7.02041...@posting.google.com>...


> I personally favor organic caverns to roomed dungeons, and plan to use
> caverns in my roguelike. I have created an algorithm for this; sample
> results follow. The problem with my algorithm is that there is no way
> to ensure that all dungeon areas are accessable. If anyone has any
> ideas how i can connect the separate dungeon segments and still
> maintain the cavern-like appearance of the dungeon id appreciate it.
> also if you have any questions about my algorithm id be glad to answer
> them.

[--sniped screenshot--]

oli g

unread,
Apr 16, 2002, 8:55:23 AM4/16/02
to

"Bru, Pierre" schrieb:

IMHO your generated caves are not really caves (they are more like tunnels), but if you would combine your
algorithm with that one of Mike_aka_MD (from the original post) you would have big caves, connected by
not-so-straight tunnels.

Oli

Ville Heikkilä

unread,
Apr 16, 2002, 11:14:15 AM4/16/02
to

"Mike_aka_MD" <MDs...@hotmail.com> kirjoitti viestissä
news:b27649f7.02041...@posting.google.com...

> sounds good, make sure the cavern is continuous first and then smooth
> it over to make it look right. Now how would i go about checking for
> continuousness and correcting a lack of it?

Hi, a gave my algorithm some more toughts and came up with this:

First you create the "seed" of the dungeon and save it. Then you create the
dungeon from the "seed" as usual ignoring contiousness. Then you check if
the dungeon is continuous and if it is not, you calculate the shortest
possible paths to make the dungeon continuous. After that you carve out the
shortest possible paths to the "seed" of the dungeon and then use this seed
to create the final dungeon. You probably need to use wider than 1 char
paths so the newly created tunnels survive to the final dungeon, you could
use the
#
#!#
#
pattern someone suggested before.

--
VTT

stank-monkey

unread,
Apr 16, 2002, 11:02:26 AM4/16/02
to
welt...@RemoveThis.osu.edu (Jesse Welton) wrote in message news:<welton.6-140...@ts33-11.homenet.ohio-state.edu>...

> In article <9d3a89d7.02041...@posting.google.com>,
> MDS...@hotmail.com (Mike_aka_MD) wrote:
>
> > I personally favor organic caverns to roomed dungeons, and plan to use
> > caverns in my roguelike. I have created an algorithm .....<snip>

> Use a flood-fill to identify each separate region. Use A* to find....<snip>

Better yet, use the floodfill to identify these regions, and make them
equivalent to dungeon levels 5-10 levels more difficult than actual.
The bravest could venture then in and be rewarded... maybe ;^)
Stanky

R Dan Henry

unread,
Apr 17, 2002, 12:43:20 AM4/17/02
to
On 16 Apr 2002 08:02:26 -0700, the disembodied brain of
thr33d...@hotmail.com (stank-monkey) transmitted thus:

Of course, if your game includes monsters who can walk through walls
or (worse) dig through walls, the player may have little choice but to
face the out-of-depth foes.

R. Dan Henry, Grand Pashah of Small Miscellaneous Objects
rdan...@earthlink.net
"Lately, the only thing keeping me from being a serial
killer is my distaste for manual labor." -- Dilbert

arak...@gmail.com

unread,
Jun 11, 2013, 3:50:23 AM6/11/13
to
> If anyone has any
> ideas how i can connect the separate dungeon segments and still
> maintain the cavern-like appearance of the dungeon id appreciate it.


I assume your using the 'cellular-automata' method for your caves...

Similar to what Mike_aka_MD has already said, consider filling a horizontal line across the map.

Except, my methodology is to do it when filling your map array with random blocks, before your first iteration or through the cellular-automata function, to achieve something like this:

########################################
##....#.#.#...#..##..##......###..#....#
#...##....###.#..#..#......#...#.#..#..#
#..#.#..#.........###...#...###....##..#
#....##.#.##....###.#.#...##.#.......#.#
#.#.##.##.#.#.....###..####.##..#.#.#..#
###...#....#..#.##.###.#...#.#######...#
##..##.#.......##..#........#..#.####..#
###....#.###....##.#...#...#.......#..##
#....####...##.##..#....##..##..#.#.#..#
#......................................#
#......................................#
###....#.##...##...#..#.#..###....#.#.##
#...#..#.#...#.##.#.#.#..###.#..#....#.#
#..#.#........#....#.##.##..####..#..###
#..#..#..###.####.##.#......#...#.#....#
#.#.#..##..#..#...##.....#..###...#..#.#
##.#..#.#.#..###.....#.#.........#.###.#
###...#.#......#..#...###.#....##.#....#
##....#..##..#.#..##.#..#.####....###.##
##...#.#.###.#.###.#.......#.##.#...##.#
###....#.#.#...##......##.#.....##.#...#
########################################

This will greatly improve the odds of the caverns being connected along the horizontal axis, from the first iteration, and thus will look the most natural after X iterations. I only use 2 iterations with my alogarithm, because of transformations done on the random seeded map.


//
// public void InitMap()
//
// This will clear the middle row of the random map
//
for(int Row = 0; Row < MapHeight; Row++) {
for(int Column = 0; Column < MapWidth; Column++) {
int MapMiddle = (MapHeight / 2);
if(Row == MapMiddle)
{
Map[Column,Row] = OpenSpace; // As opposed to wall
[...]

Joshua Skelton

unread,
Jul 31, 2013, 4:01:42 PM7/31/13
to
I've been working a technique to addresses this issue. It involves generating a network of rectangle nodes and connecting bezier curves, and then applying a standard cellular automata process on top. I have an animated gif of the process on my blog:
http://joshuaskelton.com/post/48733271827

If the entrance/exit is placed within a rectangle and the line width is at least two, I've found it always generates connected maps.

Gerry Quinn

unread,
Aug 2, 2013, 9:18:08 AM8/2/13
to
In article <eceb492f-e8bb-47d5...@googlegroups.com>,
joshua....@gmail.com says...
> I've been working a technique to addresses this issue. It involves generating a network of rectangle nodes and connecting bezier curves, and then applying a standard cellular automata process on top. I have an animated gif of the process on my blog:
> http://joshuaskelton.com/post/48733271827
>
> If the entrance/exit is placed within a rectangle and the line width is at least two, I've found it always generates connected maps.


I've done something similar - I call it the BWG method for 'Black-White-
Grey'.

It starts like yours with the rooms and connections in white. I place
black where I want to be sure there will be a wall. Everything else is
grey.

Then set the grey cells randomly to 50% wall or floor (whatever). I
apply a standard multistep CA method, but after every round of
calculation all black cells are set to wall and all white cells are set
to floor.

It's kind of like what you are doing but more forced, and with forced
walls as well as forced floors. Probably the results come out the same,
but I don't have to worry about paths getting blocked because white
floor always stays floor. Likewise, divisions I mean to enforce are
black and cannot be eroded by the cellular automaton algorithm.

- Gerry Quinn

jlund3

unread,
Aug 2, 2013, 12:47:52 PM8/2/13
to
From that gif it looks like you still generate disconnected maps, except that the area you initially carved out is connected. One thing I do to help in the situation where you have a large connected map with a few small disconnected regions is to just do a flood fill to identify the set of tiles in the large connected region, and then re-fill everything else on the map. I typically do this by simply selecting a random open point, which statistically speaking will usually be part of the large connected region. I then do the flood fill and check to see if the region I choose is larger than some threshold. I usually choose something like .4 * width * cols, but YMMV. If not, I just reject the whole map and start again. On larger maps, this rarely happens, and I just fill in the small unconnected parts of the map. On smaller maps it happens more frequently but the cost of generating a small map is much less. With this method, you are guaranteed to get a connected cave which takes up a decent portion of the map, and you don't have the weird looking straight tunnels between multiple small caves.
0 new messages