Spiking neurons

Finished September 2026

LIF Snake

0 → 19.52average food per game, untrained vs. trained, 40 unseen seeds

A Snake controller built from leaky integrate-and-fire neurons and synapses that learn from reward. No ML libraries. Every spike and weight update is my own code.

PythonPygameMatplotlibLIF neuronsR-STDP
THE SHORT VERSION

What I tested, built, and learned.

19.52trained, food per game
34.38simple greedy rule, same seeds
100%spiking choice matches argmax

The problem

I wanted to see if I could get a working game agent out of individual simulated neurons instead of a neural-net library, and be able to watch why it picks each move.

What I built

Eleven game-state features become sensory spikes. Sixteen populations, one per heading and food direction, feed three motor neurons (left, straight, right) through synapses that strengthen when a move earns reward. Danger signals inhibit unsafe moves, and the motors compete until one fires.

How I checked it

On 40 seeds it never trained on, it averaged 19.52 food. Untrained, it scores zero, and a random player that only avoids crashing gets 1.0. Its best run was 45, and 29 tests check the neuron code against game behavior.

What didn't work

A one-line rule, take a safe move toward the food, averages 34.4 and beats it on 34 of the 40 seeds. With only 16 contexts and 3 actions, the network is really learning a 48-entry lookup table, and it doesn't find the best entries. The spiking competition also picks the same move as a plain argmax every time, so the neurons implement the decision without changing it. Richer inputs would give the spiking part something to do.

Recorded trained LIF controller playing Snake with motor spike and action-value charts
FIXED-SEED EVALUATION REPLAY · SCORE 15
LIVE CONTROLLER TRACE
STEP 001
heading eastfood westfood southpath clear
left25.000 spikes
straight25.000 spikes
right48.002 spikes
SELECTED ACTIONRIGHTreward +0.08

WHAT THE NETWORK IS DOINGFood is behind-left in absolute space. The east × south context activates most strongly, so the right motor spikes twice and wins the inhibitory competition.

Observable inputs, action values, and spikes, not a generated chain-of-thought.

Details

  • Reward-modulated spike-timing plasticity
  • Saved weights and fixed-seed evaluation
  • Greedy and random baselines on the same seeds