one generation to the next, we copy the new generation
array to the current generation array and then begin the
computation for a new generation.
Keeping It Fresh
Actually, things get a little more complicated here. If
you do a little reading about the Game of Life, you soon
begin to realize that there are some simple repeating
patterns that can occur every 2, 3, 4, 5 ... generations that
are called oscillators. Two generation oscillators are quite
common, and perhaps the most common is a pattern
called traffic lights. This is a pattern of three living cells in a
horizontal row surrounded by empty cells. In the next
generation, this becomes a vertical row of living cells; the
two end cells die because they only have one neighbor;
and two cells are created above and below the center cell
because it has three neighbors.
In the next generation, it returns to a horizontal row of
three living cells and then flips back and forth with each
new generation. If the display has only stable cells in
patterns that do not change — like a square block of four,
In order to do this, we must remember back an
additional generation, i.e., we will need to store three
generations in three 32x32 arrays. Then, we not only need
to compare the new generation to the current one, but
also go back and compare it to the previous one. If the
new generation is the same as either one of the last two,
we restart the process. If we want to check for three
generation oscillators, we would need four arrays; four
generation oscillators, five arrays, etc.
Unfortunately, the Mega 2560 has only enough
memory for three generation oscillators, but not four. The
problem here is that we are being wasteful and storing our
two-bit colors representing off, red, green, and blue in an
eight-bit byte. This simplifies our programming task, but
restricts the number of generations back we can check. It
is possible to store four two-bit cells in a single byte, but I
will leave that program model to those readers who are
interested enough to write the necessary code.
Wrap-Up
As mentioned, the complete Arduino sketch is
included in the download material and contains lots of
comments. This project began with thinking about a new
display for a digital clock and morphed into a Game of Life
display. For the future, there is still a plan to add a real time
clock circuit to the Arduino shield and alternately display
the time and date interspersed with a display of the Game
of Life to keep things lively. NV
July 2014 29
The Game of Life
The Game of Life — also known simply as Life — is a cellular
automaton devised by the British mathematician, John Horton
Conway in 1970.
“Life” is a zero-player game, meaning that its evolution is
determined by its initial state, requiring no further input. One
interacts with the Game of Life by creating an initial configuration
and observing how it evolves.
The universe of the Game of Life is an infinite two-dimensional
orthogonal grid of square cells, each of which is in one of two
possible states: alive or dead. Every cell interacts with its eight
neighbors, which are the cells that are horizontally, vertically, or
diagonally adjacent. At each step in time, the following transitions
occur:
• Any live cell with fewer than two live neighbors dies, as if
caused by under-population.
• Any live cell with two or three live neighbors lives on to the
next generation.
• Any live cell with more than three live neighbors dies, as if by
overcrowding.
• Any dead cell with exactly three live neighbors becomes a
live cell, as if by reproduction.
The initial pattern constitutes the seed of the system. The first
generation is created by applying the above rules simultaneously to
every cell in the seed — births and deaths occur simultaneously,
Conway was interested in a problem presented in the 1940s by
mathematician John von Neumann, who attempted to find a
hypothetical machine that could build copies of itself. He succeeded
when he found a mathematical model for such a machine with very
complicated rules on a rectangular grid. The Game of Life emerged
as Conway’s successful attempt to drastically simplify von
Neumann’s ideas.
The game made its first public appearance in the October 1970
issue of Scientific American, in Martin Gardner’s “Mathematical
Games” column. From a theoretical point of view, it is interesting
because it has the power of a universal Turing machine; that is,
anything that can be computed algorithmically can be computed
within Conway’s Game of Life.
Gardner wrote:
The game made Conway instantly famous, but it also opened
up a whole new field of mathematical research — the field of
cellular automata. Because of Life’s analogies with the rise, fall, and
alterations of a society of living organisms, it belongs to a growing
class of what are called “simulation games” (games that resemble
real life processes).
Courtesy of en.wikipedia.org.
There is a second program available at the article link
that packs the Game of Life values into single bits. This
allows the arrays to be much smaller, and it can check back
eight generations for oscillators. This does add a lot of
overhead, however. A generation now takes about 1.4
seconds to update, but it is still fast enough to make the
display interesting.