User Rating 0.0 β˜…β˜…β˜…β˜…β˜…
Total Usage 0 times
Category Generators
Fast
Presets:
Is this tool helpful?

Your feedback helps us improve.

β˜… β˜… β˜… β˜… β˜…

About

Maze generation is a subset of graph theory concerned with producing spanning trees over grid graphs. A correct maze has exactly one path between any two cells. This tool implements 8 distinct generation algorithms - from the bias-heavy Binary Tree to the uniform Aldous-Broder - each producing structurally different passage distributions. Getting algorithm choice wrong matters: Binary Tree creates obvious diagonal bias, Recursive Backtracker creates long corridors with low branching factor, and Kruskal's produces short, uniform dead ends. The generator operates on an W Γ— H grid where each cell stores 4 wall bits. Generation time scales as O(W β‹… H) for most algorithms. The solver supports BFS for guaranteed shortest path, A* with Manhattan heuristic for directed search, and Wall Follower for simulating physical traversal. Note: Wall Follower fails on mazes with isolated loops, which cannot occur in perfect mazes but can in modified ones.

maze generator random maze pathfinding maze solver maze algorithms recursive backtracker maze export

Formulas

The maze is modeled as a grid graph G = (V, E) where |V| = W Γ— H and each vertex connects to at most 4 neighbors. A perfect maze is a spanning tree of this graph: exactly W β‹… H βˆ’ 1 edges, zero cycles.

Walls per cell = 4 bits: N = 1, S = 2, E = 4, W = 8

A* heuristic uses Manhattan distance:

h(c) = |cx βˆ’ goalx| + |cy βˆ’ goaly|

where c is the current cell and goal is the target. The cost function is f(c) = g(c) + h(c), where g(c) is the actual distance from start.

Total passages in a perfect maze: P = W β‹… H βˆ’ 1. Total possible walls in the interior grid: Wtotal = 2 β‹… W β‹… H βˆ’ W βˆ’ H. Walls removed equals passages created.

Reference Data

AlgorithmTypeBiasDead-End %River (Corridor Length)Time ComplexityPerfect Maze
Recursive BacktrackerDFS + StackLong corridors10%HighO(n)Yes
Kruskal’sEdge-basedUniform short25%LowO(n log n)Yes
Prim’sFrontierRadial from start20%LowO(n log n)Yes
Aldous-BroderRandom WalkNone (uniform)20%MediumO(n2) avgYes
Binary TreePer-cell coin flipNW diagonal30%LowO(n)Yes
SidewinderRow-based runsHorizontal runs, N bias25%Medium-HO(n)Yes
Hunt-and-KillWalk + ScanLong corridors12%HighO(n2) worstYes
Eller’sRow-by-row setsSlight horizontal18%MediumO(n)Yes
Solver Algorithms
BFSQueueShortest path - - O(n) -
DFSStackFirst found path - - O(n) -
A* (Manhattan)Priority QueueDirected shortest - - O(n log n) -
Wall Follower (Left)Physical ruleFollows left wall - - O(n) -

Frequently Asked Questions

A perfect maze is a spanning tree of the grid graph: every pair of cells is connected by exactly one path. There are zero loops and zero isolated regions. All 8 algorithms in this tool produce perfect mazes. An imperfect maze contains loops (multiple paths between cells) or walled-off areas. Imperfect mazes are created by removing additional walls after generation.
Binary Tree makes an independent random choice at each cell: remove either the North wall or the West wall (never both, never neither). This forces the top row to be a single corridor running East and the left column to run straight North. The result is a consistent NW-to-SE diagonal texture. For unbiased results, use Aldous-Broder, which produces a uniform spanning tree at the cost of higher expected runtime.
BFS (Breadth-First Search) and A* both guarantee the shortest path in an unweighted grid. BFS explores all cells at distance d before distance d + 1. A* achieves the same result with fewer visited cells by using the Manhattan heuristic to prioritize cells closer to the goal. DFS and Wall Follower do not guarantee shortest paths.
Generation algorithms run in O(n) to O(n2) time where n = W Γ— H. Canvas rendering is the bottleneck. Grids up to 150 Γ— 150 (22,500 cells) render smoothly on modern hardware. Above 200 Γ— 200, disable animation for instant generation. Aldous-Broder should be avoided above 50 Γ— 50 due to its O(n2) expected time.
Yes. The PNG export produces a raster image at the canvas resolution. The SVG export produces a scalable vector file with clean line geometry suitable for laser cutting, CNC routing, or import into Unity/Unreal as a texture. For print, use the browser's print function - the tool includes print styles that hide UI controls and center the maze on an A4 page.
In a perfect maze (no loops), the left-hand Wall Follower always reaches the exit. If the maze contained loops - which this tool does not generate - the follower could circle indefinitely around an island of walls disconnected from the boundary. This tool only generates perfect mazes, so Wall Follower always terminates.