AI Snake

The classic, played smooth. Eat apples, grow, don't bite yourself — or switch on the autopilot and watch a real pathfinding AI fill the board.

0
Score
0
Best
3
Length
Ready
Use the arrow keys, WASD or swipe.
Space pauses · R restarts
Options
Walls
Speed
Sound

How to play

Steer

Arrow keys or WASD on a keyboard; swipe the board or tap the arrows on a phone. You can queue two turns quickly for tight corners.

Grow

Each apple adds one segment and one point. The board has 400 cells, so a perfect game ends at length 400.

Don't crash

In Classic mode walls end the game. In Wrap mode you pass through to the other side — only your own body can stop you.

Pause and restart

Space pauses, R starts over. Your best score for each wall mode is saved in your browser.

Want the longer version, with tactics for the late game? Read how to play Snake well.

Watch the AI

Press Auto and the snake drives itself. This is not a scripted demo — it is a graph search running in your browser on every move, and the route it plans is drawn on the board as faint dots.

The full write-up, with a re-runnable benchmark of all three strategies, is in how the Snake AI works.

Questions

How do you play Snake?
Steer the snake with the arrow keys, WASD, a swipe on the board or the on-screen arrows. Every apple you eat adds one segment and one point. In Classic mode the game ends if you hit a wall or your own body; in Wrap mode the walls let you through to the opposite side, so only your body can end the game. Space pauses and R starts a new game.
What does the AI autopilot do?
Turn on Auto and the snake drives itself. The default Safe search strategy runs a breadth-first search to the apple, then checks that its own tail would still be reachable after eating; if not, it follows its tail into open space instead. The Hamiltonian cycle strategy follows a fixed loop around the board with safe shortcuts and can fill every cell. Greedy search is the naive version with no safety check, kept so you can see why it gets trapped.
Can the AI fill the whole board?
Yes. The Hamiltonian cycle strategy follows a loop that visits every cell exactly once, so it can never run into itself, and it reaches all 400 cells on the 20×20 board. Safe search gets close to a full board but can be cut off late in the game. The numbers from a re-runnable benchmark are in the how-the-AI-works article linked above.
Is the game free and does it need an account?
It is completely free, with no account, no download and no ads inside the game. Everything runs in your browser; the only thing saved is your best score, in your own browser's local storage.
Does it work on a phone?
Yes. Swipe anywhere on the board to turn, or use the on-screen arrows that appear on touch screens. The board scales to fit your screen and the game pauses automatically if you switch tabs.

Add this Snake to your website

Free to embed on any site, blog or classroom page — the game and its AI run in your visitor's browser. Paste this where you want the board to appear:

Keep the credit line under the frame — it is how the widget stays free.

More games with real AI