Can a Fly Brain Play Flappy Bird? Experimenting with MaleCNS and Spiking Neural Networks

What happens if, instead of training a neural network to play a game, we take the wiring diagram of a real biological nervous system and connect it to Flappy Bird? That is what I wanted to explore with MaleCNS, a reconstructed connectome of the adult male Drosophila central nervous system. The interesting part is that the network itself is not trained to play Flappy Bird. The connectivity comes from the reconstructed fly nervous system.

In this experiment, Flappy Bird is controlled by a spiking neural network built from the connectivity of the fly CNS. The network contains approximately 166,700 neurons and 25.6 million connections. Instead of training a model to decide when to flap, I translate the game state into a simple looming signal, inject that signal into visual projection neurons associated with looming detection, and watch for activity in the fly’s escape pathway.

What is MaleCNS?

A connectome is essentially a wiring diagram of a nervous system. It describes neurons, their connections, synapses, anatomical information and other metadata associated with the nervous system. MaleCNS represents the reconstructed central nervous system of an adult male fruit fly, including both the brain and the ventral nerve cord.

The dataset is MaleCNS v1.0, produced by FlyEM at HHMI Janelia together with the University of Cambridge, the MRC Laboratory of Molecular Biology and Google Research. It maps the complete central nervous system of an adult male Drosophila melanogaster: the brain and the ventral nerve cord (the fly’s equivalent of a spinal cord).

MaleCNS
  ├── neurons
  ├── synapses
  ├── connectivity
  └── anatomical information
Male Fruit Fly CNS Connectome (Source : Google Research)

For this experiment I use the MaleCNS data through the flybrain package. The package provides a sparse connection matrix containing approximately 25.6 million connections, together with metadata describing neuron type, anatomical side, superclass, position and other information. But having a connectome is not enough. A connectome tells us who is connected to whom. We still need a model describing how signals move through those neurons. That is where the spiking neural network comes in.

Turning the Fly Connectome Into a Spiking Neural Network

The MaleCNS network is simulated using a Leaky Integrate-and-Fire, or LIF, neuron model. LIF is one of the simpler mathematical models of neuronal activity.Each neuron maintains a membrane potential. Incoming signals increase or decrease that potential, while the value gradually leaks back toward its resting state.If the potential crosses a threshold, the neuron fires a spike and then resets.

How Does a Fly Brain See Flappy Bird?

I am not rendering the Flappy Bird screen into a simulated compound eye and recreating the complete visual processing pipeline of a fruit fly.Instead, I take information from the game environment and convert it into something analogous to a biologically meaningful sensory signal.

The Looming Signal

The senory signal I chose is looming. Looming describes the visual effect of something getting rapidly larger as it approaches you. For a fly, this can represent an approaching predator or another object on a collision course. For Flappy Bird, I reinterpret the same concept as: The ground or bottom pipe is getting dangerously close. The game state is therefore converted into a single value between roughly 0.0 and 1.0 representing the strength of this looming stimulus.

The LC4 and LPLC2 Neurons

The looming signal is injected into two groups of visual projection neurons:

  • LC4
  • LPLC2

These neurons are associated with responses to looming visual stimuli.

brain = FlyBrain(device="auto")

loom_cells = brain.cells(["LC4", "LPLC2"])
dnp01 = brain.cells(["DNp01"])

The game-generated looming value is injected directly as voltage into the LC4 and LPLC2 neurons.his is another important simplification: the real fly eye is not simulated. The experiment starts farther down the visual processing pathway.

Now we need an output from the fly nervous system. For that, I use DNp01, a descending neuron associated with the fly’s giant-fiber escape system. In a real fly, this pathway is involved in rapid escape behavior such as take-off. Experimented with an LC10a -> DNp01 pathway, but in my tests it did not cause DNp01 to fire, so the current version uses LC4 and LPLC2.

Watching the Brain Fire

The project includes a live browser view. Run it with the --web flag and a page opens at
http://localhost:8765/ showing the fly’s nervous system firing while it plays.

Try It Yourself

The code is on GitHub, create a python virtual environment and run these commands

pip install -r requirements.txt

python brain.py                    # watch the game window
python brain.py --web --headless   # live brain view in the browser

The first run downloads the connectome files (about 260 MB).

Final Thoughts

Nothing in this network was trained. A hand-made looming signal goes in, the fly’s own wiring
carries it to the escape neuron, and the bird flaps. It is a simplified experiment, not a
simulated fly: the eye is skipped and the neuron constants are hand-calibrated. The next step
I would like to try is rendering the game into a simulated compound eye, so the fly sees the
pipes instead of being told about them.