Maze generation is a fascinating application of graph theory and algorithms. This interactive demo lets you generate mazes using a variety of classic algorithms and types, inspired by the open-source Maze Generator by razimantv.
How to use
- Choose the maze type (Rectangular, Circular, or Polar Warp).
- Choose the algorithm (DFS, Prim’s, Wilson’s, Kruskal’s, Eller’s, Hunt-and-Kill, Binary Tree, or Sidewinder).
- Set the maze size (Small, Medium, or Large).
- Click Regenerate to create a new maze.
- The solution path will appear after 1 second.
Note: Some algorithm and maze type combinations are intentionally disabled. For example, Polar Warp mazes do not support Binary Tree or Eller’s algorithms, as these combinations are not valid or may cause errors. The UI will automatically prevent you from selecting invalid combinations.
Maze Generator
maze.length: 0
maze[0]?.length: undefined
Maze Generation Logic
The maze generator ensures that every maze is solvable and the solution respects all walls. Here’s how it works:
Maze Generation and Solution Logic
Key Features:
- Guaranteed Solvability: The generator retries until a solvable maze is found
- Wall Respect: Solution paths never go through walls
- Non-Trivial Solutions: Prevents straight-line solutions that don’t follow maze passages
- Visual Delay: 1-second delay before showing the solution for dramatic effect
Supported Algorithms
- DFS (Depth-First Search / Recursive Backtracker): Long, winding passages with few dead ends. Feels organic and twisty.
- Prim’s Algorithm: Dense, bushy mazes with many short dead ends. Complex and tangled.
- Wilson’s Algorithm: Uniform spanning tree using loop-erased random walks. Bushy and mathematically uniform.
- Kruskal’s Algorithm: Randomly merges sets by removing walls. Balanced, classic maze appearance.
- Eller’s Algorithm: Processes the maze ring-by-ring (or row-by-row), creating bands and clusters. In circular mazes, this can look especially unique or “strange”.
- Hunt-and-Kill: Random walk with periodic “hunting” for new start points. Organic, with a mix of long and short passages.
- Binary Tree: Simple, directional bias (north/east or outward/clockwise). Fast, but produces mazes with a clear directional pattern.
- Sidewinder: Processes each row (or ring), creating runs and occasionally connecting outward. Directional, with horizontal or circular bias.
Each algorithm produces a visually distinct maze. Try them all for both rectangular and circular mazes to see the differences!