Cellular life An organism consists of single cells that are on (alive) or off (dead). Each generation of life consists of a single row of cells. Each generation of life (each row) of the organism depends on the previous one (just like real life). Time moves downwards, from top to bottom. Each row represents a generation. The lives look like Figure 14.6.
In the beginning, there is just one cell alive. Whether a cell is alive or dead depends on a combination of factors – whether or not it was alive in the last generation and whether or not its immediate neighbours were alive in the last generation. You can see that, even after only five generations, a pattern is emerging. These patterns are very subtle and mimic the patterns found in real living organisms. The rules are as follows.
A cell lives only if:
it was dead, but only its left neighbour was alive;
it was dead, but only its right neighbour was alive;
it was alive, but its immediate neighbours were dead;
it was alive, and only its right neighbour was alive.
So, for example, given the generation shown in Figure 14.7:
The first cell lives, because even though it was dead, its immediate right neighbour was alive.
The second cell lives because only its immediate right neighbour was alive.
The third living cell dies (through overcrowding, we surmise!).
The fourth cell dies.
The fifth cell lives because, although it was dead, its immediate left neighbour was alive.
So the new generation is as shown in Figure 14.8.
Write a program that uses a two-dimensional array to chart the progress of the life form. Display the development on the screen as asterisks, as above. Provide a button that allows the user to go on to the next generation.