Snake Game
The classic — eat the food, grow longer, and avoid your own tail, with the space-management strategy that decides long games.
Arrow keys or swipe to steer.
There is a strategy that always wins — on half of all boards
Snake has a guaranteed winning strategy. Find a closed route that visits every square exactly once, then follow it forever. The snake can never hit itself, because it is always chasing its own tail, and every apple eventually appears in front of it.
That route is called a Hamiltonian cycle, and on a rectangular grid it only exists when the number of cells is even:
| Board | Cells | Chessboard colours | Winning cycle |
|---|---|---|---|
| 4 × 4 | 16 | 8 / 8 | exists |
| 5 × 4 | 20 | 10 / 10 | exists |
| 5 × 5 | 25 | 13 / 12 | impossible |
| 7 × 7 | 49 | 25 / 24 | impossible |
| 10 × 10 | 100 | 50 / 50 | exists |
| 20 × 20 | 400 | 200 / 200 | exists |
| 21 × 21 | 441 | 221 / 220 | impossible |
The third column is the whole proof. Colour the grid like a chessboard: every move changes colour, so a closed loop has to alternate and therefore needs exactly as many squares of each. A 5 × 5 board has 13 of one and 12 of the other, so no closed loop can cover it — and no amount of cleverness about the route changes the counts.
On an odd board the guaranteed win is therefore simply unavailable. There are Hamiltonian paths — routes that visit every square without returning to the start — but a path leaves the snake stranded at the end rather than looping, so it works once and cannot be repeated. We check the parity rule against the colour counts across 1,521 board sizes on every build; they agree exactly, because they are the same statement.
And nobody plays that way, for a good reason
The cycle strategy is a proof rather than a way to play. Each apple sits somewhere on the loop, so reaching it takes about half a lap, and there are as many apples as there are cells:
| Board | Cells | Moves to fill it |
|---|---|---|
| 6 × 6 | 36 | 648 |
| 10 × 10 | 100 | 5,000 |
| 20 × 20 | 400 | 80,000 |
The cost grows with the square of the cell count, because both the number of apples and the length of a lap grow with the board. Doubling the side multiplies the work by sixteen. A guaranteed win that takes eighty thousand moves is not something anyone would sit through.
This is why snake AIs that actually perform well do something hybrid: take shortcuts while the board is mostly empty, and fall back to following the cycle only once the snake is long enough that a mistake would be fatal. The interesting part of the problem is not whether a safe route exists — on an even board it always does — but how long you can afford to ignore it.
How to use
- Steer with the arrow keys or by swiping.
- Eat food to grow.
- Avoid the walls and your own body.
- Plan your route before the snake gets long.
Frequently asked questions
What is the best strategy for a long game?
Follow the edges and fill space systematically rather than cutting directly to each piece of food. As the snake grows, the constraint stops being reaching the food and becomes leaving yourself a route out afterwards — trapping yourself in a pocket of your own body is what ends most long games.
Is there a perfect strategy?
Yes, in principle. Following a Hamiltonian cycle — a route visiting every cell exactly once — guarantees the snake never traps itself and will eventually fill the board. It is also extremely slow, which is why programs that play well use it as a fallback and take shortcuts when they can prove it is safe.
How old is the game?
The concept dates to Blockade, an arcade game from 1976. It reached a vast audience when Nokia preloaded it on the 6110 in 1997, which made it arguably the first mobile game most people ever played and put it in front of tens of millions.
Why does it get harder as the snake grows?
Because the free space shrinks while the thing you must avoid grows. Early on, almost any route works; late on, a single careless turn can seal off a region you needed. The difficulty curve comes entirely from your own past decisions.
What happens if the snake fills the board?
That is the win condition, and it is genuinely difficult — on a standard grid it means eating every piece of food without a single mistake. Most implementations simply stop, since there is nowhere left to place food.
Does speed increase as you score?
In many versions, yes, which compounds the difficulty of the shrinking space. Whether that is a fair challenge or an artificial one is a matter of taste — some players prefer constant speed, where the difficulty comes purely from the snake's own length.
🔒 This tool runs entirely in your browser. Nothing you enter is uploaded, logged, or stored.