Snake is a game about a single decision repeated a few hundred times: turn now, or don’t. The snake never stops moving, it can only grow, and everything it has ever eaten is still on the board as body. Early on the board is enormous and nothing you do matters much. Later, the most dangerous thing on the board is you.
That makes Snake a clean little lesson in planning under a shrinking space. The food is never the hard part. The hard part is still having somewhere to go after you’ve eaten it.
How to play
The board here is 17 squares by 17. You start three squares long in the middle of the board, facing right, and nothing moves until you press a direction.
- Movement. Once started, the snake advances one square per tick in the direction it’s facing. You choose turns; you can’t stop or slow down. The speed you picked (Slow, Normal or Fast) stays fixed for the whole round.
- Turning. You can turn a quarter-turn left or right. A request to reverse straight back into your own neck is ignored. If you press two turns quickly, both are kept and applied on consecutive ticks, so “up, then left” really does go up one square and then left.
- Eating. When the head lands on the diamond, you score one point and grow: the tail stays where it is for that tick, so you end up one square longer. A new diamond appears on a random empty square.
- Crashing. The round ends if the head would move off the board or onto any square of your body. There’s one exception, and it’s important: the square your tail is vacating this tick is empty by the time your head arrives, so following your own tail is legal.
- Filling the board. If you ever grow to cover all 289 squares, there’s nowhere left to put food and you’ve finished the game outright. Nobody expects you to.
Your score is the number of diamonds eaten. Each speed keeps its own best.
A worked example
Here’s the top-left corner of a board mid-game. H is the head, heading right; the digits are body segments counted back from the head, so 4 is the tail. F is the food.
| a | b | c | d | e | |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | 4 | 3 | 2 | 1 | H |
| 3 | |||||
| 4 | F |
The greedy move is to turn down now and then left along row 4. Let’s trace it.
- Down — head to e3. The tail leaves a2.
- Down — head to e4.
- Left — head to d4, then c4, then b4: eat. You’re now six long, stretched from b4 back up column e and along row 2.
That worked, but look at where you are: six squares long, lying along row 4 and up column e, with your head at b4 pointing at the wall one square away. The very next tick or the one after, you must turn up or down, and the food chose that for you. On an open board it’s harmless. On a crowded one, “go straight at the food” is how you end up in a corner facing your own body.
The patient alternative is to keep going right along row 2, loop down, and come back along row 4 from the right. It takes more ticks, but you arrive at the food travelling left with open space below and behind you, and the body you’ve laid down forms a straight wall at the edge instead of a hook in the middle.
Strategy
Stay away from the walls early, then use them late
A wall is a side you can’t escape through. With a short snake, hugging walls just throws away options. With a long snake, the opposite is true: laying your body flat along an edge wastes the least space, because the wall was never usable anyway.
Think about the exit, not the food
Before turning toward food, ask where your head will be pointing once it gets there, and whether that direction has room. A diamond in a corner costs you nothing to reach and a lot to leave.
Chase your tail
The tail is the one part of your body that is guaranteed to move out of the way. When you’re boxed in, turning toward your own tail buys time: you can follow it indefinitely without crashing. Long runs are mostly tail-following with detours for food.
Don’t cut the board in half
If your body splits the empty squares into two regions and your head goes into the smaller one, you’ll run out of room before the body that walls it in has moved away. Before a turn, glance at how much space each side of it leaves.
Lay the body in lanes
Strong players zig-zag: sweep across a row, drop down one, sweep back. The body folds into tidy parallel lanes, the open area stays one big rectangle, and the head always has a known way out. It’s slower per diamond and much safer per round.
The idea underneath
Snake is a path-planning problem on a grid graph: squares are nodes, and neighbours are joined by edges. Each tick you pick one edge out of the head. Your body is a set of nodes you can’t use, and it moves: every tick the tail frees one node and the head claims one. Eating breaks that balance in your disfavour.
The perfect strategy would be a Hamiltonian cycle: a loop that visits every square exactly once and returns to its start. Follow such a loop forever and you can never crash, since your body always sits on the part of the loop you just left, and you’ll eventually pass every diamond.
Here’s the catch. Colour the board like a chessboard. Every move goes from one colour to the other, so any closed loop alternates colours and uses equally many of each. A 17×17 board has 289 squares: 145 of one colour and 144 of the other. No loop can cover them all. On any board with an odd number of squares a perfect cycle is impossible, and some greed is forced on you. (On boards with an even number of squares, such as 16×16, a Hamiltonian cycle always exists.)
So Snake is really a trade-off between two algorithms. Greedy shortest-path-to-food is fast but fragile. Cycle-following is safe but slow. Good play is greedy while the board is empty and increasingly cycle-like as it fills.
Common mistakes
- Leaving a one-square-wide corridor. You can enter it, but you can’t turn around inside it.
- Speeding up too soon. Best scores are kept per speed, so there’s no penalty for learning on Slow.