Back Fruit Fly Slot Machine

How the Fruit Fly Slot Machine works

Fruit Fly Slot Machine is an interactive neuroscience piece that runs in the browser. A micro-CT scan of a real fruit fly (Drosophila melanogaster) sits on a bar stool and plays a one-armed bandit by itself. Beside it, 60,000 real neurons from the MaleCNS connectome are drawn at their measured positions and light up as it plays.

The fly picks its own stakes. Its mushroom body learns, from reward and punishment dopamine, that the machine is bad for it. It keeps playing anyway. When it runs out of credit it panics, gives up, and behaves as if it were dying.

It is a question put to a real brain: what would a fruit fly's nervous system do if the fly were forced to gamble forever?

What is real

What is a model

Nobody has recorded a fruit fly playing a slot machine. The activity on screen is a rate model run over the measured wiring:

drive_i = GAIN · Σ_j W_ij · r_j + I_i
r_i    += (φ(drive_i) − r_i) · dt / τ

The game only injects current into real populations: visual neurons while the reels turn, mechanosensory and descending neurons while the foreleg works the lever, the PAM cluster on a payout and PPL1 on a loss, the way optogenetic reinforcement experiments drive them. Between spins the fly's standing state keeps driving the network, so the brain is never idle. Which regions light up after that is decided by the connectome, not by a script.

This is a rate model on a type-collapsed graph, not a spiking simulation of every neuron.

How it learns

The fly learns the way real flies do: in the mushroom body. Kenyon cells carry a sparse code for the current context, which here is sitting in front of this machine. They connect to mushroom-body output neurons (MBONs). When dopamine arrives while the Kenyon cells are active, the Kenyon cell → MBON synapses in that compartment weaken.

Which MBON belongs to which dopamine cluster is not written by hand. It is read off the connectome's own synapse counts. For example, MBON01 (γ5β′2a) receives 290 synapses from PAM and 1 from PPL1, while MBON11 (γ1pedc) receives 308 from PPL1. The weakened synapses are written back into the simulation, so the network's output changes with what the fly has been through. On these odds it learns that the machine is bad, and it keeps playing: learned aversion slows its approach but never stops it.

How it gambles

Its inner state

The readouts use signals that have actually been measured in this animal, not human feelings with insect names:

The fly's thoughts shown in words are ours; a fly has no words. Each line is chosen from its actual state (credits, losing streak, the last outcome, NPF, the defensive state and what it has learned), so the words translate numbers that are already on screen.

What it is not

Built with

React, three.js and React Three Fiber, with the simulation, the learning and the synthesised sound all running client-side in plain JavaScript. There is no server and no tracking. The source code is on GitHub.

Credits and licences

Watch the fly play

Frequently asked questions

Is the fruit fly brain in the Fruit Fly Slot Machine real?

Yes. The anatomy is real: 60,000 neurons are drawn at their measured positions from MaleCNS v1.0, the complete connectome of a male fruit fly mapped by HHMI Janelia's FlyEM team with Google Research, the University of Cambridge and the MRC LMB. The wiring the simulation runs on comes from 151.9 million measured synapses. The activity itself is a model, because no one has recorded a fly playing a slot machine.

What is a connectome?

A connectome is a complete wiring diagram of a nervous system: every neuron and every synapse between them. The fruit fly (Drosophila melanogaster) is the most complex animal whose whole central nervous system has been mapped.

How does the fly decide how much to bet?

Nothing hard-codes the stake. It comes from the fly's state at the moment it pulls: low neuropeptide F pushes it to chase losses, recent reward dopamine makes it bolder, the defensive state makes it careful, and what its mushroom body has learned about the machine pushes either way. It bets between 1 and 5 credits.

Does the fruit fly actually learn?

Yes. Its mushroom body learns on the measured wiring: dopamine arriving while Kenyon cells are active weakens the Kenyon cell to MBON synapses in that compartment. Punishment (PPL1) weakens the MBONs that drive approach, reward (PAM) weakens the ones that drive avoidance. On these odds it learns the machine is bad, and keeps playing.

What happens when the fly runs out of credit?

It panics, then gives up: its heart slows almost to a stop, its satisfaction signal drains and it slumps on the stool, behaving as if it were dying. After a while someone feeds the machine and it comes round, warier than before.

Is this a gambling website?

No. There is no money, no betting and nothing to buy. The fly plays alone; you watch.

What is the Fruit Fly Slot Machine built with?

React, three.js and React Three Fiber in the browser. The connectome simulation, the mushroom-body learning and the synthesised sound all run client-side in JavaScript, with no server and no tracking.

Who made the Fruit Fly Slot Machine?

It was made by ryhox and Nexor. The source code is open on GitHub.