Snake Game

Use the arrow keys (or the on-screen buttons) to steer the snake, eat food, and grow longer.

Score: 0Length: 1Best: 0

The rules and numbers behind this Snake

The board is a 20 x 20 grid (300 px wide, 15 px per cell), and the snake advances exactly one cell every 120 milliseconds. Speed never changes: eating does not make the game faster, so the pace at the start is the pace at the end. Each piece of food is worth 10 points and adds one segment. A new game begins with a length-1 snake sitting near the middle of the board, motionless until you press the first arrow key. Hitting a wall or any part of your own body ends the run on the spot, and if you fill all 400 cells the game ends with a perfect score. Every figure below is derived from these settings.

Snake lengthScoreShare of boardEmpty cells left
100.3%399
5401.3%395
10902.5%390
201905.0%380
5049012.5%350
10099025.0%300
200199050.0%200
300299075.0%100
4003990100.0%0

Length always equals score / 10 + 1, so the highest possible score is 3990 points (399 pieces of food). The score counts food eaten and nothing else; surviving longer without eating earns nothing.

Getting a feel for the clock

At 120 ms per cell the snake covers roughly 8.33 cells per second. Travel times for a few distances:

Cells travelledTimeNote
50.60 s
101.20 s
202.40 sStraight across one side of the board
404.80 sAcross and back again

If the food is 13 cells away by Manhattan distance (horizontal gap plus vertical gap), even the shortest route takes 1.56 seconds. Most of the game is planning a path that your own body does not wall off during that time.

Controls and input handling in detail

Worked examples

Example 1: distance. With the head at (10, 10) and the food at (3, 16), the gap is 7 columns plus 6 rows = 13 cells, so the fastest possible arrival takes 13 x 0.12 s = 1.56 s. If your body sits on that route you have to detour, and the distance grows.

Example 2: a dead end made of your own body. Imagine a length-4 snake curled into a 2 x 2 square with the head facing the cell the tail is in. Because this version treats the tail cell as occupied, the head cannot enter it and the run ends immediately. Even a short snake can trap itself, so look two cells ahead before every turn.

Example 3: what a perfect game needs. To fill every cell you must eat 399 pieces of food, reaching length 400 and a score of 3,990. A 20 x 20 board has an even number of rows and columns, which means a Hamiltonian cycle exists: a closed loop that visits every cell exactly once. Following that loop forever would, in theory, never crash. It is not the fastest way to eat, though, so it takes much longer than an efficient but riskier run.

Practical tips and common mistakes

  1. Do not hug the walls by habit. Along an edge one side is already blocked, which halves your options. While the snake is short, use the middle of the board.
  2. Move in wide loops as you grow. Zig-zagging in tight spaces makes it easy to cross your own tail.
  3. Take your time with corner food. A corner cell has only one or two approach paths, so secure your way back out before you go in.
  4. Do not mash keys. Only one direction is read per step, so extra presses add nothing, and the last one may not be the one you meant.
  5. On a phone, learn where the buttons are first. Find a grip where your thumb does not cover the board.

Limits and what is stored

Using your result

Convert your score to a length (score / 10 + 1) and compare it with the share-of-board column above to see how much of the grid you can currently fill. If your runs keep ending at a similar length, the cause is usually the same kind of mistake at that stage, so replay the last few cells of the path before you died.

A short history of Snake

Steering a growing line to eat food goes back to late-1970s arcade games such as Blockade, and a version that shipped on Nokia phones in the late 1990s introduced it to a huge audience. Versions differ in speed changes, wall-wrapping and tail-cell collisions, so scores from different Snake games cannot be compared directly.

Frequently Asked Questions

Can I play this on mobile?

Yes. Tap the four direction buttons under the board. The arrow keys and Space shortcuts are for desktop keyboards.

Is my best score saved?

No. It is kept only while this page stays open, and reloading the page clears it.

Why does the opposite arrow key do nothing?

Once the snake has two or more segments, turning 180 degrees would put the head straight into the body, so the input is ignored. Turn up or down first, then turn again to complete a U-turn.

Can the snake pass through walls?

No. Touching a wall ends the game; there is no wrap-around mode here.

What is the highest possible score?

3,990 points, which requires eating 399 pieces of food and filling all 400 cells. The game then ends with a completion message.

More mini-games

Try the color sequence memory game for a memory challenge, Breakout for ball-and-paddle action, or the maze escape game for path-finding.