Does this sound reasonable? (Dungeon generation)

G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

I've been reading the conversations about this in other threads and I
had an idea. I just want to get some feedback on it and see if anyone
else thinks this is reasonable or if I overlooked some glaring defect.

I read somewhere (either roguebasin or roguelikedevelopment) about
having a theme for dungeon levels (a list of room templates that are
used up as the dungeon is generated) and was thinking that a
generalization of this might work well. Make a big graph of room
template connections (including empty rooms of various descriptions).
I would assume you would store this a some template along with a list
of what rooms can be connected to this.

After you have that, start by generating the dungeon as a bunch of
blank rooms and hallways. (Probably all rectangular if that makes
things easier.) During this you have to make a second graph that shows
what rooms are connected to what. (If you were doing this for a town,
you could use proximity instead of actual connectivity.)

Finally, apply a random template to a random room. Then for each of
the neighboring rooms apply a template from the list of possible room
templates connected to the first one, making sure that it doesn't
violate the room template graph WRT the other rooms around it. (I
didn't say that right, did I?)

Anyway, once all this is done, the dungeon is finished...

I do see a problem myself (and I'm sure other people will see other
problems). It would be very likely that you could have a room that
couldn't have any of the templates applied to it. (It could happen
with as few as three rooms. If TemplateA can connect to either
TemplateB or TemplateC and TemplateB and TemplateC can only connect to
TemplateA, then a ring of three rooms can't be filled out. You could
say that it's alright for a room to connect to a copy of itself but
that only makes it slightly less likely to occur. [You need four
rooms.])

One other thing... The templates would have to be very detailed to make
this interesting. They would need atleast a list of prerequisites
(such as room size and number of doors) and a list of objects to place
in the room. Just a list of objects would probably be boring though.
This is one place scripting (atleast some weak scripting) would be
helpful. That way, you could say place the throne on the far side of
the room with a double row of columns leading to it. (I can't think of
how you'd do that in a data-driven system when you don't know the
layout of the empty room.)

Well, that's all for now. (In case anyone is wondering, I am in the
process of writing a roguelike but I'm only doing it for my own
amusement. If it every gets to a playable state I'll release it but
right now it's just a white @, a green g and some #s.)
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

