Tiny Snake

H64 neural policy · browser CPU

Runs locally 24.3 KB model No scripted path

6,211 parameters.
One goal: don’t crash.

I trained a tiny neural network to play Snake by watching a teacher, making its own mistakes, and learning from the situations it actually got into. This page runs the finished model entirely in your browser.

HOW IT WORKS

Same basic idea as an LLM. Much, much smaller.

Both systems turn context into scores for what should happen next. The scale and task are radically different.

Language modelThis Snake model
What goes in

Tokens from a conversation

28 measurements of the board

What comes out

A score for possible next tokens

A score for left, straight, or right

What it learned

Patterns in language and data

Patterns that tend to stay alive and reach food

Scale

Often billions of parameters

6,211 parameters · 24.3 KB

WHAT IT “SEES”

Not pixels—the useful facts

The model gets a compact dashboard: danger near each move, direction to food and tail, current heading, open space, obstacle distances, body length, and distance to each wall.

That makes it tiny and fast, but also limits what it can learn compared with a full vision model.

WHAT IT DOESN’T DO

No hidden perfect-snake trick

There is no Hamiltonian cycle, search tree, or hand-authored route. It makes one local decision at a time. It can still trap itself because it does not plan an entire game into the future.

It also is not told whether the board wraps. It has to infer behavior from the measurements it receives.

THE RECEIPTS

Small enough to email. Fast enough to disappear.

The deployed model is the exact FP32 checkpoint, exported into a raw binary and evaluated by a hand-written JavaScript runtime.

TRAINING STATES220K

100K teacher states plus six DAgger rounds of 20K each.

TEACHER AGREEMENT95.07%

Action accuracy on a fixed, held-out 10K-state validation set.

MODEL SIZE24.3 KB

6,211 FP32 weights. No ONNX or ML framework in the browser.

TRAINED BOARDS10–20

Sizes 10, 12, 16, and 20; 24×24 was held out.

WHY THE RESULT IS INTERESTING

It generalizes beyond the boards it studied.

The model never trained on 24×24 boards, yet over 300 seeded games it still averaged 81 food with wrapping and 56.4 with solid walls. That is not perfect play—but it is learned behavior transferring to a larger world.

24×24 WRAP81.0average food
24×24 BOUNDED56.4average food
Important caveat

95.07% does not mean a 95% win rate. It means the model picked the teacher’s move 95 times out of 100 on individual examples. Snake is a long-horizon game: one bad move can end a run hundreds of steps later.