Tool to automatically generate rectangular (perfect) mazes in 2D. Maze generator based on given height and width, ready to be printed.
Maze Generator - dCode
Tag(s) : Fun/Miscellaneous
dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!
A perfect labyrinth is a geometric figure in two parts. Thus, it does not include an inner loop, that is to say that each wall is connected to all the others in its part. This kind of labyrinth is represented by a graph.
Example: Perfect maze with the + part and the * part: // 5x5
+++++++++++++
+ + +
**** + * + +
* * * +
* ******* ++++
* + +
**** **** + +
* * +
* * **** * +
* * * *
*************
Example: Imperfect maze, with a central island o: // 5x5
+++++++++++++
+ + +
**** + o + +
* * o +
* * oooo ++++
* o o + +
**** o o + +
* o o +
* * oooo * +
* * *
*************
In imperfect labyrinths, some cells are inaccessible.
To get out of a perfect giant labyrinth, select a wall and follow it until finding the exit. Indeed, in this way, keeping the same wall always left or right, the player will walk a whole side of the labyrinth until finding the exit.
This method works only in perfect labyrinths games, in an imperfect maze, along an island leads the player to turn in circles.
A perfect maze has 2 exits (one of which is usually called entrance). If there are multiple exits (3, 4 or more) then it cannot be a perfect maze.
However, to generate a maze with several exits, it is possible to start from a perfect maze generator and add a few holes in the exterior walls to have additional exits.
The size of a labyrinth can be defined with their number of rows and columns (generally called corridors). In practice, the existence of the walls makes the labyrinth slightly larger.
dCode generates ASCII labyrinths whose total size is $ 2n+1 $ with $ n $ the number of corridors (vertical or horizontal).
Among the mazes of plant type, are in France the Labyrinthe de Beaugency or in Belgium the Labyrinthe de Barvaux.
In the cathedrals of Reims and Amiens are drawn on the ground labyrinths.
Maze/Labyrinth is also the name given to a series of films, novels or a board game.
dCode retains ownership of the "Maze Generator" source code. Any algorithm for the "Maze Generator" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "Maze Generator" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "Maze Generator" or any other element are not public (except explicit open source licence like Creative Commons). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.
The content of the page "Maze Generator" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source.
Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).
To cite dCode.fr on another website, use the link:
In a scientific article or book, the recommended bibliographic citation is: Maze Generator on dCode.fr [online website], retrieved on 2025-04-15,