Utilia

Maze Generator and Game

Free maze generator with three algorithms and shareable codes. Play with keys or swipes against the clock, show the solution, then print or save a PDF.

Time
0:00
Moves
0
Best time
–

Get from the green entrance (top left) to the red exit (bottom right). Keyboard: arrow keys or WASD, Shift + arrow to run to the next junction. Touch: swipe on the maze to run along a corridor, or use the arrow buttons.

How to use the maze generator

  1. Set the Width (columns) and Height (rows), from 4 to 60 cells each, and pick an Algorithm. Click New maze.
  2. Your position is the dot in the green entrance at the top left. Reach the red exit at the bottom right.
  3. Move with the arrow keys or WASD (ZQSD on a French keyboard). Hold Shift with an arrow to run along a corridor to the next junction. On a phone or tablet, swipe on the maze to run in that direction, or tap the arrow buttons under it for single steps.
  4. The timer starts with your first move and stops at the exit. Your trail is drawn behind you; walking back over it erases it, so it always shows the route you are on.
  5. Stuck? Show solution draws the shortest path from where you stand to the exit. Back to start puts you at the entrance again with the timer reset.
  6. To play on paper, click Print or Download PDF. Tick Add a solution page first if you want the answer on a second page.

Share a maze with its code

Every maze has a Maze code such as b20x15-k3j9x2: the algorithm letter (b, p or k), the width × height, and a random seed. The same code always rebuilds exactly the same maze on any device, so you can challenge a friend to beat your time on the same layout. Type or paste a code and click Load code, or use Copy link to share a web address that opens that maze directly.

The three generation algorithms

All three build a perfect maze: every cell can be reached and there is exactly one path between any two cells, so there are no loops and no closed-off areas. They differ in the texture of the maze:

  • Recursive backtracker (long corridors) walks randomly from cell to cell, knocking down walls, and backs up when it reaches a dead end. It produces long winding passages with few branches: the solution is usually long and takes you across most of the grid.
  • Prim (many short dead ends) grows the maze outward from a random cell, adding a random frontier cell each time. You get lots of short side branches, which makes the maze look busy but the main path easier to see.
  • Kruskal (even, branchy) removes randomly chosen walls between cells that are not already connected (tracked with a union-find structure). The result is evenly branched everywhere, without a visible starting point.

The line above the maze gives the size, the length of the shortest path and the number of dead ends, so you can compare algorithms at a glance.

How the solution is found

The solution uses a breadth-first search (BFS): starting from your cell, it explores all neighbours one step away, then two steps, and so on, until it reaches the exit. Because every step costs the same, BFS always finds the shortest path. In a perfect maze that path is also the only one without backtracking. When the solution was shown during a run, your finishing time is not saved as a best time.

Printing tips

The printed and PDF versions draw clean black walls on white, with the maze code in the title so you can find the same maze again. Sizes around 15 × 15 suit young children; 30 × 30 and above make a solid puzzle for adults. Very large mazes (50 × 60) have thin corridors on an A4 page, so print them at full page size.

Frequently asked questions

Is every maze solvable?

Yes. All three algorithms produce perfect mazes, where every cell is connected to every other one by exactly one path, so there is always a way from the entrance to the exit.

Can I play the same maze again or share it?

Yes. Note the maze code or click Copy link. Loading the same code rebuilds the identical maze, on any computer or phone.

Where is my best time stored?

Only in this browser, per algorithm and size. Nothing is sent anywhere. Clearing your browser data removes it.

How do I play on a touch screen?

Swipe on the maze: your dot runs along the corridor in that direction until the next junction. For precise single steps, use the arrow buttons below the maze.

Why is the PDF different from what I see on screen?

The PDF and print views are made for paper: black walls, no trail and no player dot. The solution page shows the shortest path from the entrance, not from your current position.