Rectangular Maze Construction by Combining Algorithms and Designed Graph Patterns

—Rectangular digital mazes can be constructed by algorithms automatically. However, visual aesthetics such as the shapes and structures of mazes can’t be created gracefully due to the mechanic characteristics of algorithms. This study proposed a method to combine the maze generation algorithm and the graph patterns designed by designers, in order to make mazes can be constructed not only automatically but also creatively.


INTRODUCTION
Mazes and labyrinths have been used as pure visual art, such as the architectural decoration, or been built as the walk-through puzzles in corn-fields.Digital mazes can be built as stand-alone games, or be applied to construct levels of computer games.Besides, the printed puzzles are still popular till now.Mazes can be constructed either automatically by using algorithms or manually by applying drawing tools [1].With manual method, mazes can be designed more gracefully, but it is very time consuming.While applying algorithms, mazes can be quickly constructed, but due to the characteristics of algorithms, the constructed mazes appear as "mechanical" as compared to those mazes designed by designers manually (Fig. 1).Recent researches attempted to create imageresembling mazes [2,3].They created mazes algorithmically by referencing to the provided images.These mazes are less creative as compared to those designed manually.Furthermore, there may be no suitable images can be referred to while constructing the mazes.How to combine the automatic merits of algorithms and the creative characteristics of designers to build mazes seems to be a good design method.However, little research has been studied for this approach.
Labyrinth is a maze with single path that simply winds its way from start to finish with no branches.Unlike other general mazes, labyrinths are unsuitable for being used as printed puzzles, or be applied to digital games, since there are no ways to go wrong for players.While considering the construction of mazes for computer games, it is expected that the shape or structure of mazes can be adjusted dynamically in order to increase the challenge, to enhance the game entertainment, or to create the consecutive levels.Although current algorithms can produce a whole new maze for a new game level, it is not trivial to either dynamically change some part of the maze, or to control the whole shape or structure of mazes.
In this study, we present a simple way to combine the maze generation algorithm and the graph patterns designed by designers.Due to the modular feature of this method, it is easy to adjust the shape or structure of mazes dynamically.

II. MAZE BASICS
A rectangular maze can be viewed as having m cells in width and n cells in height.Each cell is consisted of up, down, left, and right four cell walls.If the wall between two neighboring cells is broken, these two cells are connected to form a path.A maze is also a puzzle, it essentially contains a starting cell, an end cell, and the player is to find a solution path from the starting cell to the end cell.If there exists one and only one path between any two cells in a maze, the maze is a perfect maze.Otherwise, it is a non-perfect maze.Most of the mazes generated by using algorithms are all perfect mazes [4].
If we regard each cell as a node, the carved invisible walls as links, we can express a maze as a graph.Since there are no circles existing in a perfect maze, a perfect maze is basically a spanning tree [5].The maze generation algorithms are therefore nothing more than algorithms for constructing random spanning trees.Some well-known algorithms include: (1) Depth-first Search (DFS) algorithm [6].(2) Kruskal's algorithm [7].
(3) Hunt-and-Kill maze generation (HKMZ) algorithm [8].By using the DFS algorithm as an example, this method uses the stack as data structure.Firstly, a cell is randomly selected.Then, one of unvisited neighbor cells is selected.The wall between them is deleted, move to this new cell, and push this cell onto stack.If all of the four neighbor cells are all already visited, pop out the cell from stack (backtracking the cell) until one of unvisited neighbor cells of the pop out cell is found, and continues the cell visiting process.When all of the cells are visited, the process ends and maze is constructed at the same time.Since the maze is perfect, there always exists a path between any two selected cells.Therefore, we can select any two cells of a maze puzzle to be the starting and ending cells, respectively.
The generating algorithms involve random mechanisms in the wall-breaking process.As in the DFS algorithm, the order of selecting unvisited neighbor cells plays an important role in forming the path structure of maze.For example, if the unvisited horizontal (left or right side) cells have higher priorities to be selected than the vertical (up or down side) cells in the wall-breaking process, the path structure of maze will become more horizontal.We can assign weights to cells or cell walls in order to control the path structure of maze [4].This principle can be applied to control the appearance of mazes as described in the following section.

