0% found this document useful (0 votes)
33 views5 pages

Room Maze Generation Using PCG Techniques

Uploaded by

Ash
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)
33 views5 pages

Room Maze Generation Using PCG Techniques

Uploaded by

Ash
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

Atlantis Highlights in Engineering, volume 3

3rd Joint International Information Technology, Mechanical and Electronic Engineering Conference (JIMEC 2018)

Procedural Content Generation for Room Maze


Hongqiao Zhang1 ,Xiaohua Zeng1 ,Lingfei Duan1
1. College of Electronic Information and Electrical Engineering, Xiangnan University
Chenzhou, China
7223387zhq@[Link]

Abstract—Procedural content generation (PCG) has recently


become one of the most popular topics in computational II. RANDOM GENERATION OF ROOMS’ AREA
intelligence and video games’ content research. This paper has
proposed an implementation method for procedural content A. Initialization of Room Grid
generation of room maze. Firstly, using flood-fill algorithm to Two dimensional grid is used to generate the room maze
make the random rooms’ center, inner floors and boundary. with size of H rows by columns W, and 4 neighborhood is used
Then tree traversal algorithms which are Depth First Search as the relation between grid cells. Each grid cell has two
(DFS) and Breadth First Search (BFS), used to build the relation
attributes: room state (STA) and room index (RID). The STA
table of rooms and get the door position between different rooms.
indicates the state of the cell in the room, and the RID indicates
Finally, this paper has illustrated the different characteristics of
DFS and BFS with different relation information during which rooms the cell is belong to. The relational values of RID
generating the room maze. This method of procedural content and STA are listed here:
generation can be used to make auto dungeon map for video
games or provide plenty of connected graphs for the AI learning TABLE I. GRID CELL’S ATTRIBUTES
research.
Grid cell’s room state and room index
Keywords—procedural content generation; maze generation; STA RID Details
flood-fill algorithm; tree traversal algorithm; DFS; BFS Initial cell state which belongs to nothing.
If any empty cell has not yet been processed before
Empty -1
stage of boundary generation, it will change to the
I. INTRODUCTION boundary state with RID=-1.
Procedural content generation is a way to generate content Key -1
Initial cell state which belongs to nothing. These
interacting with human automatically. It aims to build endless cells have chance to become Center cells.
possibilities of artistic content which can reduce a lot of Center ≥1 First cell owned by specific room.
manual configuration [1]. In recent years, PCG is used to the Inner ≥1 Room’s floors which can be passed through.
video game content like the sandbox games and dungeon
Blocked cells between rooms. Its RID is a data sets
games. It also can be utilized for generating the content of AI Boundary
-1 or
of its 4 inner state neighborhood cells’ RID. In
learning [2]. values≥1
other situation, RID is -1.
The search-based procedural content generation (SBPCG) Cells which transformed from Boundary state are
Door values≥1
used to connect different rooms.
is a usual way to implement the PCG. It uses different kinds of
search algorithms to explore and change the content or style of This paper initializes all the grid cells’ RID to -1. The cell
the given space [3]. This paper contributes a kind of SBPCG with the position of odd row and odd column sets the STA to
based on flood-fill algorithm and tree traversal algorithms to Key, other cells’ state are Empty. Fig. 2 illustrates an initialized
build infinite kinds of 2-D room mazes [4~6]. The random 7 by 7 grid.
content created by this method has controllable information for
further using. The outline of this method is as following:

Initialize room

Generate rooms’ center and inner floors

Generate boundary, relation information


and connected doors between rooms.

Room maze generation done


Fig. 2. Initialization of the 7 by 7 Grid
Fig. 1. Outline of the Proposed SBPCG Method

Copyright © 2019, the Authors. Published by Atlantis Press.


