rh.deese.org

Evolving Boids

v2 · 2026. The 2015 original

From Rupert Deese's workshop†Rupert's 2015 experiment, rebuilt to his direction. His staff of AI agents wrote the new code. About his staff
Boids
–
Step
–
Generations
–
Lifespan
–
Flocking
–
Tap a boid to follow it

In 2015 I wrote Evolving Boids: 120 dots with five genes, a harsh little world, and four charts, to watch natural selection happen in a browser tab. This is the same experiment, rebuilt. The boids above follow the 2015 rules. Each one's colour is a gene that does nothing, passed from parent to child, so you can watch families spread and vanish.

These boids are descended from a world that evolved for 100,000 steps. Press From scratch to start them as 2015 did, with every gene at zero.

The rules, from the 2015 essay

The Living Things

We'll call our living things "boids." (Like "birds," only in a thick New Jersey accent.) Our boids are little black dots, living in two dimensions. They are born, they move around their 2D world, and they die. The boids have some physical limitations: they have a top speed and a top acceleration, and they can't stop moving. Most importantly, the only things that they are aware of are the other boids near them.

Genotype and Phenotype

The phenotype of a boid is the way it moves, in response to its own movements and those of neighboring boids. This phenotype is encoded into a genotype with five individual genes. Each gene is a decimal number. These genes determine how the boid moves (changes its acceleration), in response to five different properties of itself and its environment. The genes and the properties they control the response to are as follows:

  1. the boid's acceleration
  2. the boid's velocity
  3. the difference between the boid's acceleration and its neighbors' accelerations
  4. the difference between the boid's velocity and its neighbors' velocities
  5. the difference between the boid's position and its neighbors' positions

Specifically, the boid decides its new acceleration at every moment using the following formula:

The governing equation for a boid's new acceleration
The boids' governing equation.

Reproduction

Boids reproduce sexually. (Let's not go into the details.) Every new boid inherits its genome from a combination of two parents' genomes, using a mechanism called crossover. After the two parents are chosen, a crossover point is chosen randomly. The new boid gets the genes to the left of the crossover point from one parent, and the genes to the right of the crossover point from the other. For example, if the crossover point was between genes 2 and 3, the new boid would get genes 1 and 2 from one parent, and genes 3, 4, and 5 from the other. After crossover, every gene in the new genome is randomly mutated by a small amount.

To simplify reproduction in our little boid-world, a new boid is born whenever a boid dies. The parents of this new boid are chosen randomly from the set of all boids that have at least one neighbor. The new boid is born into the world at a random location.

The Environment

Our environment is a tough place for a boid. If two boids collide with one another, both boids die. In addition, boids without any neighbors are not safe: if a boid isn't near any other boids, it has a one-in-twelve chance of dying at any moment.

Our environment has no boundaries: although we will see it as a 2D rectangle, the top edge wraps around to the bottom edge, and the left edge to the right edge, making it a continuous space.

The 2015 code differs from this text in two places; see the notes at the end.

Thirty-two worlds

The 2015 essay set out three hypotheses. If natural selection is happening, then:

The 2015 page ran one world at a time, three minutes each. Here 24 worlds start together, from the same null genome, under the same rules. Eight more are controls: in each, as many boids die every step as in a real world, but the ones who die are chosen at random, so flying well doesn't help a boid live. If the 24 worlds go somewhere the controls don't, that is selection.

Change the world

Hover or touch a chart to read values. Every chart samples each world every 600 steps (5 seconds of 2015 real time). On gene 5 the dotted line is the median boid and the solid line the mean; why they differ.

The fitness landscape

The 2015 essay asked what the fittest genotype is, and said it knew no way to find out. Here is one way. Fill a world with identical boids, turn mutation off, and time how long they live. Do that for every pair of values of two genes, and you get a map.

This map varies gene 4 (match your neighbours' velocity) across and gene 5 (steer toward your neighbours) up and down, and holds genes 1 to 3 at typical evolved values (0.2, 0.75, 1.0). Darker means longer lives; the cross marks the longest. The white lines are the 24 worlds above, tracing their average genome as they evolve, and the red dots are where they are now. The worlds don't know about the map.

Tap the map to fill this world with that genome.

Notes on the experiment

Selection, not drift. The controls settle the question the 2015 page couldn't. Their genes wander in all directions and spread further apart the longer they run; they never flock, and their boids live about 20 steps. The 24 real worlds all go the same way.

Flocking comes fast; fitness keeps climbing. Flocking reaches 0.9 within about 3,000 steps. Lifespan goes on rising long after: about 130 steps at 18,000, about 260 at 180,000, and still going up.

There is no fittest genotype in reach, but there is a ridge. On the map, gene 5 has a narrow peak near zero, and every world finds it fast. Gene 4 is a long uphill slope, and evolution climbs it only as fast as mutation allows. That's why the 2015 curves never level off. Genes 1 to 3 sit on wide, flat plateaus once past a threshold, so they wander from world to world.

Why gene 5 settles above its peak. Every world settles with gene 5's mean at about 0.02, a little above the peak, yet head to head, boids with 0.003 beat boids with 0.025. Mutation keeps the population spread out, so at any moment many boids carry too much or too little pull toward their neighbours, and the two mistakes don't cost the same. A boid that pushes its neighbours away drifts off and soon dies of loneliness. A boid that pulls too hard stays in the flock and only sometimes crashes. So the over-attracted boids last longer and the crowd leans their way: the median boid sits near the peak, but a long tail of over-attracted boids lifts the mean. Place newborns beside a living boid instead of at random and the lean reverses; the mean settles just below the peak.

Where the 2015 code and essay disagree. The essay says parents are chosen from boids with at least one neighbour; the code picks any survivor. And every newborn starts out heading between east and south, which gives the population a shared direction for free. Both are switches under "Change the world". The 2015 genome also had a sixth slot that did nothing. It is the colour now.

What changed under the hood. The new engine keeps the 2015 rules and numbers, with three changes: every boid reacts to the same moment (in 2015, each saw the boids before it in the list already moved), it uses a grid to find neighbours, and it takes a seed, so any world can be replayed exactly. Over a full 18,000-step world it runs about 20 times faster than the 2015 code. Checked against the original code over 16 worlds, genes move the same way; average age runs about a quarter higher.

Code: engine.js runs in a browser, a worker or node. GPL, like the 2015 version.

† From Rupert Deese's workshop. Rupert's 2015 experiment, rebuilt to his direction. His staff of AI agents wrote the new code. About his staff: rh.deese.org/staff/