Random Maze Generator
Generate random mazes with 8 algorithms, solve with 4 pathfinding methods, animate step-by-step, and export as PNG or SVG. Fully interactive.
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.
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.
A* heuristic uses Manhattan distance:
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
| Algorithm | Type | Bias | Dead-End % | River (Corridor Length) | Time Complexity | Perfect Maze |
|---|---|---|---|---|---|---|
| Recursive Backtracker | DFS + Stack | Long corridors | 10% | High | O(n) | Yes |
| Kruskalβs | Edge-based | Uniform short | 25% | Low | O(n log n) | Yes |
| Primβs | Frontier | Radial from start | 20% | Low | O(n log n) | Yes |
| Aldous-Broder | Random Walk | None (uniform) | 20% | Medium | O(n2) avg | Yes |
| Binary Tree | Per-cell coin flip | NW diagonal | 30% | Low | O(n) | Yes |
| Sidewinder | Row-based runs | Horizontal runs, N bias | 25% | Medium-H | O(n) | Yes |
| Hunt-and-Kill | Walk + Scan | Long corridors | 12% | High | O(n2) worst | Yes |
| Ellerβs | Row-by-row sets | Slight horizontal | 18% | Medium | O(n) | Yes |
| Solver Algorithms | ||||||
| BFS | Queue | Shortest path | - | - | O(n) | - |
| DFS | Stack | First found path | - | - | O(n) | - |
| A* (Manhattan) | Priority Queue | Directed shortest | - | - | O(n log n) | - |
| Wall Follower (Left) | Physical rule | Follows left wall | - | - | O(n) | - |