The Game of Life

The Game of Life is an old programmer’s puzzle that teaches teenagers to write and analyse their own code. The goal of the game is to simulate the development (life and death) of cells within one organism. An organism is a matrix of arbitrary size, and the rules are as follows: if a cell is alive and surrounded by 2 or 3 living cells, it will survive. If there is an empty position and is surrounded by 3 living cells, a new cell will be born. How to create this simulation in Excel?

In our example, the organism is a 20×20 cell matrix. The simulation is performed by two main and one auxiliary subroutine. The first aims to reset the matrix, i.e. to set the array values ​​to zero, and then to determine by random method which cells will be alive and which won’t. The second subroutine checks conditions and, depending on them, determine which cells will live and which ones will die. The last subroutine serves only to delete cells within a spreadsheet matrix.

We begin the initialization by resetting the array. Although life is in a 20×20 matrix, our array will be 22×22. This is important because of the computation of the sum of cells surrounding those located at the edges and in corners of the matrix. We will reset the matrix by setting the array members to 0, and then use the Excel function RANDBETWEEN to calculate where the cells are living by the random choice principle. This happens within 20×20 matrix. To complicate things a little, a Spin Button was added that changes the value of AF2 cell in the range of 1 to 5. The higher this number, the fewer cells will be generated initially. Following this procedure, the living cells in the matrix are given a value of 1 and the dead (empty positions) 0.

The second subroutine is used to check and change the life status of individual cells. Using two nested loops that go from 1 to 20, each value in the matrix is ​​checked and the sum of the cells surrounding it is calculated. If there is no life in the position (value 0) and it is surrounded by three cells, a new cell will be born. If a living cell (value 1) is surrounded by 2 or 3 adjacent cells, it will survive, and if more or less, it will die. In the end, we will use another double loop to show the living and dead cells in the given positions.

We start the simulation by clicking the RESET button (the first subroutine), and proceed from phase to phase by clicking NEXT (the second subroutine). With each subsequent click, you will watch as the kaleidoscope of life changes. Play around, and when you’re bored change the rules of the game and watch what happens.

“The Game of Life” is a simulation I first created, as a teenage programmer, back in 1989 and was introduced to it by Vlada Kostic, lecturer at the computer school led by Institute of Nuclear Sciences „Vinča“, whose course I attended. Now I’m passing forward the knowledge, if anyone wants to get an Excel simulation file they can contact me.