How to create Valentine Bunnies in Game of Life

Game of Life is a very interesting and a surprisingly simple algorithm invented by John Horton Conway in the seventies. The game is for 0 players, because it is really not a game in the common sense. The game is played on a matrix consisting of ones and zeroes, defining, in a biological sense, cells, which are alive or dead. The first step of the game is to input the initial state for all the elements in the matrix. The algorithm is then updating this matrix, applying special rules for how the cells are evolving. The result is a fascinating animation of cells that are created, spread and dies.

The reason why Game of Life is interesting is it is so simple and yet creates very complicated and interesting patterns.

Thick industrial windows of different state of discoloration, resembling “Game of Life”. Photographed by Matz JB January, 2014

The original rules as stated by Conway is:

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

In 2009-2011 I held a job as a teacher in programming in C for students at the architecture department (AT) at Chalmers University of technology. In the course I had to create exercises and content for the students. I had already written the Game of Life code in C using OpenGL, but I wanted to see if a change of the rules would yield something more interesting. Also, the students would learn about initializing arrays in different ways.

By accident, after spending the night meddling, testing and writing exercises, I suddenly saw bunnies everywhere. Rows and columns of bunnies holding hands, er… I mean paws. Additionally, they appeared to have a heart symbol on their chest. They had to be a message from the computer.

I was very excited and jotted down the rules and starting distribution. Here is the initial values of the matrix A, a matrix of doubles.

for(int i=0; i<RES; i++)
	for(int j=0; j<RES; j++)
		A[i][j] = sqrt( (i*i + i*j*j)%20 );

where RES is a resolution of the window, so we introduce spatial information in the initial distribution.

Now, this is the same rules as the original Game of Life with the slight change that instead of using integers the first iteration requires floats. Each cell >0.9 is alive and really counts as 1. This is only done for the first iteration, the subsequent iterations are exactly the same as the original game of life. B is a temporary update matrix used in the code:

 for(int i=0; i<RES; i++)
        for(int j=0; j<RES; j++)
        {
            int nn = nr_of_neighbours(i, j);

            if (A[i][j]==1) //center cell is alive
            {
                if(nn<2 || nn >=4)
                    B[i][j] = 0;

                if(nn==2 || nn==3)
                    B[i][j] = 1;
            }
            else if(nn==3) //(rule 4)
            {
                B[i][j]=1;
            }
        }//for

    for(int i=0; i<RES; i++)
        for(int j=0; j<RES; j++)
            A[i][j] = B[i][j];

where nr_of_neighbours is a function which counts the number of (in a “Moore neighbourhood”) neighbours at position (i,j) in A.

The algorithm is still game of life, with an interesting starting distribution. The pattern created from this distribution is related to the valentine theme of this post. Maybe if John Conway found this pattern he would have called it game of love instead, hehe.

The animation from frame 1 to 17 of the “game of love” cellular automata.

Below we see a closeup of A after 16 iterations. Pretty cool, huh? After about 25 iterations the pattern disappears and all we have is the border cells, almost like the vines around the text seen in the intro of The Legend of Zelda. Right after that the cells begin to eat the vines at the bottom. After 300 iterations the whole board is dead, consisting of blinkers called “traffic lights” and some “still life” called beehives and biblocks.

Heart Bunnies

The iteration #17 of the “game of love” cellular automata.

Read more about this subject: Wikipedia on game of life Wikipedia on cellular automatons

Leave a Reply

Your email address will not be published. Required fields are marked *