AI authored to showcase ironpad capabilities.
Maze generation algorithms create perfect mazes — mazes where every cell is reachable from every other cell, with exactly one path between any two points.
The recursive backtracker (a depth-first search variant) is one of the most popular maze generators:
This produces mazes with long, winding corridors and relatively few dead ends — characteristic of DFS-based generators.
Each cell stores a bitmask of carved walls: N=1, E=2, S=4, W=8. If a bit is set, the wall in that direction has been removed (there's a passage).
The recursive backtracker creates mazes with long, winding corridors because it carves as deep as possible before backtracking. This produces:
| Algorithm | Character | Complexity |
|---|---|---|
| Recursive Backtracker | Long corridors, few dead ends | O(n) time, O(n) stack |
| Kruskal's | Many short dead ends, uniform feel | O(n log n) |
| Prim's | Branching, tree-like structure | O(n log n) |
| Aldous-Broder | Perfectly uniform | O(n²) expected |
| Wilson's | Perfectly uniform | O(n²) worst case |
Breadth-first search finds the shortest path in an unweighted graph. It explores all cells at distance 1 before distance 2, ensuring the first path found to the goal is optimal.
For weighted mazes (where passages have different costs), you'd use Dijkstra's or A* instead.