📜 ⬆️ ⬇️

Labyrinths: classification, generation, search for solutions


This classic post describes in detail the most popular ways of creating and passing mazes. The article is divided into four parts: classification, generation algorithms, labyrinth solving algorithms, and other operations with mazes.

Labyrinth classification


Labyrinths in general (and therefore the algorithms for their creation) can be divided into seven different classifications: dimensions, hyperdimensionality, topology, tessellation, routing, texture and priority. The labyrinth can use one element from each class in any combination.
Dimension: the dimension class essentially determines how many dimensions in space the maze fills. There are the following types:


Hyper-Dimensionality: classification by hyperdimension corresponds to the dimension of an object moving through a maze, and not the maze itself. There are the following types:


Topology: A topology class describes the geometry of a maze space in which it exists as a whole. There are the following types:


Tessellation: the classification of the geometry of the individual cells that make up the maze. Existing types:


Routing: Routing classification is probably the most interesting aspect of maze generation. From is associated with the types of passes within the geometry defined in the categories described above.


Texture: Texture classification describes the style of aisles with different routing and geometry. Texture is not just parameters that can be turned on or off. Here are some examples of variables:


Priority: this classification shows that labyrinth creation processes can be divided into two main types: adding walls and cutting passages. Usually, when generating it, it comes down only to the difference in algorithms, and not to noticeable differences in the labyrinths, but still it is useful to take this into account. The same maze is often generated in both ways:


Other: The above is by no means an exhaustive list of all possible classes or elements within each class. These are only the types of labyrinths that I created myself. Notice that almost every type of labyrinth, including labyrinths with special rules, can be expressed as a directed graph with a finite number of states and a finite number of choices in each state, and this is called labyrinth equivalence . Here are a few other classifications and types of labyrinths:


Algorithms for creating labyrinths


Here is a list of generalized algorithms for creating various classes of labyrinths described above:



There are many ways to create perfect mazes, and each one has its own characteristics. Below is a list of specific algorithms. All of them described the creation of a maze by cutting out passages, however, unless otherwise indicated, each can also be done by adding walls:


Algorithm% dead endsType ofA priorityIs there biasedness?Homogeneous?MemoryTime% solutions
Single route0TreeWallsYesNeverN ^ 2379100.0
Recursive BacktrackertenTreeThe walkwaysYesNeverN ^ 22719.0
Hunt and kill11 (21)TreeThe walkwaysYesNever0100 (143)9.5 (3.9)
Recursive division23TreeWallsYesNeverN *ten7.2
Binary tree25Lots ofBothNotNever0 *ten2.0
Sidewinder27Lots ofBothNotNever0 *122.6
Eller's algorithm28Lots ofBothNotNotN *204.2 (3.2)
Wilson's algorithm29TreeBothYesYesN ^ 248 (25)4.5
Aldous-Brodera Algorithm29TreeBothYesYes0279 (208)4.5
Kruskal AlgorithmthirtyLots ofBothYesNotN ^ 2334.1
Prima algorithm (true)thirtyTreeBothYesNotN ^ 21604.1
Prima algorithm (simplified)32TreeBothYesNotN ^ 2592.3
Prima algorithm (modified)36 (31)TreeBothYesNotN ^ 2thirty2.3
Growing a tree49 (39)TreeBothYesNotN ^ 24811.0
Growing forest49 (39)BothBothYesNotN ^ 27611.0

This table briefly presents the characteristics of the algorithms for creating ideal mazes described above. For comparison, a single-route maze algorithm has been added (theoretically, single-route mazes are ideal). Explanation of columns:


Algorithms for solving labyrinths


There are many ways to solve labyrinths, and each of them has its own characteristics. Here is a list of specific algorithms:


?????
Random MouseoneNotYou/NotYesNot
Wall FolloweroneNotYou/YesYesYes
oneNotYou/YesYesYes
oneYes+NotYesNotYes
Recursive BacktrackeroneYesYouNotYesNotYes
Tremo AlgorithmoneYesYouInside / overNotNotYes
Dead end fillerAll +NotLabyrinthAboveNotYesYes
Cul-de-sac FillerAll +NotLabyrinthAboveNotYesYes
Blind Alley SealerAll +YesLabyrinthNotNotNotYes
Blind Alley FillerEverythingYesLabyrinthAboveNotYesNot
Collision solverAll the shortestYesYou +NotNotNotYes
Search for the shortest pathsAll the shortestYesYou +NotYesNotYes
Finding the shortest path1 shortestYesYou +NotYesNotYes

This table briefly lists the characteristics of the maze-solving algorithms described above. By these criteria, it is possible to classify and evaluate algorithms for solving labyrinths. Explanation of columns:


Other maze operations


In addition to creating and solving labyrinths, you can perform other operations with them:


Algorithm implementations


Source: https://habr.com/ru/post/445378/


All Articles