A game character with a real fly brain
Game NPCs usually run on rules someone wrote. This fly runs on 867 neurons and 40,722 connections copied from a real fruit fly brain, the FlyWire map. Nobody wrote "go to the sugar".
Grey is the whole fly brain (139k neurons) at its real shape. Bright dots are the 867 this game runs, at their real positions. Drag to turn it, tap a dot to switch it off.
How it works
The brain is real
The wiring comes from FlyWire, the first complete map of an adult fruit fly brain: 139,255 neurons and their connections, traced from electron microscope images. The firing rules come from the whole-brain model by Shiu et al. (Nature, 2024). Each neuron adds up its inputs, leaks a little, and fires when it crosses a threshold.
Running all 139k neurons would melt a phone, so I ran the full brain on a server first. I fed it sugar, bitter and touch, kept every neuron that ever fired, and kept the real connections between them. That's the 867 you see, and it still behaves like the full brain for these senses.
The body is mine
The brain has no legs here, so a few lines of code connect its outputs to a toy body. I picked the outputs by testing which neurons fire for sugar, bitter and touch on each side:
sugarSide = decoder(106 output neurons) // fitted on 440 brain runs
turn = sugarSide
+ (sugar fading ? turn harder : 0)
- bitter(L) + bitter(R) // DNp42, DNge067
- touch(L) + touch(R) // DNg35, DNg84
eat = MN9 > threshold // proboscis motor neuron
back = bitter or touch too high
Every input to that code is a neuron's firing rate. Nothing in it knows where the sugar is.
The race
The blue fly is a normal game NPC: a behaviour tree I wrote by hand, checked top to bottom every frame. It gets the exact same senses as the brain fly, the same antennae and the same sugar smell. One was designed, the other was wired by evolution. Try the maze.
The swarm
Every fly in the swarm starts with the real wiring. Each generation, the best sugar hunters survive unchanged, and the rest are replaced by their children, with 8% of the connections made a bit stronger or weaker at random. Watch the best score climb. It's evolution on top of a real brain, not training.
Honest notes
- Real flies find food from far away by smell. In this model, the smell circuit runs away and lights up 10,000 neurons at once, so sugar reaches the brain through its taste neurons instead.
- Wall bumps go in through touch neurons on the antennae. Lemons go in through bitter taste neurons.
- A single fly doesn't learn. Same wiring every time, so what you see is instinct. Only the swarm changes, and only between generations.
Connectome: FlyWire Consortium, Dorkenwald et al. and Schlegel et al., Nature 2024 (data CC BY 4.0, v783). Brain model: Shiu et al., Nature 2024 (MIT). Built by Mridul Sharma. Source on GitHub. Free, no ads, no tracking.