How It Works
The maze is a perfect maze: a spanning tree over the grid of cells, so there is exactly one path between any two cells and no loops. It's carved with randomized depth-first backtracking. Starting from the top-left cell, the generator repeatedly steps to a random unvisited neighbor, knocking down the wall between them, and keeps a stack of the cells it passed through. When a cell has no unvisited neighbor left, the generator backtracks along the stack until it finds one that does, or the stack runs out and the maze is done.
Play and Speed animate one carve or backtrack at a time, highlighting the current cell and the backtracking stack. Instant jumps straight to the finished maze. Show Solution runs a breadth-first search from the top-left cell to the bottom-right cell and highlights the shortest path — breadth-first search finds it first because it explores cells in order of increasing distance from the start.
The maze is generated from a seed, kept in the page's URL as ?seed=, so
reloading or sharing the link reproduces the exact same maze.