The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.
The game 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, or, for advanced players, by creating patterns with particular properties.
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, (or populated and unpopulated, respectively). Every cell interacts with its eight neighbours, 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 neighbours dies, as if by underpopulation.
- Any live cell with two or three live neighbours lives on to the next generation.
- Any live cell with more than three live neighbours dies, as if by overpopulation.
- Any dead cell with exactly three live neighbours 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, and the discrete moment at which this happens is sometimes called a tick. Each generation is a pure function of the preceding one. The rules continue to be applied repeatedly to create further generations.
The Go programming language version go1.12.9 should be installed. Go to this link and follow the instructions to install based on the system. To check the installation, we can check its version by running the following command on the terminal:
go versionExample of the output:
go version go1.12.9 darwin/amd64The Dep, for dependency management tool for Go, version v0.5.4 should be installed. Go to this link and follow the instruction to install based on the system. To pcheck the installation, we can check its version by running the following command on the terminal:
dep versionExample of the output:
dep:
version : v0.5.4
build date : 2019-06-14
git hash : 1f7c19e
go version : go1.12.6
go compiler : gc
platform : darwin/amd64
features : ImportDuringSolve=falseIn order to test, go to this project root directory and run the following command:
make testIn order to build, go to this project root directory and run the following command:
make buildA new directory named bin (if not already there) will be created, containing the built project.
After building the project, in order to run, go to this project root directory and run the following command, fill in the [alphabet] value yourself:
make run inputtype=[a] inputpath=[b] outputtype=[c] outputpath=[d] generation=[e]Notes:
- [a]: can either be
file(if you want the input to be read from a file) orcustom(if you provide a way to get the input) - [b]: the location of the source, can be file location if the input type is
file(the extension should be *.cell) or any other source if it'scustom - [c]: can either be
file(if you want the output to be written to a file) orcustom(if you provide a way to put the output) - [d]: the location of the target, can be file location if the output type is
fileor any other target if it'scustom - [e]: number of generation (should be whole number more than zero)
Example:
make run inputtype=file inputpath=./input/glider.cell outputtype=file outputpath=./glider.cell generation=5The input and output file has the following limitations:
- living cell will be written as character
o - dead cell will be written a character
- - each line will be separated by new line character
- there's no empty line allowed
- the shape of the cell state should be in rectangle
- providing an all-dead state will result in error
- file extension should be
*.cell
Warning:
If inputtype or outputtype or both are set to be custom, then you need to provide the custom type that abide by the interface in contract.go inside io directory of this project. So, for inputtype, you have to provide a type that follows io.Reader while for outputtype would be io.Writer. In contrast, you don't have to put value to inputpath for inputtype and outputpath for outputtype respectively.
Example inputtype, for the input will be custom, while the output will be in the form of file.
make run inputtype=custom outputtype=file outputpath=./glider.cell generation=5Example outputtype, for the output will be custom, while the input will be from a file.
make run inputtype=file inputpath=./input/glider.cell outputtype=custom generation=5Example for both input and output will be custom.
make run inputtype=custom outputtype=custom generation=5Don't forget to provde the io.Reader or io.Writer or both when initializing the param