Game of Life

The basic Game

The Game of Life is a pretty standard coding exercise that I thought would do as part of my Creative Coding course. I am using Processing, “a flexible software sketchbook and a language for learning how to code within the context of the visual arts.”

The Game board is a grid of square cells which may be alive or dead. The grid is ‘seeded’ with a starting configuration, then unfolds according to the following set of rules.

Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:

  1. Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
  2. Any live cell with two or three live neighbours lives on to the next generation.
  3. Any live cell with more than three live neighbours dies, as if by overpopulation.
  4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

The first generation is created by applying the above rules simultaneously to every cell in the seed – births and deaths occur simultaneously. The rules continue to be applied repeatedly to create further generations.

In theory the grid is infinite, but in my exercise it is bounded. Live cells are coloured white, dead cells are black. Click the “Go! Go! Go!” button to launch the Processing sketch and start the Game. The starting condition is random: each cell has a 50% chance of being alive or dead. As your finger hovers over button, you might think of them all as geometric Schrödinger’s Cats!

It’s fascinating to watch, as patterns bloom across the grid and engulf areas previously in stasis. The field of mathematical and computing research it spawned is pretty darn fascinating too.

Note: If there is a problem with loading this or any of the following Processing sketches, or they are running slow, there is a companion blog of example videos.

Shades of grey

I was interested in what happened when Life is no longer seen in black and white, but in shades of grey. So I allowed each cell to have a value on the greyscale spectrum between 0 (black) and 255 (white). It could be thought of as energy levels. Each initial value is random on the scale. The rules I chose are close to standard Life; cells with the right amount of surrounding energy thrive, and cells with too little or too much surrounding energy shrivel. So a

At each step in time, the greyscale fraction (greyscale value divided by 255) of the eight neighbours is summed and rounded to the nearest integer. Call this the greyscale index. Then the following transitions occur:

  1. Any cell with a neighbouring greyscale index of less than two loses n points of greyscale.
  2. Any cell with a neighbouring greyscale index of two maintains its greyscale.
  3. Any cell with a neighbouring greyscale index of three gains n points of greyscale.
  4. Any cell with a neighbouring greyscale index of more than three loses n points of greyscale.

Values are always constrained to between 0 and 255. If n=255, the game becomes standard Life. I set n=2; if there a lot of cells, n=1 can be a bit too glacial! It is slower paced than Life, but again really interesting to see how it unfolds. The starting configuration is relatively uniform in its greys, but very quickly the cells polarise into lines of black and white. It is as though the battle-lines of political opinion were drawn street-by-street, and society becomes a maze to navigate. Yet opinions are not set in stone. There is occasionally a convulsion, and some cells that were black become white, and others flip from white to black. Change is more confined than in standard Life, but it is real. Thoughts?

Update: even more shades

A friend suggested I ‘go technicolor’, so…

Tribes: I used the above rules for each of the RGB channels. I thought there would be more blocks of colour. But although there are a few lines, the centre of the grid stays very mixed. It’s around the edges that the tribes appear, as though having fewer neighbours, and hearing fewer opinions, leads to more monochrome neighbourhoods.

Shifting middle: This has the same rules, except that n varies with the greyscale of the cell itself. If the cell is closer to black or white, n is smaller, ie views are entrenched. If the cell is closer to the middle of the scale, n is larger, ie views are more open to change. n follows a normal distribution, rounded to integers between 0 and 4. I thought it might polarise more, but can’t tell the difference with my first version.

Incentive? Again, the same rules, with varying n. n is higher for cells closer to black, and lower for cells closer to white, ie the more unhealthy have a greater incentive to shift to a healthier lifestyle. n varies in a straight line, rounded to integers between 0 and 4. It turns out the grid moves to what looks like a steady state, mostly polarised into resolutely unhealthy and fairly (but not very) healthy.

Uniformity: This one has a different rule, simply that a cell takes on the average of its neighbours. Thankfully life doesn’t quite work like that, despite the best efforts of our mass media!

Leave a Comment