Snake
Snake is a classic arcade game where you control a growing snake to eat food while avoiding walls and your own tail.
Key features
- Classic snake gameplay with arrow key controls
- Progressive difficulty as the snake grows
- Score tracking and high score memory
- Colorful graphics with smooth movement
Guide
Snake is one of the oldest and most recognized video games in history. The idea first appeared in arcades in the mid-1970s, where two players each controlled a growing line that left a trail behind it. Home consoles, arcades, and home computers carried many versions through the 1980s. The game reached a mass audience in the late 1990s when mobile phones started shipping with it preinstalled, and for many people it was their first mobile game. The simplicity of the concept, a line that grows as it eats and must avoid hitting walls or itself, makes it endlessly replayable. The rules of Snake are straightforward. You control a line (the snake) that moves continuously in one direction on a grid. You can change direction to up, down, left, or right, but you cannot reverse direction (moving left when already moving right is not allowed because the snake would collide with itself). A food item appears at a random position on the grid. When the snake's head reaches the food, the snake grows longer by one segment and a new food item appears elsewhere. The game ends when the snake collides with a wall or with any part of its own body. Your score is typically the number of food items consumed or equivalently the length of the snake minus its starting length. The playing field is usually a rectangular grid. Common sizes range from 20x20 to 40x40 cells. Some implementations use wraparound edges where the snake exits one side of the board and enters from the opposite side, effectively turning the grid into a torus. Wraparound removes wall collision as a failure condition but adds its own challenges because the snake can appear unexpectedly from the opposite side. Other implementations use solid walls where hitting any edge ends the game. The wall behavior fundamentally changes strategy and should be noted before you start playing. Keyboard controls in browser implementations follow a standard pattern. Arrow keys control direction: up, down, left, right. Some versions also support WASD keys (W for up, A for left, S for down, D for right) for left-handed play or personal preference. The snake moves at a fixed tick rate, meaning it advances one cell per game tick. The tick rate typically increases as the snake grows longer or as you reach higher score thresholds, making the game progressively faster and more challenging. The fundamental beginner strategy is to move in large, sweeping patterns rather than tight turns. New players often make the mistake of chasing food directly, taking the shortest path. This works early when the snake is short, but it quickly leads to trapping situations as the snake grows. Instead, develop the habit of moving in broad loops that keep the snake's body organized. Think of it as mowing a lawn: systematic coverage keeps the path clear. Wall hugging is a basic survival technique. When you do not have an immediate target, move the snake along the walls of the playing field. This keeps the snake's body along the perimeter, leaving the center of the grid open. When food appears, you can safely enter the open center, grab the food, and return to the perimeter. This strategy works well in the early and mid-game before the snake occupies a large portion of the board. The Hamiltonian cycle strategy is the most reliable method for completing a Snake game (visiting every cell on the board). A Hamiltonian cycle is a path that visits every cell in the grid exactly once and returns to the starting cell. If the snake follows a fixed Hamiltonian cycle, it will eventually eat every food item and fill the entire board without ever colliding with itself. The simplest Hamiltonian cycle on a rectangular grid is a zigzag pattern: move across the top row, drop down one row, move back across, drop down, and repeat. This method guarantees a perfect game but is extremely slow because the snake travels the entire cycle between each food pickup. Shortcutting a Hamiltonian cycle is the intermediate strategy that balances safety with speed. Instead of following the full cycle path every time, you take shortcuts across the interior of the cycle when doing so does not break the cycle's integrity. The key rule is that any shortcut must keep the snake on the correct side of the cycle so that it can rejoin the main path before colliding with its tail. Implementing this mentally requires practice, but it dramatically reduces the time between food pickups. Spatial awareness becomes critical as the snake fills more of the grid. At 30 to 40 percent board coverage, you must start planning two or three moves ahead. At 60 percent coverage, every move requires evaluating whether the chosen path leaves enough room for the snake's body to follow without creating a dead end. The most common cause of death at long lengths is self-trapping: the snake's head enters a region of the grid surrounded by its own body with no exit. Before turning into any enclosed area, verify that there is a path out. Food placement in most implementations is random, appearing at any unoccupied cell on the grid. Some versions place food far from the snake's head to increase difficulty. Others use weighted placement to keep food in the center. Understanding the food placement logic helps you position the snake advantageously. If food tends to appear centrally, keeping the snake's head near the center reduces travel time. If food appears anywhere, maintaining a perimeter-hugging strategy ensures you can reach any location without crossing your own body. Speed management is an often overlooked aspect of Snake strategy. In versions where speed increases with length, the difficulty curve is exponential rather than linear. The first 20 food items are easy. The next 20 are moderately challenging. The last 20 before the board fills up are extremely demanding because you are controlling a very long snake at high speed with very little empty space. Prepare for this curve by building good habits early. Clean, systematic movement at low speeds translates directly to survival at high speeds. The grid-based movement system means that all positions are discrete. The snake does not move smoothly between cells in terms of game logic. It jumps from one cell to the next each tick. This means timing your direction changes to align with game ticks is important. If you press a direction key between ticks, it queues the direction change for the next tick. In fast implementations, pressing keys too quickly can queue multiple direction changes, sometimes causing unintended reversals. Most well-built browser versions prevent illegal moves (reversals) by ignoring inputs that would cause the snake to move into its own neck. Input buffering varies between implementations. Some versions store only the most recent key press, while others maintain a queue of two or more inputs. A two-input buffer lets you make rapid L-shaped turns (pressing right then down in quick succession) that execute over two consecutive ticks. This is extremely useful for navigating tight spaces. Test your browser version's input handling early by making quick successive turns to understand how it processes rapid inputs. At advanced levels of play, the snake occupies most of the board and you need to think in terms of channels and corridors. The empty cells form narrow paths that the snake's head must navigate while its body fills and then vacates the space behind it. The snake essentially chases its own tail through these corridors. The trick is maintaining a corridor structure that always connects back to the tail. If the head can always reach the tail, the game can continue indefinitely (or until the board is full). A common scoring variant adds bonus points for speed. Instead of just counting food items, the score includes a time bonus that decreases the longer you take to eat each food item. In these variants, the safe but slow Hamiltonian cycle strategy yields lower scores than a faster, more aggressive approach. You need to balance risk against reward. Taking shortcuts that reduce time per food item increases your score but also increases the chance of self-collision. Some browser versions include power-ups or obstacles. Speed boost items temporarily increase the snake's movement rate. Slow-motion items reduce it. Obstacles are static blocks on the grid that the snake must avoid. Portals teleport the snake from one position to another. Each modifier changes the optimal strategy. Obstacles reduce available space and require more careful pathfinding. Speed boosts demand faster reflexes and shorter planning horizons. Browser implementation details matter for competitive play. The game loop timing affects how responsive the controls feel. A 60 FPS render loop with a 100ms game tick (10 moves per second) provides smooth animation with a manageable pace. A 50ms tick (20 moves per second) is significantly faster and demands quicker reactions. Some versions let you choose a difficulty level that maps directly to tick rate. Start at a comfortable speed and increase it as your skills develop. Collision detection in browser Snake is cell-based. The snake's head position is compared against all wall cells and all body segment positions each tick. If any match is found, the game ends. This means the snake cannot squeeze between two adjacent body segments or walls. Each cell is either occupied or empty, with no partial overlap possible. Understanding this binary collision model clarifies why certain paths are safe and others are not. Rendering in browser Snake typically uses either HTML canvas or a grid of DOM elements (divs). Canvas rendering is more performant for large grids and fast tick rates. DOM-based rendering is simpler to implement and style with CSS. From a gameplay perspective, the rendering method does not affect the game logic. What matters is the visual clarity: the snake, food, and empty cells should be easily distinguishable. High contrast between these elements reduces visual confusion, especially at high speeds. To improve at Snake, practice with intention. Set specific goals like reaching a length of 50 without dying, or clearing 80 percent of the grid. Replay games mentally after losing to identify the decision that led to the collision. Most deaths can be traced to a specific turn made 3 to 5 moves before the actual collision. Building the habit of forward-thinking, anticipating where the snake's body will be several moves from now, is the single most important skill for long survival runs. The perfect game in Snake means filling every cell on the grid. On a 20x20 board, that is 400 cells. Achieving this requires either following a Hamiltonian cycle or equivalent path that guarantees safety. Very few human players achieve perfect games on large grids at high speeds. The achievement is more common at slow speeds or on small grids. If you are aiming for a perfect game, start with a small grid and slow speed, master the Hamiltonian approach, then gradually increase the challenge.
Frequently asked questions
How do you play Snake?
Use arrow keys to direct the snake toward the food. Each food eaten makes the snake longer. Avoid hitting walls or your own tail.
Is Snake game free?
Yes, completely free and browser-based on WebRecast.
