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:
- the boid's acceleration
- the boid's velocity
- the difference between the boid's acceleration and its neighbors' accelerations
- the difference between the boid's velocity and its neighbors' velocities
- 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:
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 phenotype (visible movement) of the boids will change over time
- the average fitness of the boid population will increase over time
- the average genotype of the boid population will approach the most fit genotype, over time
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.