III. MAZE APPEARANCE
Previous studies about the maze appearance could be roughly classified into two categories: the maze art, and the image-resembling mazes.For maze art, Christopher Berg, the maze artist, he draws mazes based on monuments and ancient wonders [1].In his works, the path routing pattern of maze could be viewed as being a "brush pattern" while "painted" these works.
Pedersen and Singh [9] considered the maze as bearing resemblance with point distribution patterns generated by stochastic sampling algorithm.They proposed a geometric attraction-repulsion model that can evolve a simple shape into an organic labyrinth.Their works are visually similar to the Traveling salesman art [10].These works of maze art principally tried to generate labyrinth like patterns to mimic the shapes of some natural objects.
Xu & Kaplan [2] proposed an algorithm to construct vortex mazes.A vortex is a collection of passages that wind around each other in a spiral and converge on a central junction, wherein each spiral can be viewed as an alternative of labyrinth with the property of moving the dead end very far along the passage from the entrance.The spirals or vortex mazes are suitable to be used to fill in some ellipse or circular like regions.In the same year, they proposed a method to construct mazes resembling user-supplied images [11].After designer manually partitioned the supplied image into a set of regions and assigned the style parameter for each region, the computer generated the filling-in maze patterns into these regions automatically, then, the walls between regions were broken to form a maze.In order to form maze textures in regions, they generalize the rectangular maze construction method by using two orthogonal streamlines [12] to form the grids.Their method can't preserve the salient structures in the source image essentially.Wan et al. [3] presented a reaction-diffusion simulator based on the cellular neural networks [13] to evolve image-resembling mazes from the source images.Their method could retain the interior structure in the images by using stripe patterns.However, user-specified guiding curves and postprocessing methods should be given to turn the evolved stripe patterns into a maze.
Instead of using the contour information of supplied images to form mazes, Bosch & Herman [14] segmented the supplied image into K by K cells firstly.Then, randomly generated points for each cell (the number of points was proportional to the mean of gray levels in the cell), and applied the algorithm of solving traveling salesman problems (TSP) to find a path connecting these points.This work was similar to the Traveling salesman art proposed by them in the next year [10].For applying the pixel information to generate image-resembling mazes, we can first extract out the image object from background to form a mask, which is used to constrain the area to form the whole shape of maze (Fig. 2(b)), then approximate the binary mask area with rectangular grids, and apply the DFS algorithm to generate maze.Wherein the mean of image gradient magnitude of each cell is used as the searching priority of the cell (greater mean with higher priority) in The image gradient magnitude (Fig. 2(c)) can be estimated by the edge detection filters such as the Sobel operator or the Prewitt filter [15].As shown in Fig. 2(d), the path structure of maze is aligned to the shape texture of flower.Unlike the approach of image-resembling mazes, the puzzle company Conceptis Limited [16] introduced a normally rectangular maze generated by algorithms, however, the cells that make up the solution path, when filled in, will reveal a hidden image.From the view point of puzzle games, maze art works are not suitable for being used as puzzle games, and the path structure of image-resembling mazes are still too "mechanical", as compared to the free-form path structure designed by designers.

IV. THE PROPOSED MAZE CONSTRUCTION METHOD
We proposed that the whole maze is consisted of micro maze cells.Each micro cell can be classified into one of the five abstract categories (Fig. 3), wherein the figure, the black dots represent the entrance or exit of the micro maze cell.By using the B0 cell as an example, it represents the micro maze cell can enter from the left and leave out to the right or vice versa.For the D0 cell as another example, the maze cell can enter from one of the three sides, and leave out by one of the other two sides.The abstract type with index 0 in each category is denoted as the standard or canonical cell.And the other cells with index value greater than 0 can be obtained by rotating the canonical cell.In order to "soften" the path structures of mazes as originally constructed by algorithms, the path details contained in micro maze cells are not specified and can be designed freely by designers.The system architecture of proposed method Figure 3.The abstract types and categories of micro maze cells is shown in Fig. 4. Firstly the area of rectangular maze is segmented according to the size of micro maze cells.The maze construction algorithm (DFS algorithm was used in this study) is applied to get the random spanning tree.By referencing to the "code books" (the abstract types of cells shown in Fig. 3), each cell can be coded and we will get the coded spanning tree.Finally, the maze realization block decodes each coded cell by randomly selects and transforms the corresponding micro maze cell from designed graph pattern libraries to implement the whole maze.V. CONCLUSIONS The creation of engaging mazes requires both information engineering and aesthetic considerations.In this study, the maze construction process can be divided into two parts: the design of graph patterns to be used as micro maze cells, and the algorithm for automatically selecting and transforming the micro maze cells to piece up the maze.This method can gracefully combine the artistic works of designers and the automatic feature of algorithms.Moreover, by mixing or changing the graph patterns of micro maze cells, the appearance of mazes can be dynamically adjusted, and a variety of mazes can be easily constructed.

Figure 2 .
Figure 2. Maze constructed by applying image processing techniques: (a) source image (b) mask area (c) image gradient magnitude (d) the constructed maze (proposed by the author).

Figure 4 .
Figure 4. System architecture of the maze construction method.
category can be implemented by rotating the canonical patterns in the maze realization processing block.

Figure 5 .
Figure 5. Examples of designed graph patterns.Some of the constructed mazes with graph patterns designed by four designers are shown in Fig. 6.It can be seen obviously that the four mazes have distinct styles due to the micro maze patterns designed by different designers.The mazes in Fig. 6 (a) and (b) are perfect mazes, and the mazes in Fig. 6 (c) and (d) are not, since there exist loops in the designed micro cells.By mixing the graph patterns of micro maze cells in the maze generation process can produce a large variety of mazes.As examples shown in Fig. 7, Fig. 7(a) was constructed by mixing the two graph pattern sets as used in Fig. 6 (a) and (b), and Fig. 7 (b) used the pattern sets in Fig. 6 (a), (b), and (c).

Figure 6 .
Figure 6.Examples of mazes constructed by the proposed method.

Figure 7 .
Figure 7. Examples of mazes constructed by mixing the graph patterns of designers: (a) mixing patterns of two designers (b) mixing patterns of three designers.