Essay · Sep 2026 · 9 min read

I wired a real fly’s brain into my video game

A fruit fly’s mapped nervous system, 2,500 simulated neurons and tens of thousands of attempts at a river-dodging game. What it took to get real learning, and the times I almost fooled myself.

Wiggly Gator is a small arcade game I made. You steer a gator down a river, through gates, around logs and mines. At some point I started wondering whether a real brain could play it. I didn’t mean a neural network loosely inspired by brains. I meant an actual animal’s wiring diagram.

It turns out you can download one.

  • 166,700neurons in the published fly connectome
  • ~2,500of them simulated to play the game
  • 45,000logged attempts on the public site
  • 14,420best score so far, on Hard

The brain

Researchers have now mapped entire insect nervous systems, neuron by neuron and synapse by synapse. The one I used is called MaleCNS, from a team including HHMI Janelia, the MRC Laboratory of Molecular Biology, Cambridge and Google Research. It covers a male fruit fly’s brain and nerve cord: about 166,700 neurons and 25.6 million synapses. It’s free to download.

I didn’t simulate all of it. I started from the fly’s real looming-detection neurons, the ones that notice something about to hit it, and followed each neuron’s strongest connections forward two steps until I reached neurons that send commands down to the body. That left about 2,500 neurons and 11,000 connections. Smell, taste and courtship have nothing to do with dodging a log, so they stayed out.

The data corrected me right away. I expected those visual neurons to feed the fly’s walking-and-steering neurons, because that’s what I remembered from papers. In the real wiring they mostly feed its escape circuit instead, including the famous “giant fiber” neuron. So the escape circuit is what steers the gator.

Plugging it in

Every 65 milliseconds the fly gets a five-cell strip of vision showing the river ahead, from clear to blocked. Its motor neurons split into a left group and a right group, and whichever side fires more wins: steer left, steer right or hold. Those are the same three inputs a person gets. No shortcuts.

The neurons are simple spiking models. They leak, fire when they cross a threshold and reset. Each connection is excitatory or inhibitory depending on which neurotransmitter the sending neuron is predicted to use. That came out to 29% inhibitory, straight from the data, which is what keeps the network from saturating.

The first honest result was bad. Untrained, every run ended in a crash within four seconds. That was fine. An untrained connectome is a reflex, not a strategy.

Getting it to learn

I trained only the roughly 2,300 synapses feeding directly into the motor neurons, with a standard reward rule: connections that were active just before a good outcome get strengthened, and connections active before a bad one get weakened. Getting that to work took a series of failures, each of which taught me something.

  1. 80 identical runs. With no randomness in training, the fly scored exactly 100 and survived exactly 4,008 milliseconds, 80 times in a row. The game and the brain were both deterministic, so there was never a different outcome to learn from.
  2. Random moves taught it nothing. Adding random steering during training created variety, but the randomness came from outside the brain. The learning rule only sees the brain’s own spikes, so it couldn’t connect a lucky random move to anything it had done.
  3. Reward every decision: 100 → 140. Scoring every 65 ms decision, instead of only the final result, produced the first real improvement. It was the same on every evaluation run, and the training curve climbed steadily.
  4. The 140 was mostly a shield. Easy mode makes you invincible for the first four seconds of each life, and the first two gates on that map have no hazards. A lot of that score was the fly coasting through its shield. On Hard, with no shield, doing nothing scores zero.
  5. This fly leans left. Shown a perfectly centered gate, the brain steered left every time. With no input at all, it stayed quiet. The real anatomy isn’t symmetric: 224 of its sensory neurons are on one side and 211 on the other. A calibration drill that rewards going straight through centered gates took its “hold steady” response from 0% to about 97%. It only stuck when I mixed the drill into every training attempt.
  6. Seeing from where it is: 200 → 1,150. The fly’s vision had been computed from the gate’s position in the river, not relative to where the fly actually was. Fixing that raised the untrained score to 200 before any training. With training and a full left, center and right drill, it passed all 10 gates.
  7. It finished the map. After I fixed a subtle bug where evaluation runs quietly changed the random numbers training saw, one checkpoint cleared the whole river: 1,650 points in 24.5 seconds. Left running, it scored 1,100 more on the next river, which it had never seen.

The ceiling, and the needle in the haystack

Then I went looking for the limit. I ran three independent searches of 3,000 attempts each, all starting from a checkpoint that scored 2,530. In 9,000 attempts, exactly one beat it, by 10 points.

Looking at the full logs for 6,000 of those attempts changed how I describe the result. The median was 1,090. Ninety-five percent scored 1,100 or less. The record of 2,540 happened once.

The fly didn’t steadily improve to 2,540. The search found one rare configuration that works, and kept it.

That’s a less exciting story than “it kept getting better.” It’s also the true one. Each fly on the public site replays one fixed checkpoint, so it gets the same score every time you watch it.

Six flies

For a fair comparison, I forked six flies from the same starting brain and gave each one its own random seed and 1,500 attempts per difficulty. They got names, because of course they did.

Best score per fly, same starting brain, 1,500 attempts each
FlyEasyMediumHard
Johnny2,5205,9401,230
Frank2,0306,5401,810
Pickles8,2206,8809,020
Meatball13,9305,8700
Ziggy7,1603,3601,670
Beans4,6704,300390

Meatball posted the best score on any difficulty, 13,930 on Easy, and a flat zero on Hard. Pickles placed near the top on all three, which looked like a wild coincidence until I checked the code. Each seed replays the same sequence of random tweaks every time it runs. Pickles isn’t three lucky draws. It’s one lucky recipe, tested three times.

Later, giving Pickles one more layer of trainable synapses took its Hard score from 9,620 to 14,420, a 50% jump. The same change did nothing at all on Easy or Medium. I still don’t know exactly why, and I’m not going to pretend I do.

What I took from it

  • A deterministic system can’t learn without noise. If every attempt is identical, there’s nothing to compare.
  • Check the data, not your memory of the literature. The wiring I expected wasn’t the wiring that was there.
  • Look for the shield. My first “good” result was measuring how well the fly coasted through invincibility. Check what your benchmark is really rewarding.
  • Fix the input before you train harder. Letting the fly see from its own position helped more than any amount of extra training.
  • Report the distribution, not the best run. One in 6,000 is a very different claim from “it improved.”
  • Determinism cuts both ways. It stalled early training. It also saved me when a good checkpoint got overwritten: I replayed the exact same seeded run and got the identical weights back.

I built this with AI coding agents alongside me, and we kept a running research journal the whole way. It’s almost 900 lines now, and most of it is about things that didn’t work. That’s the only reason I trust the parts that did.

To be clear about what this is: the fly isn’t conscious, and it isn’t clever. It’s a small slice of real wiring, trained with a simple rule, playing a simple game. What’s real is the wiring, the learning and the logs.

Every fly’s best run is replayable. Watch one, or race it head-to-head and see if you can beat a bug.

Race a fly