Free original police games · no download, no sign-up
PatrolArcade

Home › Blog › Behind the Game

How We Built 40 Guaranteed-Solvable Parking Puzzles

Nothing ruins a puzzle game faster than a level that can't be solved, or a "par" score that turns out to be wrong. When we built Squad Car Escape, we wanted to be able to promise two things: every one of the 40 levels has a solution, and the par shown above the board is the true minimum number of moves. This article explains, without any maths degree required, how we made that promise.

Why not design the levels by hand?

Hand-designed sliding-block puzzles can be beautiful, but they have two problems for a small team. First, it is surprisingly easy to build a board that looks solvable and isn't — one truck in the wrong place can lock the whole lot. Second, even when a puzzle is solvable, knowing the shortest solution by hand is very hard. You might find a 14-move solution and never notice a 12-move one.

A computer, on the other hand, is excellent at the kind of patient, exhaustive checking these puzzles need. So we let the computer do the checking, and we did the choosing.

Step 1: think of the puzzle as a map of positions

Imagine every possible arrangement of the vehicles on a board as a place on a map. Two places are connected by a road if a single slide takes you from one to the other. Solving a level means finding a route from the starting place to any place where the police car is at the exit.

For a typical board, that map contains anywhere from a few hundred to many thousands of arrangements. That sounds like a lot, but it's small enough for a computer to visit every single one in moments.

Step 2: search outward, one move at a time

The technique we use is called breadth-first search. Starting from one arrangement, the program first lists every arrangement reachable in one move, then every arrangement reachable in two moves, then three, and so on — never visiting the same arrangement twice.

Because it explores in order of distance, the first time it reaches a solved arrangement, it has found the shortest possible solution. There's no guesswork: any shorter solution would have been found earlier. That shortest distance is exactly what we show as Par.

In the game, one move means one slide of any length. The search counts moves the same way, so par always matches how the move counter works.

Step 3: find the hardest starting position

Here is the part we enjoy most. Instead of just checking a random board, we flip the question around. For each randomly generated set of vehicles, the program:

  1. Explores the whole map of arrangements those vehicles can reach.
  2. Marks every arrangement where the police car is already at the exit.
  3. Searches backwards from all of those solved arrangements at once, measuring how far every other arrangement is from being solved.
  4. Picks the arrangement that is furthest away as the starting position.

That gives us the most challenging puzzle a particular set of vehicles can produce. Boards where the police car can never reach the exit are simply thrown away.

Step 4: choosing 40 levels with a smooth difficulty curve

We generated thousands of boards this way, with different numbers of cars and trucks, and sorted the results by par. Crowded lots often turned out to be unsolvable; sparse lots were usually too easy. The best puzzles came from lots with roughly eight to thirteen vehicles.

From that pool we picked 40 levels and arranged them into four ranks:

  • Rookie (levels 1–10): par 3 to 5.
  • Officer (levels 11–20): par 6 to 9.
  • Detective (levels 21–30): par 10 to 12.
  • Chief (levels 31–40): par 13 up to 31 for the final level.

Hard puzzles with a very long minimum solution are rare — only a handful of the boards we generated needed more than 20 moves — so the last few levels are genuinely special.

Step 5: testing every level automatically

Before release, we ran an automated test that plays all 40 levels by following the solver's moves one at a time and checks two things: that the police car really does reach the exit, and that it takes exactly the number of moves shown as par. All 40 levels passed. We also used a test bot that drags vehicles with a simulated mouse to make sure the controls, the win animation and the star ratings work as intended.

The same solver powers the Hint button

When you press Hint, your browser runs the same breadth-first search from your current position — not the starting one. That's why hints still work after you've moved things around, and why the suggested move is always part of a shortest remaining solution. The search runs right on your device; nothing is sent to a server.

What this means for you as a player

  • If a level feels impossible, it isn't. There is always a way out, and there is always a hint available.
  • Three stars are always achievable: par is a real solution, not a theoretical target.
  • Solving a level in par means you found a solution as good as the computer's.

Ready to test yourself against the solver? Start with our beginner's guide, then try the six solving techniques on the Chief levels.

Play Squad Car Escape