Game of Life simulation
I originally wrote a Game of Life model in C, GOL. But I wanted to convert it into Golang for a few reasons:
- Learn Go
- Consider more novel topologies based on border rules (see #border-topologies).
- Extend GOL simulation for generic update rules.
- Extend GOL lattice for integer values (i.e. not just 1/0)
- Run physical system simulations based on applications of cellular automaton:
- Computational fluid dynamics
- Population dynamics
- Ising Models
- Other interesting cellular automaton: Rule 90, Langton's ant
- Boolean binary logic rules (i.e. consider the 1 cell + 4 neighbours as a 5 bit input - 1 bit output to a logic circuit)
- Discretise and extend to 2D my previous research in rho signalling in cell-cell junctions during collective cell migration
Current usage simply displays the simulation onto the terminal. Usage:
> Go-L --help
Usage of Go-L:
-aliveratio float
The fraction of squares that start as alive, assigned at random. Domain: [0.0, 1.0]. (default 0.8)
-gridsize uint
Length of square grid to define game on. (default 20)
-iterations uint
Max number of iterations to simulate game of life. If stable solution, will exit early. (default 100)
-topology string
Specify the topology of the grid (as a fundamental topology from a parallelograms). Valid parameters: BORDERED, TORUS, KLEIN_BOTTLE, PROJECTIVE_PLANE, SPHERE. (default "BORDERED")
-updatedelay uint
Additional period delay between updating rounds of the game, in milliseconds. Does not take into account processing time. (default 200)
-updaterule uint
Specify the number associated with the update rule to use. Default to Conway's Game of Life. (default 1994975360)
In redefining how the border conditions work, we can simulate GOL as if it was played on a variety of manifolds. This is most clearly seen when looking at the fundamental polygons derived from a square (or parallelogram). When considering the neighbours of a cell on the border of the lattice, a fundamental polygon helps show where the neighbouring values should be.
Sphere | Real Projective Plane | Klein Bottle | Torus |
---|---|---|---|
Consider a square lattice of size 5, coordinates indexed in
Or for a torus
or a real projective plane
and lastly a klein bottle
For update rules that consider 2nd degree neighbours (i.e.
A cellular automaton designed by mathematician John Conway showing how complex emergent behaviour can arise from simple rules. In his case, at each future timestamp, a cell will be updated, based on its four neighbouring cells:
- A live cell will survive if only 2 or 3 of its neighbours are alive
- A dead cell with 3 alive neighbours will become alive
- All other cells die.
Conway's Game of Life is but one 2D cellular automata that depends only on its 4 direct neighbours. One can conceive of
other update rules. If one considers the five relevant cells: left, cell, right, up & down, there are then
- Define an ordered set on the 32 possible states $ { s_i }_{i=0}^{32} $
- Create a 32 digit binary number,
$B$ , where$B_i = 1$ iff the update rule maps the cell with state$S_i$ to 1. - All update rules can be then indexed from this,
$U_B : {0,1}^5 \to { 0, 1}$
Consider a simple 1D case of: left, cell, right. There are 8 states with a natural indexing:
111 | 110 | 101 | 100 | 011 | 010 | 001 | 000 |
---|---|---|---|---|---|---|---|
1 | 0 | 1 | 1 | 0 | 0 | 0 | 1 |
In this repo, we consider a similar binary representation for cells: left, cell, right, up, down and a natural indexing
We can now consider the update rule in Conway's Game of Life:
- Alive and 3 neighbours: 01111, 10111, 11101, 11110 ([15, 23, 29, 30])
- Alive and 2 neighbours: 00111, 01101, 01110, 10101, 10110, 11100 ([7, 13, 14, 21, 22, 28])
- Dead and 3 neighbours: 01011, 10011, 11001, 11010 ([11, 19, 25, 26])
Which gives a binary number with 1's at positions: [7, 11, 13, 14, 15, 19, 21, 22, 23, 25, 26, 28, 29, 30] or in binary: 01110110111010001110100010000000 or in base 10: 1994975360