Maze Escape Game

Move your character with the arrow keys, WASD or the on-screen buttons and find the exit of a maze that is generated fresh every time. When you escape, the game compares your moves with the shortest possible route.

Moves: 0Time: 0s

Move with the arrow keys, WASD or the buttons above. The timer starts on your first move, and cells you have visited are tinted.

How to play

The green square in the top-left corner is the start and the red square in the bottom-right corner is the exit. The blue circle is you. Move one cell at a time with the arrow keys, with W, A, S and D, or with the four on-screen buttons. If a wall blocks the direction you press, you hear a low buzz and nothing moves, and the move counter does not change. The counter only counts real steps, so walking into a dead end and back out counts every cell twice. The timer begins at your first successful step rather than when the maze appears, so you can study the layout for as long as you like without it costing time. It stops when you reach the exit, and cells you have crossed stay tinted light blue so you can see which branches you have already tried. Changing the difficulty or pressing "New maze" immediately builds a fresh maze and resets everything. No scores are saved and nothing is sent to a server.

Maze sizes

The three levels differ only in the width of the square grid. The values below are calculated from the same size constants the game code uses. The number of open passages follows from the maze being a connected structure with no loops: a connected set of N cells with no cycles always has exactly N minus 1 links. The interior walls that remain are the total number of cell boundaries, 2n(n minus 1), minus those open passages, which leaves (n minus 1) squared.

LevelGridCellsOpen passagesInterior walls leftCanvas (px)
Easy11Γ—11121120100352Γ—352
Normal17Γ—17289288256408Γ—408
Hard23Γ—23529528484460Γ—460

Shortest-route reference table

Start and exit are always at opposite corners, so even with no walls at all you would need at least 2(n minus 1) moves. Real mazes wind around, so the true shortest route is much longer. The "simulated" columns are random-dependent values: they come from running this page's generator 3,000 times per size and measuring the shortest route each time, and they are rounded to give you a feel for the scale. Every maze you play is different, and running the simulation again gives slightly different numbers. The 10% columns and the median are the values at those positions in the sorted list of 3,000 results.

LevelTheoretical minimumSimulated minimumLowest 10%MedianTop 10%Wall-follower worst case
Easy2020325278240
Normal324068112164576
Hard44601121902741056

The "wall-follower worst case" column is an upper bound, not a measurement. A hand-on-the-wall strategy, which is described below, can traverse each passage at most twice in a maze with no loops, so it can never take more than 2 times (cells minus 1) moves. When you finish, the game shows the exact shortest route length for the maze you just solved next to your own move count.

Efficiency score and two checked examples

Efficiency is shortest moves divided by your moves, times 100. A score of 100% means you never took a wrong turn. Dividing by the shortest route for that particular maze makes scores comparable between mazes, which raw move counts are not: a lucky, short maze would otherwise look like skill.

How the maze is generated, and how the shortest route is found

The generator is the well-known recursive backtracker, implemented with a loop and a stack instead of recursion. Every cell starts with four walls. The algorithm marks the start cell as visited, picks one of its unvisited neighbors at random, knocks down the wall between them and moves there. When a cell has no unvisited neighbors it pops back along the stack until it finds one that does. When the stack is empty every cell has been visited. The random choice uses the browser's Math.random, which is not a cryptographic generator, so this is for fun only and not for anything that needs unpredictability.

The result is a "perfect maze": every cell is reachable and there is exactly one route between any two cells. Because there are no loops, a maze without a solution cannot occur. Mazes from this method tend to have long, winding corridors with relatively few branches, which fits the table above, where the Normal median is more than three times the theoretical minimum.

The shortest route shown after you win is computed with breadth-first search the moment the maze is created. Starting from the start cell, it visits cells in order of distance, never entering a wall, and records each cell's distance. The distance recorded at the exit is the shortest number of moves. This costs time proportional to the number of cells, so even the 529 cell Hard maze is processed instantly.

Tips for escaping faster

Controls and display notes

The arrow keys and WASD are captured by the game, so the page does not scroll while you play and the difficulty menu does not change value when you press an arrow key. After you pick a difficulty the menu releases focus so you can start moving straight away. Keyboard shortcuts with Ctrl, Alt or the Command key are left alone. On a phone, use the four buttons under the board. The canvas shrinks to fit your screen width while keeping its internal resolution, but the Hard maze is 460 pixels wide, so on a small screen its lines look thinner.

Building your skill over time

Repeat the same level a few times and watch your efficiency percentage, not the raw move count. A score around 50 to 70 percent is a reasonable first target, since 100 percent means you saw the whole route before moving. The time is affected by your typing speed and device, so treat it as a secondary measure. On Hard, the tinted trail is especially useful, because the board is too large to read at a glance and checking each junction against it keeps you from repeating work.

Frequently Asked Questions

Does the maze have more than one path?

No. A maze built this way is a "perfect maze" with exactly one route between any two cells. There are plenty of forks, but no loops, so you can never walk around an obstacle. A dead end always means turning back.

Do bumps against walls add to my move count?

No. Pressing toward a wall only plays a sound. The counter increases only when your character actually changes cell.

When does the timer start?

On your first successful step, not when the maze appears, so time spent studying the layout is free. It stops at the exit and shows the final time to one decimal place.

Can I play on a phone?

Yes. The on-screen buttons under the board move your character one cell per tap, so no keyboard is needed.

Can I replay the same maze?

No. Each maze is generated at random and not stored, so the same layout will not come back. Reloading the page or changing the difficulty discards the current maze.

More puzzles to try