How the Traffic Jam puzzle works
Traffic Jam belongs to the family of sliding-block puzzles: pieces that can only slide, a crowded board, and one piece that has to reach the way out. This page explains the rules, where these puzzles come from, how to think about them, and how a computer finds the shortest solution of every puzzle on PictorX.
The rules
The board is a 6 x 6 grid with an exit on one side. Cars take two squares and trucks three, and each one is either horizontal or vertical for the whole game: it can slide forwards and backwards along its lane but never turn, lift or pass through another vehicle. One vehicle sliding any distance counts as one move. The goal is to bring the red car to the exit.
A long family of puzzles
Sliding-block puzzles go back to the 1880s and the 15 puzzle, where numbered tiles slide around one empty square. In the 20th century came puzzles with blocks of different sizes, such as the Chinese Huarong Dao and the French L'Âne Rouge, in which one big block has to escape through a gap. The parking-lot version with cars and trucks first appeared in Japan in the 1970s and spread around the world in the 1990s; its rules are the ones Traffic Jam uses.
Strategies that help
Start from the goal: list the vehicles in the red car's way, then for each one ask where it could go and what blocks that place. That chain of blockers is the real puzzle. Vertical trucks in the red car's row are the key pieces, because they need three free squares in their column. Sometimes the red car has to move away from the exit first to let another vehicle pass.
How the puzzles are made and graded
The generator parks a random set of cars and trucks, then explores every position they can reach, often tens of thousands. A breadth-first search back from the positions where the red car is out counts the fewest moves from each one. The puzzle starts from a position at the distance the difficulty asks for: 4 to 8 moves on Easy, 9 to 15 on Medium, and the farthest position found, 16 moves or more, on Hard.
Hard to solve in general
Small boards are easy for a computer, but the general problem is hard. Mathematicians have shown that deciding whether a sliding-block puzzle of this kind can be solved at all is PSPACE-complete when the board can be as large as you like: no known shortcut beats searching an enormous number of positions.
Frequently asked questions
Why can't a car turn?
That is the rule that makes the puzzle: every vehicle keeps its direction, like a car stuck in a lane. Horizontal vehicles move left and right, vertical ones up and down.
What is the hardest possible puzzle?
On the standard 6 x 6 board, the hardest known starting positions need around 50 moves. The Hard puzzles here are the farthest positions from the exit in their parking lot, usually 16 to 30 moves.
How does the computer find the fewest moves?
It treats every arrangement of the vehicles as a point and every move as a step between two points, then runs a breadth-first search from the arrangements where the red car is out. The first time the search reaches a position, it has found the shortest way from there.
Is a move one square or a whole slide?
A whole slide. Moving a car three squares in one go is one move, and nudging the same car again straight after does not add another.
Ready to try it?
Open PictorX in your browser — no install, no credit card required to start.
Play Traffic Jam