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.
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.
- Safe search (default) runs a breadth-first search to the apple, then plays that path forward in its head and checks whether its tail would still be reachable after eating. If the answer is no, it follows its own tail into open space until a safe route appears.
- Hamiltonian cycle follows a fixed loop that visits every cell once, taking shortcuts toward the apple only when they provably stay clear of the body. It never traps itself and can fill all 400 cells.
- Greedy search is the naive version — shortest path, no safety check. Watch it wall itself in; that is why the other two exist.
The full write-up, with a re-runnable benchmark of all three strategies, is in how the Snake AI works.