0% found this document useful (0 votes)
122 views

Labyrinth

1) The document compares three maze generation algorithms: Depth-First Search (DFS), Prim's algorithm, and the Recursive Definition algorithm. 2) It analyzes the path lengths generated by each algorithm, finding that DFS and Recursive Definition produced longer paths on average than Prim's algorithm. 3) Based on the path length analysis, the document recommends DFS as the base for new maze representations, as it meets requirements for generating long maze pathways.

Uploaded by

Kevin Leonard
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views

Labyrinth

1) The document compares three maze generation algorithms: Depth-First Search (DFS), Prim's algorithm, and the Recursive Definition algorithm. 2) It analyzes the path lengths generated by each algorithm, finding that DFS and Recursive Definition produced longer paths on average than Prim's algorithm. 3) Based on the path length analysis, the document recommends DFS as the base for new maze representations, as it meets requirements for generating long maze pathways.

Uploaded by

Kevin Leonard
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

,(((&,*  Tainan, Taiwan August 31, 2015 – September 2, 2015

Examination of Representational Expression in


Maze Generation Algorithms
Aliona Kozlova, Joseph Alexander Brown, IEEE Member, and Elizabeth Reading
Department of Computer Science, Innopolis University, Kazan, Republic of Tatarstan, Russia 420111
[email protected] and [email protected]

Abstract—Procedural content generation is widely used in


game development, although it does not give an opportunity to
generate the whole game level. However, for some game artifacts
procedural generation is the preferred way of creation. Mazes are
a good example of such artifacts: manual generation of mazes
does not provide a variety of combinations and makes games
too predictable. This article gives an overview of three basic
two-dimensional maze generation algorithms: Depth-first search,
Prim’s, and Recursive Definition. These algorithms describe three
conceptually different approaches to maze generation. The path
lengths of the algorithms are compared, and advantages and
disadvantages of each algorithm are given.
Fig. 1. Map Created by the Depth First Search Algorithm

I. I NTRODUCTION

Computational Intelligence algorithms have representation II. A LGORITHMS


as key factor in their expressive ability. Procedural Content A. Depth First Search Algorithm
Generation (PCG), see [1], using search based methods has The DFS is said to be one of the simplest algorithms to
been an emerging topic. Understanding the representation generate maze [5]. Each cell is initialized to have walls on
allowed from current maze generation algorithms allows for a every side. DFS starts with a random cell selection, which is
understanding in the potential expressive ability and control of the start, and goes cell by cell breaking walls until it reviews
the evolution, see [2] for the taxonomic definitions. Statistical all the cells on the field. The following sequence of actions
analysis of two-dimensional maze creation has been examined describes generation algorithm:
for more complex generative methods [3], in terms of path
1) A random cell is selected to be the starting point (in
length, but not for some of the base algorithms which can be
this paper’s implementation the first cell is the starting
used for mazes. This is the goal of this demonstration paper.
point). The cell is put into a stack.
Mazes are useful in genres of games such as rougelikes.
2) One random cell from current cell’s neighbors is picked.
Their generation is a challenging task since there are several
3) If the picked cell has not been checked by the algorithm
things that have to be controlled during generation [4]:
yet, the wall between current cell and random cell is
• the maze has to have an entrance and exit broken. The sequence of actions is repeated from the
• the exit must be reachable from the entrance first point, but with the random cell as a starting point.
• cells that are not included in the path have to be reachable 4) If the picked cell was checked, then we pick another cell
from the entrance from cell’s neighborhood and repeat from Step 3.
• there must be no cycles in the maze 5) If all the current cell’s neighbors were checked, then we
• any cell in the maze should be reachable go to the previous cell and make it current, then proceed
• the amount of walls should be considerable, so that the from Step 2.
player will not reach the exit too fast. 6) The algorithm stops when all the cells are checked.
That is why by now there is plenty of maze generation The sample output from this algorithm is depicted on 1.
algorithms. Three of well-known algorithms are described
below. B. Prim’s Algorithm
The remainder of the paper is organized as follows: Sec- Prim’s algorithm [6], starting with all cells initialized as
tion II examines the Depth-first search (DFS), Prim’s, and walls, takes one random cell and detects its neighbors (fron-
Recursive Definition algorithms. In Section III the algorithms tiers), one of which is randomly added to the maze. When the
are compared. Finally, Section IV gives the conclusions of cell is added to the maze, the new frontiers are detected. The
the study and advises on a representation to use in future algorithm goes on until all the cells are in the maze. So the
generative methods. sequence of the actions is the following:

