Skip to content
Salvador Borrego

High-school research project · 2023

Borrego's Game of Life

It started in my first year of bachillerato (the last stage of secondary school in Spain), in computing class: I wrote Conway's Game of Life from scratch. It became my research project (TDR), where I invented a version with three species of cells and tried to turn it into an evolutionary algorithm.

The evolutionary part did not work out back then. Here are the three 2023 versions, with their bugs fixed and playable on the page. The evolutionary algorithm, finally working, has its own laboratory.

Try it Open the laboratory

Black 10 by 10 grid with grey lines and a few red, green and blue cells
A screenshot of the three-species version, June 2023.

Try it

Pick a version and a scenario, or draw your own cells. Each generation applies the rules to every cell at once.

The simulation needs JavaScript.

Draw or erase cells with the mouse or your finger.

Generation 0

  • Alive0
  • Red0
  • Green0
  • Blue0
  • Mixed0

Draw with

Rules · Conway

  • A live cell stays alive with 2 or 3 live neighbours.
  • It dies with fewer than 2 (loneliness) or more than 3 (overcrowding).
  • A dead cell comes back with exactly 3 live neighbours.

What was broken in 2023

What I found when I went back to the code and the project documents, and how it works now.

Conway

  • The rules in the code were right: it counted every cell's neighbours before changing any of them.
  • The theory document said a cell stays alive with «more than 2 and fewer than 3» neighbours. There is no whole number between 2 and 3.

Now A cell survives with 2 or 3 neighbours, which is what the code did. The «Walker» and «Loop» scenarios are the two shapes left commented out in the sketch.

Borrego

  • Cells were born with 4 neighbours: the code only checked for 3 of one species, not that they were the only ones, and they died the next generation.
  • If two species reached 3 at once, the last one the loop looked at always won.
  • Drawing while paused did not work: the rules kept running on stale counts and the new cell died instantly. Holding the click toggled it on and off, and when zoomed in it drew on the wrong cell.

Now A cell is born with exactly 3 neighbours of one species, as the documents said. Drawing only changes that cell, and the next generation counts it.

Mixing

  • A mixed cell's colour was blended with neighbours that had already moved on to the next generation, so it depended on the order the grid was scanned.
  • Every newborn cell was mixed. The child of three greens looked green, but its green neighbours did not count it as one of their own.

Now Each generation is worked out in full before anything changes, and the child of three greens is green. With the species scattered at random, in 36 out of 40 runs only mixed cells are left in the end.

The evolutionary algorithm, at last

The goal of the project was for the species to evolve: cells with traits, the best ones selected, and children inheriting part of them. It did not work, and now I know why. Evolution needs three things:

  1. Inheritance

    Something passed from parents to children that changes how a cell lives. In the mixing version the colour was inherited, but it changed nothing.

  2. Variation

    Small mutations when inheriting, so there is always something new to try. There were none.

  3. Selection

    Whatever works better leaves more offspring. The stats the project proposed (times revived, time alive…) measured things but decided nothing.

Now every cell inherits its own survival rules from its three mothers, with mutations, and nobody picks the best: the food on the board and what each genome costs decide who leaves more daughters. It lives in its own laboratory, with a big board, rewind and a pattern library.

Open the laboratory

Decisions and why

Real problems that came up along the way, and how I solved them.

  1. The rules come from the 2023 papers

    Nothing was reinterpreted. Borrego's birth rule was already written in the project's theory and in my notes, the «ethnic condition»: exactly 3 neighbours, all of the same species. The code back then did not follow it; now it does. The only fix to the text is «more than 2 and fewer than 3», which with whole numbers lets nothing survive: it meant 2 or 3.

  2. The whole generation at once

    Each generation is worked out in full on a copy of the board, then everything changes at once. That fixes the colour of mixed cells and lets you draw while paused without the rules being applied twice to the same generation.

  3. Runs you can replay

    All randomness comes from a seed: the same scenario with the same seed always gives the same run, and the link stores it so you can share it. Automated tests check every rule, that the result does not depend on scan order, and that a seed replays the same thing.

What is inside