Snake Game Strategy: How to Get Longer Without Trapping Yourself
Snake is about as simple as a game gets. You steer, you eat, you grow, and you lose the moment your head hits a wall or your own body. It takes seconds to learn, but most players stall at the same kind of score game after game, because the thing that ends a game of Snake is almost never a slow reaction. It's a turn you made ten or twenty moves earlier.
This guide explains where those turns come from and what to do instead. It covers how our Snake works, why heading straight for the food stops working once you're long, the one check that doubles your score, and the pattern that fills the whole board. The numbers come from bots playing the game's own code: 1,000 games for each habit, on the same board, Classic speed and food placement you get.
The rules in our Snake
The board is 20 squares by 20, so 400 squares in all. You start as a single square in the middle, heading right. Each piece of food is worth 1 point and adds one square to your length. When you eat, a new piece appears at once on a random empty square.
On the default Classic speed the snake moves one square every 95 milliseconds, a little over 10 squares a second, and the speed never changes during a round (Slow is 140 ms a square, Fast 65 ms; every number in this guide is for Classic with walls on). You only choose the direction: arrow keys or W A S D on a keyboard, a swipe on a phone. You can't turn straight back on yourself; a key for the opposite direction is ignored.
The game ends when your head moves into a wall or into any part of your body. Since the snake starts as one square and every point adds one, a full board means 399 points, the highest score possible.
Two details are worth knowing before anything else.
Quick turns wait in line. The game keeps up to two turns and plays one per step, each checked against the turn before it. Heading right, up then left within the same 95 ms gives up on this step and left on the next: a tight U-turn in two quick presses. A key for the direction you're already going, or straight back the way the previous turn points, is ignored.
The square your tail is leaving still counts as your body. In some versions of Snake you can follow your own tail with no gap, because the tail moves out of the way as the head moves in. Not here: the game checks for a crash before the tail moves.
Why chasing the food stops working
The obvious way to play is to go straight for the food by the shortest route. While the snake is short, that's exactly right: there's nothing in the way, and every move toward the food is a move well spent.
We gave a bot exactly that habit: the shortest free path to the food every time, and when no path exists, the move with the most room. Over 1,000 games it averaged 77.2 points, with a median of 78, and its best game reached 135. It needed only 17.1 moves per piece of food, so it was fast. Three times out of four, it died by running into its own body.
Here is how that happens, in a real game the bot played:
The food appeared inside a pocket that the snake's own body had walled in. The shortest path led straight in. Once the head entered, there were 23 free squares for a body 60 squares long, and the walls of the pocket were parts of the body that wouldn't move out of the way in time. The bot ate the food and crashed into itself 24 moves later.
That's how almost every game of Snake ends. The fatal move doesn't look dangerous: there's open space ahead and food right there. The danger is that the space is closed, and the snake is longer than the space.
The one check that doubles your score
The fix is a single question to ask before you go for the food: once I've eaten it, can I still reach my own tail?
Your tail is the one part of your body that is always moving away from you. If there's a path from your head to your tail, you can always follow it, and the snake keeps opening up space behind itself. As long as that path exists, you're never trapped, however long you are.
We gave the second bot that check. It takes the shortest path to the food only when, after eating, its head can still reach its tail. If not, it follows its tail and stays away from the food until a safe route opens up. (If that takes longer than about 40 seconds, it gives up waiting and goes for the food, the way a bored player would.)
Over the same 1,000 games, it averaged 155 points, twice the food-chaser, with a median of 153 and a best game of 392, just 7 short of a full board. It's slower, 29.1 moves per piece of food, because it often takes the long way around. That's the trade: a few extra seconds per point for a much longer game.
You can't run a path search in your head at 10 squares a second, but you can ask the same question in simpler terms:
- Before you enter a pocket, check that it has a way out that is open now and will still be open when you get there.
- Don't cut the board in two. When your body runs from one wall to another, the board is split. Make sure the food is on the side with more room, and that you are too.
- Keep your tail in view. If you know where your tail is and you're heading toward it, you're safe.
- Leave a gap of at least one square behind your tail when you follow it, because of the tail rule above.
The loop that fills the board
There's a way to play that can't lose: pick a route through all 400 squares that ends where it starts, and follow it forever. The food always appears somewhere on the route, so you always reach it. Your body always lies along the route behind your head, so you never run into it.
On a 20 by 20 board, a zig-zag does it: go across the top row, then back and forth down the board one row at a time, leaving the left-hand column free, and climb that column to get back to the top. We ran this bot on 100 games. It filled the board every single time, 399 points.
The catch is time. Following the loop means passing every empty square to reach each piece of food, so a full game took 63.5 minutes on average at Classic speed. The improved version takes shortcuts across the board while the snake is short, never skipping past the food and never into the stretch its body still covers, and sticks to the loop once it covers half the board. It also filled the board every time, in 33.3 minutes.
Nobody wants to play a perfect zig-zag for an hour, but the idea is the most useful thing in this guide: the tidier your body, the safer you are. A snake lying in neat parallel lines leaves the free space in one open block. A snake lying in loops and curls leaves pockets everywhere, and every pocket is a possible trap.
A plan that works
Put together, this is how to get from 50 to 150 and beyond.
- While you're short (under about 30), go straight for the food. There's room everywhere and nothing to trap you. Speed matters more than shape here.
- From about 30, start packing your body neatly. When you turn, turn back along your own body, one row over, so your body lies in parallel lines. Hug the walls rather than crossing the middle.
- Before each meal, ask the tail question. If the food is in a pocket and you couldn't get out after eating, wait. Follow your tail around the open side until the pocket opens.
- From about 100, move in zig-zags. Sweep back and forth across the open part of the board instead of cutting toward the food. You'll pass over most of the food anyway.
- Never U-turn in a hurry. A U-turn needs a free row beside you; two quick presses do it, so check the row before you press.
Practice
A game of Snake lasts a minute or two, so it's easy to try one habit at a time. Play a few games where you only check the tail question before each meal, and watch how much later the games end. Then try a few where you keep your body in straight parallel lines. If you like games where thinking a few moves ahead beats fast fingers, our Block Puzzle strategy guide is about keeping a board open for the pieces still to come, and there are more quick games in our arcade games.
More strategy guides
- Sudoku Strategies: How to Solve Any Puzzle Without Guessing
- Minesweeper Patterns: 1-1, 1-2-1, 1-2-2-1 and How to Read the Board
- Solitaire Strategy: How to Win More Games of Klondike
- Chess for Beginners: How to Stop Losing Pieces and Start Winning Games
- Backgammon Strategy: Opening Moves, Safe Play and Winning the Race
- Mahjong Solitaire Tips: How to Clear Every Heap Without Getting Stuck
- Hearts Strategy: What to Pass, When to Duck and How to Shoot the Moon
- Spades Strategy: How to Bid, Play Nil and Stay Out of the Bags
- Best First Words for Five-Letter Word Games, and How to Solve in Four
- FreeCell Strategy: How to Win Almost Every Deal
- Spider Solitaire Strategy: Tips to Win at 1, 2 and 4 Suits
- Checkers Strategy: How to Win More Games of Checkers
- Reversi Strategy: How to Win at Reversi and Othello
- Yacht Dice Strategy: How to Score Higher in Every Game
- Four in a Row Strategy: How to Win at Connect Four
- Dominoes Strategy: How to Win at Dominoes
- Ludo Strategy: How to Win at Ludo
- How to Solve Nonograms: Techniques That Never Need a Guess
- Dots and Boxes Strategy: Chains, the Double-Cross and Control
- Sea Battle Strategy: How to Win at Battleships
- Tic-Tac-Toe Strategy: How to Never Lose (and When You Can Win)
- Hangman Strategy: The Best Letters to Guess and How to Win
- Water Sort Puzzle Tips: How to Solve Every Level
- Block Puzzle Strategy: How to Score High on an 8×8 Board
- Memory Game Tips: How to Find Every Pair in Fewer Moves
- 8 Ball Pool Tips: Aim, Cut Angles, Spin and Winning More Racks
- Brick Breaker Tips: How to Aim the Ball and Clear the Wall Fast
- Word Search Tips: How to Find Words Faster (Tested on 1,000 Puzzles)
- Mini Crossword Tips: How to Solve a 5×5 Fast (Tested on 600 Puzzles)
- Jigsaw Puzzle Tips: Edges, Colour Piles and Finishing Faster (Measured)