Project 1 The game of life
Name: Choong Pak Shen
Matriculation number: 101904

Abstract
Based on the book Chaos and Fractals, second edition by Heinz-Otto Peitgen, Hartmut Jurgens and Dietmar Saupe (2004), the idea of “Game of Life” is simulated here in project 1. “Game of Life”, being unparalleled to its name, is not a game in the usual sense. It is a “game” without player, a cellular automata which had raised interests to many mathematicians. The key point to run the “Game of Life” is to define an initial state, a set of rules which is independent on the position of the group within the layer, and the number of states of each cell (or pixel). Usually, “Game of Life” utilizes two states, 1 (alive, shown in black) and 0 (dead, shown in white). After all the conditions are set, the “Game of Life” will run on its own. In this Project 1, three types of rules are introduced.

Discussion
The first type of rules introduced here is the one-out-of eight rule. For each of the cell (or pixel), the states of its eight neighbours are checked for every time steps. If there is only one neighbour alive, the cell (or pixel) will be alive. Otherwise, the state of the cell remains unchanged. The simulation box is 200 × 200 large and the time steps taken is 100 steps. To test the neighbours, a variable named “testLife” is collecting information (in this case, summing all the values of the eight neighbours) from its eight neighbours and the rules will be applied through “If” command. In order to save the calculation time, two variables named “oldLife” and “newLife” are used alternately in such a way that the “newLife” represents the future time step and it reads data from “oldLife” so that rules can be applied on “oldLife” and the results are recorded in “newLife”. Periodic boundary condition applied here since the simulation box is not large enough. For every time step, the data is tabulated and printed out using “Manipulate”. The following figure shows the outcome of one-out-of-eight rule with initial condition as a dot.



The one-out-of-eight rule generates a fractal, which repeats itself at a smaller scale. Nature always tend to generate fractals on its own, for example, fern. In this case it looks pretty much like an orderly constructed city. It is possible to change its initial conditions and see how the “Life” grows.

(*One-out-of-eight rule*)
(*Constant declaration*)
L=200;(*Size of the simulation box*)
tStep=100;(*Number of time steps taken*)
Print[ProgressIndicator[Dynamic[n/tStep]]];(*Print progress indicator*)

(*Variable initialization*)
For[j=1,j≤L,j++,
For[i=1,i≤L,i++,
oldLife[i,j]=0;
newLife[i,j]=0;
];
];

(*Initial state*)
oldLife[100,100]=1;

(*Tabulate the data in zero time step*)
tLife[0]=Table[oldLife[i,j],{i,1,L},{j,1,L}];

(*Start of time stepping*)
For[n=1,n≤tStep,n++,
For[j=1,j≤L,j++,
For[i=1,i≤L,i++,
(*Periodic boundary condition*)
i1=i-1;
i2=i+1;
j1=j-1;
j2=j+1;

If[i1==0,i1=L;];
If[i2==L,i2=1;];
If[j1==0,j1=L;];
If[j2==L,j2=1;];

(*Test the neighbouring by using the one-out-of-eight rule*)
testLife=oldLife[i1,j1]+oldLife[i1,j]+oldLife[i1,j2]+oldLife[i,j1]+oldLife[i,j2]+oldLife[i2,j1]+oldLife[i2,j]+oldLife[i2,j2];

If[testLife==1,
newLife[i,j]=1,
newLife[i,j]=oldLife[i,j];
];
];
];

(*Equate the old data with the updated data*)
For[j=1,j≤L,j++,
For[i=1,i≤L,i++,
oldLife[i,j]=newLife[i,j];
];
];

(*Tabulate the data for all time step*)
tLife[n]=Table[oldLife[i,j],{i,1,L},{j,1,L}];
];

(*Output print out*)
Manipulate[ArrayPlot[tLife[n],ColorRules->{1->Black,0->White}],{n,0,tStep,1}]

Discussion
The second type of rules introduced here is the majority rule. For each of the cell (or pixel), the states of all the nine cells are checked for every time steps. If there is five or more cells alive (majority of the group), the evaluating cell will be alive. Otherwise, the evaluating cell will die (minority of the group). The programming construction is the same as above, only the rules are changed accordingly. The following figure shows the outcome of majority rule with the initial condition of 30000 random alive cells. Therefore, the result for majority rule is not reproducible. From the simulation box, it is pretty sure that the image of the random alive cells “converged” into a certain image in more or less 20 time steps. This result is crucial to Project 2, which the landscape of the island is generated through this method.



The majority rule generates a random image due to the randomness of the initial condition. However, if the initial condition is the same every time the code is executed, the outcome should be reproducible. The result of the majority rule may not seem like a fractal, however if the initial condition is properly set, the outcome may be of geographical value. It is also comparable with the ant hill.

(*Majority rule*)
(*Constant declaration*)
L=200;(*Size of the simulation box*)
tStep=50;(*Number of time steps taken*)
Print[ProgressIndicator[Dynamic[n/tStep]]];(*Print progress indicator*)

(*Variable initialization*)
For[j=1,j≤L,j++,
For[i=1,i≤L,i++,
oldLife[i,j]=0;
newLife[i,j]=0;
];
];

