How a maze generator actually builds a maze
Start with a grid of squares and put a wall between every pair of neighbours. A maze generator then knocks walls down, one at a time, following a rule that never connects two squares that are already reachable from each other. When it runs out of moves, every square can be reached and there is exactly one route between any two of them. Puzzle makers call that a perfect maze, and it is what makes an answer key possible: there is one correct path, not several.
The rule you use for knocking down walls decides what the finished maze feels like. This tool offers three, and the difficulty setting is really a choice between them.
- Randomised Prim (Easier): grows outward from a single square, always knocking down a random wall on the current edge of the finished region. It branches constantly, so it ends up with more dead ends than either other method, and almost all of them are short. On a 20x20 grid it averages about 126 dead ends and a correct path of roughly 42 squares, barely longer than the 39-square minimum.
- Randomised Kruskal (Medium): shuffles every wall in the grid and removes it whenever it separates two regions that are not yet joined. Because the maze grows everywhere at once rather than from one point, the texture is the most even of the three. On the same grid it averages about 118 dead ends and a 58-square path.
- Recursive backtracking (Harder): walks forward as far as it can, only backing up when every neighbouring square has already been visited. This is depth-first search, and it produces long snaking corridors instead of a bush. Only about 42 dead ends on a 20x20 grid, but the correct path averages 168 squares, so those few dead ends are long ones.
All three finish with the same guarantee. Nobody gets a maze with no way out.