This is an open access article under the CC BY-NC license ([Link] 265
Atlantis Highlights in Engineering, volume 3

B. Inner Room Generation based on Flood-fill


Current scanned room index is M
Firstly, this paper selects one of the Key cells randomly as Clear the cell stack S0
current room’s Center cell, marking the RID as M (M≥1) and Push the Center cell to the S0
changing the STA to Center. Note that attributes of each cell
with state Empty or Key can be changed by only once during
this stage. Y
S0 Empty?
Secondly, around the Center cell, scanning cells of top-left,
top-right, bottom-left and bottom-right rectangle sub-areas as N
current room’s potential area, each sub-area has different width Pop S0’s top cell as current cell
sW and height sH, the sW and sH are random odd numbers and
ignore the position out of the grid.
Except Center cell, set current
cell’s RID and STA to M and Inner Fill
Over

Push 4 neighborhood cells in


potential room area of current cell
into S0, and these pushed cells’
RID must equals -1.

Fig. 5. Process of Single Room with Flood-fill Algorithom

Initialize room index M to 0


Fig. 3. 5 by 3 top-left Sub-area of Room1

N
Key cell Exist?
Y
M=M+1
New room index is M
Set the RID of the Key cell to M
Set the STA of the cell to Center
Next
Generate random potential room area Stage

Scan Empty and Key cells of current


Fig. 4. Room1’s Random Potential Area
potential area using Flood-fill. Set
Considering the cells’ connectivity of each room, this paper each cell’s RID to M and STA to Inner.
uses the flood-fill algorithm to fill the potential room area,
starting from the position of Center cell. In other words, Fig. 6. Generation of Random Rooms’ Area
sometimes a small part of cells in the room’s potential area are
isolated with the Center cell and should not be contained to
current room.
The RID of each flood-fill scanned Empty or Key cell will
change to the same RID of room’s Center cell, and the STA
should be set to Inner at the same time. The procedure of the
flood-fill algorithm is shown as Fig. 5.
When starting to generate another new room, we should
skip the cells whose RID is not -1. The process of this stage is
illustrated as Fig. 6.
After this stage, the cells’ state of grid should be Empty,
Center or Inner as shown in Fig. 7.

Fig. 7. Random Rooms’ Area of 7 by 7 Grid

266
Atlantis Highlights in Engineering, volume 3

C. The Generation of boundary TABLE II. ROOM RELATION OF FIG. 9’S GRID

In this part, we scan whole grid again. If the RID of current Room Relation Table
cell is smaller than any cell of its 4 neighborhood, or current Source/ Destination/ Boundary cells’ Position [row,col]
Destination Source
cell’s state is Empty, current cell’s STA will recorded as Room Index Room Index
N=2 N=3 N=4
Boundary. This condition will ensure to generate the single-
layer boundary. For each boundary cell, there are N different 2 [5,5],[5,6] [6,4] -
RIDs of its four neighborhood Inner cells. If N>0, the RID of
3 [5,8],[5,9],[6,10] - -
the boundary cell is a data sets of its four neighborhood Inner 1
cells, otherwise, its RID marks as -1. Following Fig. 8 shows 4 - [6,4] -
the boundary generation result based on the Fig. 7’s grid.
6 [8,4],[9,4] - -

3 [1,7],[2,7],[3,7],[4,7] - -

2 4 - [6,4] -

5 [0,4],[1,3],[2,3] - -

5 [3,0],[3,1],[3,2] - -
4
6 [7,0],[7,1],[7,2],[7,3] - -

B. Room Relation based on Tree Traversal


This paper builds the rooms’ relation tree by two kinds of
Fig. 8. Boundary Generation search algorithms: DFS and BFS based on previous relation
table. During the process, each room is accessed only by once.
The procedure of DFS is shown as following figure:
III. GENERATION OF ROOMS’ RELATION

A. Room Relation Table Set current forward depth level L to 1


Initialize the depth level of all rooms to -1
The boundary cell has the basic relation information Clear room stack S0
between different rooms. With this stage this paper regenerates
the rooms in an 11 by 11 grid shown as Fig. 9 to illustrate the
procedure of room relation generation. Select a room as root node
Set selected room’s level to L
Push selected room’s index to S0

Y
S0 Empty?
N
Pop from S0’s top as current node room DFS
L=L+1 Over

Push rooms, whose depth level are -1 and the


relation elements with current node room in
relation table is not empty, to S0.
Fig. 9. 11 by 11 Grid with Generated Rooms’ Area Mark depth level of these pushed rooms as L.
This paper makes the room relation table of the room grid
with boundary cells’ position. The table lists the elements’ Fig. 10. Procedure of Rooms’ DFS
position [row, column] of boundary cells without the repetitive
room relation. If selecting the room3 as the root node, the DFS trees with
The corresponding Table 2 is created by using the grid different N will look like Fig. 11 and Fig. 12. These figures
boundary information based on Fig. 9. With this table, we can show that the rooms’ tree would be more complex with more
use the boundary cells with N≥2 or just N=2 to make the room kinds of boundary cells.
tree traversal.

267
Atlantis Highlights in Engineering, volume 3

The BFS trees with different N look like Fig. 14 and Fig. 15
when select room3 as the root:

Fig. 11. DFS for Room Relation Tree (N=2)

Fig. 14. BFS for Room Relation Tree (N=2)

Fig. 12. DFS for Room Relation Tree (N≥2)


Fig. 15. BFS for Room Relation Tree (N≥2)
The procedure of BFS is shown as following figure:
From the illustrated figures, we can find that DFS has more
Set current forward depth level L to 1 depth levels than BFS. On the contrary, BFS has more room-
Initialize the depth level of all rooms to -1 crossed possibilities than DFS. And the relation table with
condition N≥2 is more complex than condition N=2, or we can
Clear the room stacks S0 and S1
say the latter condition is more controllable than the former.

Select a room as root node C. Generation of Door Cells


Set selected room’s level to L This paper uses relation table with condition N=2 to build
Push selected room to the S0 the room tree traversal and select the Door cells from boundary
cells between each pair of rooms. Here we randomly pick up a
cell of position [i,j] from relation table’s element between
Y S0 Empty? N different two rooms, and change the cell state of corresponding
position to Door. After this step, we have generated the latest
S1 Empty? Pop from S0’s top as random room maze shown as Fig. 16:
current node room
Y N
Push rooms, whose depth
level are -1 and the relation
elements with current node
room in relation table is not
S0=S1 empty, to the S1. And mark
BFS Clear S1 depth level of these pushed
Done L=L+1 rooms as L+1.

Fig. 13. Procedure of Rooms’ BFS Fig. 16. 11 by 11 Room Maze with BFS (N=2)

268
Atlantis Highlights in Engineering, volume 3

Fig. 17 and Fig. 18 illustrate the random room maze position to get the rooms’ center, we use flood-fill algorithm to
generation effect with different grid size implemented by the generate different rooms’ inner floors and boundary cells.
PCG method in this paper. During next stage, boundary information is utilized to get the
room relation table. With different types of elements in the
relation table, DFS and BFS are used to build the room relation
tree and make the door between rooms. Meanwhile this paper
has illustrated the different characteristics of DFS and BFS
under different relation information. This work of procedural
content generation can be used to make auto dungeon map for
video games or provide plenty of connected graphs for the AI
learning research.

ACKNOWLEDGMENT
This work was supported by the Xiangnan University
School Level Scientific Research Project in 2017 under Grant
No. 2017XJ22.

REFERENCES
[1] Flora Amato and Francesco Moscato, “Formal Procedural Content
Generation in Games Driven by Social Analyses,” 2017 31st
Fig. 17. 21 by 17 Room Maze with BFS International Conference on Advanced Information Networking and
Applications Workshops, 2017, pp. 674–679.
[2] Jonathan Roberts and Ke Chen, “Learning-Based Procedural Content
Generation,” IEEE Transactions on Computational Intelligence and AI
in Games, 2015, vol. 3, issue 1, pp. 88–101.
[3] Miguel Frade, F Fernandez de Vega, Carlos Cotta, “Aesthetic Terrain
Programs database for creativity assessment,” 2012 IEEE Conference on
Computational Intelligence and Games, 2012, pp. 350–354.
[4] Zhuang Cai, Lu Ye and Ang Yang, “FloodFill Maze Solving with
Expected Toll of Penetrating Unknown Walls for Micromouse,” 2012
IEEE 14th International Conference on High Performance Computing
and Communications, 2012, pp. 1428–1433.
Fig. 18. 10 by 33 Room Maze with DFS [5] Balram Swami, Ravindar Singh, “Performance Analysis of DFS based
Ordered Walk Learning Routing Protocol in MANET,” 2015
International Conference on Green Computing and Internet of Things,
IV. CONCLUSION 2015, pp. 195–198.
[6] Ishwar Baidari, Ajith Hanagawadimath, “Traversing directed cyclic and
This paper has proposed a PCG method to generate the acyclic graphs using modified BFS algorithm,” 2014 Science and
two-dimensional grid based room maze which has randomized Information Conference, 2014, pp. 175–181.
structure and controllable room relation. Based on the specific

269

You might also like