(*Initial state*)
For[k=1,k≤30000,k++,
oldLife[RandomInteger[{1,L}],RandomInteger[{1,L}]]=1;
];

(*Tabulate the data in zero time step*)
tLife[0]=Table[oldLife[i,j],{i,1,L},{j,1,L}];

(*Start of time stepping*)
For[n=1,n≤tStep,n++,
For[j=1,j≤L,j++,
For[i=1,i≤L,i++,
(*Periodic boundary condition*)
i1=i-1;
i2=i+1;
j1=j-1;
j2=j+1;

If[i1==0,i1=L;];
If[i2==L,i2=1;];
If[j1==0,j1=L;];
If[j2==L,j2=1;];

(*Test the neighbouring by using the majority rule*)
testLife=oldLife[i1,j1]+oldLife[i1,j]+oldLife[i1,j2]+oldLife[i,j1]+oldLife[i,j]+oldLife[i,j2]+oldLife[i2,j1]+oldLife[i2,j]+oldLife[i2,j2];

If[testLife≥5,
newLife[i,j]=1,
newLife[i,j]=0;
];
];
];

(*Equate the old data with the updated data*)
For[j=1,j≤L,j++,
For[i=1,i≤L,i++,
oldLife[i,j]=newLife[i,j];
];
];

(*Tabulate the data for all time step*)
tLife[n]=Table[oldLife[i,j],{i,1,L},{j,1,L}];
];

(*Output print out*)
Manipulate[ArrayPlot[tLife[n],ColorRules->{1->Black,0->White}],{n,0,tStep,1}]

Discussion
The third type of rules introduced here is the famous “Game of Life” rule.

(1) If the evaluating cell is 0 (dead), and if there are exactly three neighbouring cells that are 1 (alive), then the evaluating cell will be alive, otherwise the evaluating cell is dead.
(2) If the evaluating cell is 1 (alive), and if there are two or three neighbouring cells that are 1 (alive), then the evaluating cell will be alive.
(3) If the evaluating cell is 1 (alive), and if there are less than two neighbouring cells that are 1 (alive), the evaluating cell will die from loneliness.
(4) If the evaluating cell is 1 (alive), and if there are more than three neightbouring cells that are 1 (alive), then the evaluating cell will die from overcrowdedness.

The programming construction is the same as above, only the rules are changed accordingly. From the initial condition of a straight line, the “life” will grow into something interesting, for example the blinkers, the gliders, star ships and guns. Extensive examples and discussion on the generation of the above examples can be found from Wikipedia or any other internet resources, therefore discussion of it will be restrained. The image generated from the “Game of Life” rule will converge in the end, however it may take some thousands time steps. It is not practical to simulate the “Game of Life” for 1000 time steps in Mathematica, therefore only 100 time steps are taken.

The “Game of Life” rule is important for many applications. For example, it can be used to simulate how an ideal population grows, or the idea of the speed of light can be simulated here. One of the important application, called the Micro-worlds, is exampled in Project 2.

(*Game of life*)
(*Constant declaration*)
L=200;(*Size of the simulation box*)
tStep=200;(*Number of time steps taken*)
Print[ProgressIndicator[Dynamic[n/tStep]]];(*Print progress indicator*)

(*Variable initialization*)
For[j=1,j≤L,j++,
For[i=1,i≤L,i++,
oldLife[i,j]=0;
newLife[i,j]=0;
];
];

(*Initial state*)
For[i=50,i≤150,i++,
oldLife[i,100]=1;
];

(*Tabulate the data in zero time step*)
tLife[0]=Table[oldLife[i,j],{i,1,L},{j,1,L}];

(*Start of time stepping*)
For[n=1,n≤tStep,n++,
For[j=1,j≤L,j++,
For[i=1,i≤L,i++,
(*Periodic boundary condition*)
i1=i-1;
i2=i+1;
j1=j-1;
j2=j+1;

If[i1==0,i1=L;];
If[i2==L,i2=1;];
If[j1==0,j1=L;];
If[j2==L,j2=1;];

(*Test the neighbouring by using the game of life rule*)
testLife=oldLife[i1,j1]+oldLife[i1,j]+oldLife[i1,j2]+oldLife[i,j1]+oldLife[i,j2]+oldLife[i2,j1]+oldLife[i2,j]+oldLife[i2,j2];

If[oldLife[i,j]==1,
If[testLife==2||testLife==3,
newLife[i,j]=1,
newLife[i,j]=0;
],
If[testLife==3,
newLife[i,j]=1,
newLife[i,j]=0;
];
];
];
];

(*Equate the old data with the updated data*)
For[j=1,j≤L,j++,
For[i=1,i≤L,i++,
oldLife[i,j]=newLife[i,j];
];
];

(*Tabulate the data for all time step*)
tLife[n]=Table[oldLife[i,j],{i,1,L},{j,1,L}];
];

(*Output print out*)
Manipulate[ArrayPlot[tLife[n],ColorRules->{1->Black,0->White}],{n,0,tStep,1}]

Conclusion
From the “Game of Life”, many possibilities can be achieved. The application in Project 2 is just one of the many applications. “Game of Life” can be used to generate fractals or something that resembles the nature. It is a chaos system that generates an orderly result.