Snake AI

Pure neural network, ~81% win rate on 20x20

Loading AI model...
This may take a few seconds (73 MB)
0 Current Score
1 Episode
0 Wins (397/397)
Win Rate
0 Max Score

This agent plays Snake on a 20x20 board and wins outright — filling all 400 cells (score 397/397) — about 81% of the time, playing greedily (it always takes its single most-confident move; there is no sampling, search, planner, or rule-based fallback). The network runs live in your browser: every move you see is a forward pass through the real 4.4M-parameter policy.

It seeks food efficiently rather than tracing a fixed space-filling cycle — about 44 steps per food, roughly half the cost of a cycle-following solver. The remaining losses are mostly self-collisions in the final few percent of the board, where the snake has to thread through its own tail.

Win Rate (greedy)
~81%
Steps / Food
~44
Observation
5x39x39
Parameters
4.4M

How it works

The agent uses an egocentric, head-centered observation: a 39x39 window centered on the snake's head and rotated so the head always faces "up", which gives the network translation and rotation invariance. It chooses among three relative actions (turn left, go straight, turn right).

5-channel observation

That is everything the network sees at inference — no flood-fill, no look-ahead, no privileged state. (A flood-fill reachability map was used only as an auxiliary prediction target during training to shape the representation; it is not an input to the deployed model.)

Network & training

Win rate measured over 400 fresh held-out seeds (two disjoint 200-seed blocks: 167/200 and 163/200), greedy (argmax) play, 95% confidence interval roughly 76–88%. The in-browser network is verified to reproduce the PyTorch model's chosen action on every step of a full winning game.