paper - People Server at UNCW - University of North Carolina

advertisement
2D Procedural Dungeon Generation Analysis
Jessica Baron & Aurora Silverwood
University of North Carolina Wilmington
the graph are connected, meaning each “on” vertex is
adjacent to at least one other “on” vertex,
guaranteeing that all traversable vertices ultimately
lead to one another and are therefore connected. The
other benchmark is that the graph should reflect a
desired sparsity ratio between “on”- and “off”vertices, which is defined as approximately 40% of
the graph vertices being “on” and 60% being “off,”
the graph’s percentages being within a 10% deviation
from that ratio.
A “room” is a subset of the set of graph
vertices, consisting of, “on”-vertices that are adjacent
to one another, forming a subgraph of their own of a
width and a height; the width and height are each
constrained by certain minimum and maximum
values that are fractions of the graph’s width and
height values.
A “corridor” is a subgraph of a width and a
height, where either the width or the height has to be
equal to one. Corridors are generated after rooms
have been generated and connect two rooms at a time.
A room cannot be connected to another room, but it
must be connected to at least one corridor. A
corridor must be connected to at least one other
corridor or room, and if it is connected to a corridor,
the corridor it is connected to must be connected to a
room.
Abstract
2D dungeon maps consist of traversable
rooms and corridors, represented by connected floors
and bounded by untraversable walls. The algorithms
used in creating such maps are divided as roomgenerating algorithms and corridor-generating
algorithms. Each algorithm pair is written in Java
using custom graphs, implemented with twodimensional arrays. The efficiency of each algorithm
pair is measured in Theta notation, which is
reflected by the recorded time measurements taken
in milliseconds in creating each map. Each algorithm
has its strengths and weaknesses and can be used in
combination for different desired results.
Key Words: Procedural, dungeon, map, 2D Array ,
graph, goal specific constraints, Java
1. Introduction
The algorithms are subject to a standard set
of rules. The graph representing the map can be set to
dimensions between 30x30 vertices and 500x500
vertices, but for our testing purposes all algorithm
pairs take place on a 60x60 Graph composed of “on”and “off”-vertices. Each pair of algorithms produces
a connected graph. Testing each pair produces
standard deviation percentages that are each is no
more than 10% from the desired percent from 40%
“on” : 60% “off” ratio, and these deviations across
the different algorithm pairs differ slightly from one
another since each pair has its own unique pattern in
creating the map’s rooms and corridors.
The ultimate appeal of the composition of a
map depends on the map’s purpose and the user’s
own subjections; this is one reason why there are
multiple approaches to generating dungeons and why
we narrowed our focus to generating a particular kind
of map for this project.
3. Context
Rogue (1980) (reference figure 3.1),
developed by Michael Toy and Glenn Wichman is
one of the first video games to use procedural
dungeon generation in game. Many games following
it have been considered “Rogue-like.” Due to the
severely limited memory and disk space of early
computers, storing large maps and artwork for a
video game simply were not feasible. Today,
computer memory and processing power are not so
limited.
Procedurally generated dungeon maps
allows game developers to devote more time into
creating complex story and gameplay. The early
games used ASCII representation, similar to our
implementation. However, increased computer
processing power and memory have allowed more
modern games to combine procedural generation
with original artwork to create more appealing and
organic maps such as in the games Blizzard’s Diablo
(1996) (reference figure 3.2) and Minecraft (2009).
2. Formal Problem Statement
With minimal computational iterations
measured in Theta Notation, procedurally generate a
2D video game dungeon map, which is composed of
rectangular “rooms” that are connected by narrower
“corridors” as a graph of w × h vertices, with a width
of w vertices and a height of h vertices. Each vertex
is assigned a state that is either “on” or “off” (“on”
forming the traversable rooms and corridors, and
“off” forming untraversable boundaries, or,
“walls”). One benchmark is that the “on” vertices of
1
Once a room is created, it is added to an
array-list. This algorithm continues to run in a main
while loop until the percentage of the graph
composed of “on” (or, specifically, “room”) vertices
reaches a particular value, which is passed as a
parameter. This value is different according to which
corridor-generating algorithm this room-generating
one is paired with.
4. The Algorithms
We implemented five algorithms that use
and manipulate the base Graph class. Each algorithm
is either a room-generating algorithm or a corridorgenerating one, and these five algorithms are
combined to create five unique, map generating
algorithm pairs.
Efficiencies for Random Room Placement:
In general: Θ (1)
In our case: Θ (n+c+(w*h))
(Reference figure 6.1 for full analysis)
7. BSP Room Placement
The BSP Room Placement algorithm is an
implementation of binary space partitioning. It
partitions the graph into “leaf” objects, each of which
is stored in a tree data structure, starting with the
entire graph as the “root” of the tree.
The leaves are split until a split leaf has
children of a defined minimum size (which is directly
related to the graph’s dimensions as it is the
maximum room size plus a certain modifier, which is
a fraction of the graph’s dimensions, to prevent room
overlapping).
A bottom leaf has no children as it does not
get split. The bottom childless leaves are assigned
rooms (the maximum size of which is smaller than
the minimum leaf size), and these rooms are added to
an array-list in the order of which the leaf objects are
created.
5. The Base Graph
The base graph class is what all of the room
and corridor algorithms modify and build upon. It is
constructed as mainly a 2D array of “vertex” objects,
which each hold a Boolean state value of “on” or “off”
(the default state being “off”), and a String value that
depicts which component of the graph the vertex
belongs to: a “room,” “wall,” or “corridor.” Each
vertex is then stored in the 2D array Graph class the
graph is initialized as a blank dungeon map,
represented by “off” vertices.
Efficiencies for BSP Room Placement:
In general: Θ(1)
In our case: Θ(n+c+(w*h))
6. Random Room Placement
Random Room Placement is a brute force
room-generating algorithm. It is implemented by
randomly generating a room width and height
(bounded by minimum and maximum dimension
values), then randomly picking a vertex (x, y) on the
graph that will be the top-left corner of the room to
place. This potential room is then checked for
overlapping with other “on”-vertices of the graph. If
it will not overlap, the room is “drawn” in the graph,
starting at the top-left corner vertex. Otherwise, try to
place the same room again but at a different vertex
location; there can be a maximum of only 100 tries of
placing the same room in the graph. We have
implemented a separate method that checks for
overlapping other rooms or the borders of the graph
plus a space of three vertices horizontally and
vertically around those other rooms and borders.
(Reference figure 7.1 for full analysis)
8. Random Point Connect
This corridor-generating algorithm accesses
the array-list created by one of the room-generating
algorithms and connects two rooms at a time, which
are two consecutive elements in the room list. The
algorithm connects rooms of this array-list in a brute
force manner, selecting a random vertex each
bordering the two rooms and connecting them the
entire horizontal distance and then the entire vertical
distance (or vice versa; the algorithm randomly
decides in which direction to start). Overlapping
other corridors and rooms with these new corridors is
ignored.
2
Random Point Connect produces different
results according to how the array-list of rooms is
ordered. For example, a room list created by the
Random Room Placement algorithm has no relation
between consecutive elements in the list as randomly
generated room are added as they are successfully
placed, therefore connecting them with Random
Point Connect will often have more overlapping of
corridors.
A room list created by BSP Room
Placement
is created according to bottommost leaf objects,
whose order is reflected by how the BSP tree
splits. Therefore, when these rooms are connected,
the corridors produced are often shorter and do not
overlap as much as with a room list form Random
Room Placement.
where the algorithm carved winding corridors in
taking many iterations to find the destination vertex.
Efficiencies for Drunkard’s Walk:
In general: Θ(n)
In our case: Θ(m* w*h)
(Reference figure 9.1 for full analysis)
10. BSP Corridors
BSP Corridors must be paired with the BSP
Room Placement algorithm as its functionality is
within the classes that handle the binary space
partitioning and relies on particular information
gathered in BSP Room Placement. As with the
previous corridor-generating algorithms, BSP
Corridors connects room pairs from an array-list
generated by a room-generating algorithms and, with
each pair of rooms to connect, selects random border
vertices each from the two rooms.
BSP Corridors has a very similar
implementation to Random Point Connect but varies
slightly as it implements a possibility of one or two
connections between a single pair of
rooms. However, the largest difference between
those two corridor-generating algorithms is how the
pairs of rooms are determined.
BSP Corridors connects rooms of
bottommost leaf objects that share the same parent
leaf. Each pair of sibling leaves is also connected to
one other pair of siblings. Consequently, the graph
result often has very orderly and linear connections
between rooms.
Efficiencies for Random Point Connect:
In general: Θ(n)
In our case: Θ(w*h)
(Reference figure 8.1 for full analysis)
9. Drunkard’s Walk
Our Drunkard’s Walk algorithm is inspired
by an original Drunkard’s Walk algorithm used in
generating maps with cave structures rather than
rooms and corridors. Our implementation of the
Walk is used as a winding room-connecting,
corridor-generating algorithm. As with Random Point
Connect, this algorithm accesses the array-list created
by the one of the room-generating algorithms and
connects pairs of rooms, at a time by randomly
selecting a bordering vertex each of the two rooms.
This algorithm varies from the previous
corridor-generating one as it starts at the first room’s
selected vertex and heads off in the appropriate x and
y directions (whether positive or negative) towards
the second chosen vertex, incrementing n vertices (n
∈ N = {2,3,4,5,6} ) horizontally or vertically with
each iteration, which is randomly decided. Direction
is negated if path reaches too closely to the graph’s
borders. Drunkard’s Walk will keep iterating until it
reaches the other point, or when too many steps have
been taken. (The latter may happen if the Walk is
trapped at a corner of the graph and may reach an
infinite loop if unchecked. If the number of steps
does exceed the certain defined limit, the Walk will
continue from the current vertex to the destination
vertex in a brute force manner to ensure
connectedness.)
This algorithm produces the most varying
results, ranging from sparse maps where corridors
found their destinations quickly, to cave-like maps
Efficiencies for BSP Cooridors:
In general: Θ(1)
In our case: Θ(3c*w*h)
(Reference 10.1 for full analysis)
11. Random Room Placement and Random
Point Connect Analysis
When paired with Random Point Connect,
the maximum percentage parameter passed to
Random Room Placement is 40% (meaning that the
rooms produced by this algorithm pair
should compose no more than 40% of the graph’s
vertices), since the amount of vertices that compose
the corridors of the graph when generated by
Random Point Connect will not be too large.
3
less leaves with the larger minimum leaf size),
anticipating a large amount of vertices to compose
the corridors of the graph when generated by
Drunkard’s Walk.
Efficiencies for Random Rooms and Random
In general:
Θ(w*h) + Θ(w*h) = Θ(2(w*h)) = Θ(w*h)
In our case:
Θ(n) + Θ(n) = Θ(2n) = Θ(n)
Efficiencies for BSP Rooms and Drunkard’s:
In general:
Θ(n+c+(w*h)) + Θ(m* w*h) = Θ(n+c+(w*h)(1+m))
12. Random Room Placement and
Drunkard’s Walk Analysis
In our case:
Θ(1) + Θ(n) = Θ(n)
When paired with Drunkard’s Walk, the
maximum percentage parameter passed to Random
Room Placement is 15% (meaning that the rooms
produced by this algorithm pair should compose no
more than 15% of the graph’s vertices), anticipating a
large amount of vertices to compose the corridors of
the graph when generated by Drunkard’s Walk.
15. BSP Room Placement and BSP Corridors
When paired with BSP Corridors, as with
Random Point Connect, the minimum leaf size
modifier parameters passed to BSP Room Placement
is 1/15 of the graph’s width and 1/15 of the graph’s
height (meaning that more rooms can be placed in the
graph due to being able to split more leaves), since
the amount of vertices that compose the corridors of
the graph when generated by BSP Corridors will not
be too large.
Efficiencies for Random Rooms and Drunkard’s:
In general:
Θ(w*h) + Θ(m* w*h) = Θ(m* 2(w*h))
= Θ(m*w*h)
In our case:
Θ(n) + Θ(n) = Θ(2n) = Θ(n)
Efficiencies for BSP Rooms and BSP Corridors:
In general:
Θ(n+c+(w*h)) + Θ(3c*w*h) = Θ(n+c+(w*h)(1+3c))
13. BSP Room Placement and Random Point
Connect Analysis
In our case:
Θ(1) + Θ(1) = Θ(1)
When paired with Random Point Connect,
the minimum leaf size modifier parameters passed to
BSP Room Placement is 1/15 of the graph’s width
and 1/15 of the graph’s height (meaning that more
rooms can be placed in the graph due to being able to
split more leaves), since the amount of vertices that
compose the corridors of the graph when generated
by Random Point Connect will not be too large.
16. Figures
3.1)
Efficiencies for BSP Rooms and Random:
In general:
Θ(n+c+(w*h)) + Θ(w*h) = Θ(n+c+(w*h))
= Θ(n+c+(w*h))
In our case:
Θ(1) + Θ(n) = Θ(n)
14. BSP Room Placement and Drunkard’s
Walk Analysis
When paired with Drunkard’s Walk, the
minimum leaf size modifier parameters passed to
BSP Room Placement is 1/8 of the graph’s width and
1/8 of the graph’s height (meaning that less rooms
can be placed in the graph due to being able to split
4
Rouge Game displayed on Ascii terminal
3.2)
8.1) Random Point Connect
Diablo I, example of modern dungeon generation
application.
6.1) Random Room Placement
9.1) Drunken Corridors
7.1) BSP Room Placement
10.1 BSP Corridors
5
17. Map Examples
Random Rooms
Random Rooms and Drunkard’s Walk
BSP Rooms
Random Rooms and Random Points Connect
6
BSP Rooms and BSP Corridors
18. Statistics
BSP Rooms and Random Points Connect
BSP Rooms and Drunkard’s Walk
7
the room-vertex : corridor-vertex ratio when paired
with either room-generating algorithm?
4) What defines a “good” dungeon?
5) Why do the five algorithm pairs have more
efficient runtimes when considering that the
dimensions of the graph are limited to be within a
certain range (which is from 30x30 vertices to
500x500 vertices) versus the algorithm pair runtimes
when disregarding any restraints on the graph
dimensions?
17. Why 380?
This set of algorithms and the stated
problem relate to CSC 380 because the problem is a
goal oriented problem for the comprehension of two
dimensional arrays. While each algorithm
successfully achieves vertex percentages being within
10% of our goal ratio of on-vertices to off-vertices
and connects all rooms, they each differ in style, in
the ideal ratio of rooms to corridors, and in the
amount of iterations it takes to complete generating a
dungeon map. Many of the algorithms share similar
properties, such as using the sparsity ratio as a
sentinel value, however each algorithm produces a
uniquely different result. The implementation of
these algorithms can not only be useful to the average
game or level designer, but those who wish create
original maps to use for a base or reference.
20. Answers
1) Random room placement, random points connect
2) Random-rooms checks for overlapping by
checking the location of the room and its area plus
three-vertex-wide border around the room, and
makes sure the room will not touch any other existing
room. The BSP-rooms algorithm handles overlapping
prevention by partitioning space of the graph and
fitting rooms into that space. The max room size is
smaller than that partitioned space, so there would
never be touching or overlapping of rooms.
3) Drunkard’s walk. This algorithm can “walk”
corridors sparsely through the dungeon, or it can
take a long time finding destination rooms and
wander all over. When paired with either randomrooms or BSP-rooms, this algorithm also tends to
produce more corridors in respect to rooms.
18. Future Work
In the future, we plan on creating a method
to form irregular rooms, and another to create a cavelike map with cellular automata. Another plan is to
recode the project into C++ and integrate more
polished GUI elements into the project with using Qt.
Lastly we could to attempt a 3D implementation,
especially after writing the code in C++ and being
able to use it in Unreal Engine.
4) An average sparsity ratio of 40-60% (on-off),
connectedness, non-linear, but ultimately subjective.
5) With the graph dimensions limited to a range of
certain values, many computations (such as drawing
rooms and corridors) actually run in constant time at
both worst and best cases rather than at, for example,
width x height time.
19. Questions
1) Which algorithm pair implements a brute force
approach?
21. Sources
General:
 https://en.wikipedia.org/wiki/Procedur
2) Informally, how is overlapping checked differently
in random-room placement and BSP-room placement
algorithms?
al_generation
Random:
 http://journal.stuffwithstuff.com/2014/1
3) Which corridor-generating algorithm produces the
greatest variation in the “on”-vertex : “off”-vertex
ratio? Which trend does this algorithm produce for
2/21/rooms-and-mazes/
BSP:

8
http://www.roguebasin.com/index.php?
title=Basic_BSP_Dungeon_generation
Drunkard’s:
 http://www.roguebasin.com/index.php?

title=Random_Walk_Cave_Generation
http://www.roguebasin.com/index.php?
title=Basic_directional_dungeon_gene
ration
Examples of 2D dungeons:
 (play)

http://munificent.github.io/hauberk/
(generate)http://www.mythweavers.com/generate_dungeon.php
Images:
 figure 1.0 : Michael Toy & Glenn

Wichman’s Rogue
figure 1.1 : Blizzard’s Diablo I
Dungeon maps
9
Download