Simulation··2 min read
I made the fly brain play Magic: The Gathering
I just beat the fly brain at Magic: The Gathering.
At the start of September, Janelia, Google and Cambridge published the complete wiring diagram of a male fruit fly’s nervous system, all 166,700 neurons of it. Within a week Twitter’s new hobby was “torturing” the simulated fly brain by wiring it up to do odd things inside simulators. DOOMFLY probably started it, with the fly’s actual brain playing Doom, and someone else overfit a modelled fly body to play Beat Saber.
I wanted to play with how grim the whole idea is, so I hooked the fly up to Magic: The Gathering. I based my code on DOOMFLY’s and sat the fly in the AI opponent’s seat in XMage, the unofficial open-source Magic client. It got a mono-black deck of flies and maggots, and I played mono-green spiders against it, every one of them with reach so they can block flying insects. I thought it was hilarious, if a little grim.
Whenever XMage asks the fly for a decision (any legal card at any step, or a pass), the options are drawn as a picture in front of its eyes. DNp20, the pair of neurons DOOMFLY reads for steering left and right, cycles through them, and DNpe017 rubber-stamps the choice. Each decision gets 150 milliseconds of fly time, which takes my PC about 1.7 seconds to simulate.
DOOMFLY only wires up the photoreceptors that see brightness, so the fly is colourblind. Each option is a blob as bright as its mana cost, and the fly also gets the card’s real art, cropped out of XMage’s card images and turned up in contrast so its photoreceptors can tell the shades apart. Compound eyes don’t work like ours anyway, so it probably can’t make out the spiders, but that didn’t stop me from trying. It doesn’t matter much for the decision, because DNp20 gets 41% of its input from the ocelli, the simple eyes on top of a fly’s head that only sense how bright it is. The fly brain can also touch, smell and taste, so it feels a spell pointed at it as a touch and tastes the cards in its hand as sugar, but it has no idea what its life total is.
My first version drew the options along the bottom of the screen, where a person would put them. The fly has no photoreceptors there, so it couldn’t see half of its own options, and it lost 17 games in a row against XMage’s own AI before I noticed.
I won, by the way.
A neuroscientist in the r/mtg thread asked for the methods, so I wrote them up here. My favourite reply was “I have no mouth and I must buZz.”
You can download the fly brain yourself. I’m seriously thinking about running a league of 100 of them that play by smell and taste instead of sight, with dopamine as the reward and people cheering for their favourite fly.