ArchMageOmega wrote:
[...]
> After you have that, start by generating the dungeon as a bunch of
> blank rooms and hallways. (Probably all rectangular if that makes
[...]
> Finally, apply a random template to a random room. Then for each of
> the neighboring rooms apply a template from the list of possible room
> templates connected to the first one, making sure that it doesn't
> violate the room template graph WRT the other rooms around it. (I
> didn't say that right, did I?)
>
> Anyway, once all this is done, the dungeon is finished...

Random attempts and haphazard sets of templates aren't a good way to
use prefabs.
A typical template system starts from a small incomplete core and adds
templates to the fringes, to have 1 or 2 constraints only, and/or
ensures there is at least an eligible template for every possible
locus. (See my posts in an old thread about "Wang tiles".)
Another way to generate levels is starting from a closed dungeon and
altering or expanding eligible portions of it, if there is enough room,
according to some rules (e.g. put debris along a corridor, add a secret
door to a wall and a 3 by 3 room with a tresure and a trap behind the
door). Such transformations are independent
If I understand your description correctly, the approach you suggest
has the constraints caused by matching pieces in the middle of a
complete level and the inflexibility of pasting complete templates.
A better combination of template pasting and local alterations would be
using simple template sets (easy to make complete) to build a sparse
and simple skeleton with a good general shape, then grow and complete
it with ad hoc transformations.

> I do see a problem myself (and I'm sure other people will see other
> problems). It would be very likely that you could have a room that
> couldn't have any of the templates applied to it. (It could happen
[...]

With transformations the cause would be a lack of space around a room
and in general the lack of applicable rules (but maybe that room can be
left alone).
With an assembly of templates the cause would be an incomplete set of
pieces (but maybe we can leave a hole).
In both cases a little more game content would solve the problem.

Lorenzo Gatti
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

ArchMageOmega wrote:
>
> Finally, apply a random template to a random room. Then for each of
> the neighboring rooms apply a template from the list of possible room
> templates connected to the first one, making sure that it doesn't
> violate the room template graph WRT the other rooms around it. (I
> didn't say that right, did I?)
>
> Anyway, once all this is done, the dungeon is finished...

I did this for You Only Live Once. Not with themes, but with
tile-based dungeon construction.

http://www.zincland.com/7drl/liveonce

has the source code if you are interested in my approach.

> I do see a problem myself (and I'm sure other people will see other
> problems). It would be very likely that you could have a room that
> couldn't have any of the templates applied to it. (It could happen
> with as few as three rooms. If TemplateA can connect to either
> TemplateB or TemplateC and TemplateB and TemplateC can only connect to
> TemplateA, then a ring of three rooms can't be filled out. You could
> say that it's alright for a room to connect to a copy of itself but
> that only makes it slightly less likely to occur. [You need four
> rooms.])

You need to make a lot of templates. Even with exploiting all types of
symmetry, I ended up with 54 different rooms before I stopped getting
missing tiles in my room builder. I probably still didn't have a
complete set, but that is dealt with by just turning unfillable tiles
into solid wall.

> One other thing... The templates would have to be very detailed to make
> this interesting. They would need atleast a list of prerequisites

I don't think they need to be.

You Only Live Once's templates are very rudimentary, but I really liked
the resulting dungeon's feels. I've been thinking about moving this
dungeone generation into POWDER. It creates cavish levels a bit nicer
than random walk, IMHO.
--
Jeff Lait
(POWDER: http://www.zincland.com/powder)
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

ArchMageOmega <archmageomega@hotmail.com> wrote:
> Finally, apply a random template to a random room. Then for each of
> the neighboring rooms apply a template from the list of possible room
> templates connected to the first one, making sure that it doesn't
> violate the room template graph WRT the other rooms around it. (I
> didn't say that right, did I?)

I'm having problems visualizing this; can you give examples of templates
and what they would be connected to? It seems like there would always be
some way to hack around it... like...

If you make a house, you know what it has to have, like a kitchen and a
bathroom. Then there's a random number of bedrooms, and an x% chance
that there is a dining room, living room, basement, attick, closets, et
cetera. Obviously this is mostly different than the way you're
describing, and I can see how you could run into trouble if you got
trapped at a place where your code tried to put two bathrooms next to
each other. I think I'd understand more if I could see some examples of
what you are trying to do.

--
Jim Strathmeyer
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

The Sheep wrote:
> Not sure whether it would really work, but I think it's worth a try.

That is a pretty good idea but I do see a couple of problems with it.
It would be very easy to end up with rooms connected to other rooms
that don't make much sense (like having the treasure room connect
directly to the entry room). The other thing is that a random dungeon
probably doesn't have a Euler path.

I guess I didn't explain my idea very cleary (sorry about that) so
here's a small example, a stereotypical goblin cave.

Starting with the templates:

Goblin Treasure Horde:
- Can connect to: Goblin Throne Room
- Requirements: One exit, atleast 5x5
- Special: Unique
- (Describe how to generate room here)

Goblin Throne Room:
- Can connect to: Goblin Treasure Horde, Goblin Barracks, Goblin Common
Room
- Requirements: Atleast two exits, atleast 5x6 (I'm assuming templates
can be rotated as necessary.)
- Special: Unique

Goblin Barracks:
- Can connect to: Goblin Throne Room, Goblin Common Room, Goblin Sentry
- Requirements: Atleast 5x5

Goblin Common Room:
- Can connect to: Goblin Throne Room, Goblin Barracks, Goblin Sentry
- Requirements: Atleast 6x6

Goblin Sentry:
- Can connect to: Goblin Barracks, Goblin Common Room, EmptyA, EmptyB,
EmptyC

EmptyA:
- Can connect to: Goblin Sentry, EmptyB, EmptyC, Stair Room

EmptyB: (When describing these empty rooms make them different from
each other.)
- Can connect to: Goblin Sentry, EmptyA, EmptyC, Stair Room

EmptyC:
- Can connect to: Goblin Sentry, EmptyA, EmptyB, Stair Room

Stair Room:
- Can connect to: EmptyA, EmptyB, EmptyC
- Special: Required


Ok... Those are the templates. Now if take a dungeon...

####################################
#...#.....#....#.....#.....#########
#.1.......#....#..9..#.....#########
#...#..2.......#........10.#########
#####.....#....#.....#.....#########
#...#.....#.4..##.####.....#.....###
#.........#....#...#####.###.....###
#.3.#######......8.#.......#.13..###
#...#....#######...#.............###
#.....5..###########...12..#.....###
#...#...........####.......#########
#####.####......####.......#########
#.......##......####.......#########
#.......##..7...#####.##############
#...6...##......#.....##############
#.......##.........11.##############
#.......##......#.....##############
####################################

(Ok, hopefully you can read that... It looks alright in the
preview...)

To start take a random room... Let's say 7. And a random template.
Try, Goblin Barracks. (7 satisfies the requirements of Goblin
Barracks.)
7s neighbors are rooms 5 and 11. Goblin Barracks neighbors are Goblin
Throne Room, Goblin Common Room, and Goblin Sentry.
So... room 5 is too small to be the Throne Room or the Common Room, so
let's make it a Sentry.
Now the neighbors of room 5 are room 3 and room 6, and the neighbors of
the Sentry are Barracks, Common, EmptyA(BC)
Room 6 is too small for Common so put a Barracks there. 3 is too small
for either Barracks or Common, so make it empty.
Room 11 is too small for a Throne Room or a Common Room so make it a
Sentry.

Anyway, you get the point. Keep doing this until you fill up the
dungeon.

At some point, you'll probably have a situation like this:
Let's say room 12 is the Throne Room and room 9 is an EmptyA and you're
trying to fill room 10. The Throne Room can only connect to Treasure,
Barracks or Common and the EmptyA can only connect to Stairs, EmptyB/C
or Sentry. So there's nothing that can be put in 10... There are two
things to do in this case (as far as I can see), either include a
default template to deal with this case (maybe a rubble/water/lava/etc.
filled room or even just walls) or backtrack.

The other thing that could happen is you finish filling up the dungeon
and then realize there are no stairs. It would probably be best to
backtrack to fix this.

Anyway, did that make anything clearer or is it more confusing now? :)
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

Dnia 10 Jun 2005 00:43:31 -0700,
ArchMageOmega napisal(a):

> Well, that's all for now. (In case anyone is wondering, I am in the
> process of writing a roguelike but I'm only doing it for my own
> amusement. If it every gets to a playable state I'll release it but
> right now it's just a white @, a green g and some #s.)

How about yet another idea -- based on the ideas posted here recently.

1. Take a bunch of room templates
2. Design a number of nice levels using these templates
3. Generate some statistic data from those levels:
a. Take a random path visiting all the rooms at least once
b. Put the rooms in the order visited by this path\
c. Generate trigrams, as in random text or music generation
4. When you want a new level generated, generate the skeleton
5. Take a random path visiting all the rooms in this skeleton
6. Walk this path and apply the trigrams to determine the kinds
of rooms.

You can of course use much more complicated data structures for the
statistical analysis -- for example, instead of remembering only the kind
of rooms behind you, you could also include the size and number of exits
in the current room and the rooms behind you.

The core of this idea is to linearize the dungeon using random paths.
You also get much more data from a single level, because you can collect
the data several times, with different paths chosen every time.

Not sure whether it would really work, but I think it's worth a try.

--
Radomir `The Sheep' Dopieralski @**@_
(..) 3 Bee!
. . . ..v.vVvVVvVvv.v.. .
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

ArchMageOmega <archmageomega@hotmail.com> wrote:

> Ok... Those are the templates. Now if take a dungeon...

Thanks for the description. It's very clear now.

Can't you just run it, and if it gets stuck (which it should be able to
tell if it has done,) just retry it starting from a different spot?

In fact, it seems like you can even form a tree where each node is a
step in the setup, to get every possible room setup from a map of plain
rooms.

--
Jim Strathmeyer
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

Dnia 10 Jun 2005 13:54:46 -0700,
ArchMageOmega napisal(a):

> The Sheep wrote:
>> Not sure whether it would really work, but I think it's worth a try.
>
> That is a pretty good idea but I do see a couple of problems with it.
> It would be very easy to end up with rooms connected to other rooms
> that don't make much sense (like having the treasure room connect
> directly to the entry room). The other thing is that a random dungeon
> probably doesn't have a Euler path.

First -- you don't need an Euler path. Your path can cross rooms and
corridors multiple times. This will generate proper rooms even when
there are more than two exits.

Second -- you'll probably get the best result by remembering the number
of exits from the current room and, lets say 2 previous room kinds from
your path -- using this data, you set the kind of current room.

Most 'restricted' kinds of rooms, like treasure room or puzzle room
require either single exit or two exits -- so they streamline nicely.


If you insist on forbiding certain room combinations, you can use paths
crossing every corridor instead of paths crossing every room, and make
additional checks every time your path crosses the room -- even when
the room has already assigned it's kind. You can do negative selection --
make the rooms have a set of all possible kinds at first, end then
remove the kinds that are forbidden every time you cross the room.
Then use the original algorithm to select the kinds of rooms from what's
left.

--
Radomir `The Sheep' Dopieralski @**@_
(`') 3 Grrr!
. . . ..v.vVvVVvVvv.v.. .
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

Jim Strathmeyer wrote:
> In fact, it seems like you can even form a tree where each node is a
> step in the setup, to get every possible room setup from a map of plain
> rooms.

Sorry, but now I'm a little confused. Can you explain this a little
better (or maybe give a small example)? :)
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

Ok. I wasn't sure if that's what he was talking about or not.

I haven't tried to think it through myself yet, but what would you do
if you did search the whole tree and couldn't find a solution?

(I'd probably have more to say, but I'm getting sleepy.)
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

Dnia 11 Jun 2005 03:53:08 -0700,
ArchMageOmega napisal(a):

> Jim Strathmeyer wrote:
>> In fact, it seems like you can even form a tree where each node is a
>> step in the setup, to get every possible room setup from a map of plain
>> rooms.
> Sorry, but now I'm a little confused. Can you explain this a little
> better (or maybe give a small example)? :)
I think he means backtracking. You know, like in parsing, you search
a tree of all possible solutions:

Suppose we've got rooms A, B, and C, and we want to assign them room
kinds from among a, b, c.

We obtain something like this:

A:-,B:-,C:-
|
+-- A:a, B:-, C:-
| |
| +-- A:a, B:a, C:-
| | |
| | +-- A:a, B:a, C:a
| | |
| | +-- A:a, B:a, C:b
| | |
| | +-- A:a, B:a, C:c
| |
| +-- A:a, B:b, C:-
| | |
| | +-- A:a, B:b, C:a
| | |
| | +-- A:a, B:b, C:b
| | |
| | +-- A:a, B:b, C:c
| |
| `-- A:a, B:c, C:-
| |
| +-- A:a, B:c, C:a
| |
| +-- A:a, B:c, C:b
| |
| `-- A:a, B:c, C:c
|
+-- A:b, B:-, C:-
| |
| +-- A:b, B:a, C:-
| | |
| | +-- A:b, B:a, C:a
| | |
| | +-- A:b, B:a, C:b
| | |
| | +-- A:b, B:a, C:c
| |
| +-- A:b, B:b, C:-
| | |
| | +-- A:b, B:b, C:a
| | |
| | +-- A:b, B:b, C:b
| | |
| | +-- A:b, B:b, C:c
| |
| `-- A:b, B:c, C:-
| |
| +-- A:b, B:c, C:a
| |
| +-- A:b, B:c, C:b
| |
| `-- A:b, B:c, C:c
|
`-- A:c, B:-, C:-
|
+-- A:c, B:a, C:-
| |
| +-- A:c, B:a, C:a
| |
| +-- A:c, B:a, C:b
| |
| `-- A:c, B:a, C:c
|
+-- A:c, B:b, C:-
| |
| +-- A:c, B:b, C:a
| |
| +-- A:c, B:b, C:b
| |
| `-- A:c, B:b, C:c
|
`-- A:c, B:c, C:-
|
+-- A:c, B:c, C:a
|
+-- A:c, B:c, C:b
|
`-- A:c, B:c, C:c

Of course, you don't bulid the whole tree in the memory.
Some branches will be illegal. Suppose, The rooms A and B
are connected, and there can't be two a-kind rooms next
to each others. Then whole branches get cut out.

Now, what you have to do is to search that tree, either
depth-first (recommended) or breadth-first, skiping the
illegal branches along the way, until you reach a leaf
node which is legal -- and then it's your solution.

Of course, you don't have a guarantee that such a leaf
node exists in the tree -- but since the tree is finite
(but can be very large), you will sooner or later search
it all.

Depth-first search is like reading the above tree as it's
drawn, from top to bottom. It has the advantage that at
any moment you only keep in the memory the nodes from
the path from root to where you are -- no need to
remember the whole tree.
To implement it, you only need a way to undo the
changes -- in this case just setting the room kind to none.

--
Radomir `The Sheep' Dopieralski @**@_
(TT) 3 Waaah!
. . . ..v.vVvVVvVvv.v.. .
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

Dnia 11 Jun 2005 04:39:13 -0700,
ArchMageOmega napisal(a):

> Ok. I wasn't sure if that's what he was talking about or not.

> I haven't tried to think it through myself yet, but what would you do
> if you did search the whole tree and couldn't find a solution?

Either generate different set of empty rooms or use different template.

You could also pick a node that's close to leaf -- has small number of
unfilled rooms. Or remove some of the restrictions, so that not all the
branches get cut off.


--
Radomir `The Sheep' Dopieralski @**@_
(><) 3 Ouch!
. . . ..v.vVvVVvVvv.v.. .
 
G

Guest

Guest
Archived from groups: rec.games.roguelike.development (More info?)

The Sheep <thesheep@ sheep.prv.pl> wrote:
> Dnia 11 Jun 2005 04:39:13 -0700, ArchMageOmega napisal(a):
>> I haven't tried to think it through myself yet, but what would you do
>> if you did search the whole tree and couldn't find a solution?
> Either generate different set of empty rooms or use different
> template.

Yes, this is exactly what I meant. My point is that I don't think you
would generate the whole tree and not find a solution, but you won't
know until you try.

I gave the example of forming the tree because it's a way to get all of
the possible room arrangements given a certain map. This way, from the
possible solutions, you could pick a best solution by some measure, such
as "give me the solution where the throne room is the largest," or "give
me the solution where the treasure room is farthest form the entrance,"
or "give me the solution that contains the most barracks".

--
Jim Strathmeyer