‹,((( 532
,(((&,*  Tainan, Taiwan August 31, 2015 – September 2, 2015

TABLE I
C OMPARISON BETWEEN THE THREE ALGORITHMS IN PATH LENGTH ON A
16 X 11 MAP

Algorithm Max Min Mean StdDev


Depth First Search 126 40 79.57 20.01
Prim’s 34 24 27.78 1.97
Recursive 106 26 61.29 19.81

algorithm produces mazes that have long and winding passes,


which seems to be a good feature for a maze [9]. Mazes
Fig. 2. Map Created by the Prim’s Algorithm generated by Prim’s algorithm have shorter passes, players
have less chance to get lost in them in comparison with
previous algorithm. Mazes generated recursively dividing the
grid tend to have long straight walls, which makes it easier
to pass through them. The comparison of the algorithms is
presented in Table I.
Using a pairwise two tailed t-test as a comparison method
between means, it was found that both DFS and the Recursive
algorithms provided longer path lengths than Prim’s algorithm
(P < 0.0001) and that DFS provided longer paths than the
Recursive algorithm (P < 0.0001). Therefore, representations
which focus on DFS methods should be used in practice as the
Fig. 3. Map Created by the Recursive Definition Algorithm path lengths provided will be maximal. Further, DFS gives a
longer minimum path length than Prim’s maximal path length.

1) Select random cell. IV. C ONCLUSIONS


2) Detect its neighbors, which are in different set. This study advises to use the DFS algorithm as a base
3) Choose random neighbor. If it is not in the set, delete for new maze representations. This algorithm meets with the
the wall between current cell and the neighbor. requirements for generating long maze pathways. DFS as a
4) Go to step one (but now the random cell is selected maze generator is only able to make trees - which would allow
among cells in the maze). for fast applications of a number of existing algorithms used
5) Repeat until all the cells are in the maze. in games design such as A* to examine the graph.
The sample output from this algorithm is depicted on Figure
R EFERENCES
2.
[1] Julian Togelius, Emil Kastbjerg, David Schedl, and Georgios N. Yan-
C. Recursive Division Algorithm nakakis, “What is procedural content generation?: Mario on the border-
line”, in Proceedings of the 2nd International Workshop on Procedural
Recursive division algorithm[7] starts with the grid with no Content Generation in Games, New York, NY, USA, 2011, PCGames
walls, then randomly divides the grid into two parts and puts ’11, pp. 3:1–3:6, ACM.
[2] J. Togelius, G.N. Yannakakis, K.O. Stanley, and C. Browne, “Search-
a random pass in the wall. The algorithm is the following [8]: based procedural content generation: A taxonomy and survey”, Compu-
1) Divide the grid into two parts by the wall. Put a random tational Intelligence and AI in Games, IEEE Transactions on, vol. 3, no.
pass between two parts. 3, pp. 172–186, Sept 2011.
[3] C. McGuinness, “Statistical analyses of representation choice in level
2) Select the smaller part of the grid to work with. The generation”, in 2012 IEEE Conference onComputational Intelligence and
other is put to the stack. Games (CIG), Sept 2012, pp. 312–319.
3) Go to step one and repeat actions with selected smaller [4] Walter D. Pullen, “Maze classification”, June 2015,
http://www.astrolog.org/labyrnth/algrithm.htm.
part. [5] Ki Sang Lee, “Maze-generating algorithms”, in Physical Mathematics
4) Proceed until the width or height of one of the parts is Conference, 2009.
one cell. [6] Jamis Buck, “Maze generation: Prim’s algorithm”, January
2011, http://weblog.jamisbuck.org/2011/1/10/maze-generation-prim-
The sample output from this algorithm is depicted on Figure s-algorithm.
3. [7] Jamis Buck, “Maze generation: Recursive division”, January
2011, http://weblog.jamisbuck.org/2011/1/12/maze-generation-recursive-
III. C OMPARING A LGORITHMS division-algorithm.
[8] Emre Zorlu, “Perfect maze creation & path finding algorithms”, March
Each of the three algorithms were run 100 times to produce 2012, http://emrezorlu.com/2012/03/20/maze-creation-solving.
[9] D. Ashlock, C. Lee, and C. McGuinness, “Search-based procedural
a 16x11 size maze as an example of their generation. This size generation of maze-like levels”, IEEE Transactions on Computational
was chosen in order to meet with an iOS development aspect Intelligence and AI in Games, vol. 3, no. 3, pp. 260–273, Sept 2011.
ratio. From the figures we can see that different algorithms
give mazes that typically look different. Depth first search

533

You might also like