This program implements The Game of Life by John Conway, in C.
- Any live cell with fewer than two live neighbours dies (underpopulation).
- Any live cell with two or three live neighbours lives to next generation.
- Any live cell with more than three live neighbours dies (overpopulation).
- Any dead cell with exactly three live neighbours comes alive.
The program supports the RLE file format, which stands for Run Length Encoded. This means that you can load and run any game board from over a thousand patterns hosted on the LifeWiki website.
For some sample rle input files, see the *.rle files in the inputPatterns
directory.
000000000000111100000000
000000111000111000000100
000000000001111000000010
000000111110001000001110
000000000111111110000000
If you wish to provide your own custom patterns in plaintext format, you can do so by following this convention. All the rows must be the same length. Use a 1 to represent an alive cell and a 0 to represent a dead cell.
For a sample input file, see the twoGosperGliderGuns file in the inputPatterns
directory.
..........................
. oooo .
. ooo ooo o .
. oooo o .
. ooooo o ooo .
. oooooooo .
..........................
The printed board consists of an 'o' to represent an alive cell and a '_' (space) to represent a dead cell. The dots shown above are used for creating the wrap around effect. Each dot is replaced by the opposite side's value. These extra values are not printed, they're just used for calculating the rules correctly. This allows the automata to develop as if the board is continuous and wraps around itself.
To compile, run:
gcc gameOfLife.c -o <filename>
Generating a random board:
<filename> -random rows columns [-time timeMilli] [-gen numberOfGen]
Supplying an input board:
<filename> -input inputPattern [-time timeMilli] [-gen numberOfGen]
Notes:
- default timeMilli is 200.
- default number of generations is infinite.
- if the inputPattern file ends in .rle the program will use the RLE format.
- if the input file is not in the same directory, please provide the path to it when using the -input option.
- Two Gosper Glider Guns
Compile:
gcc gameOfLife.c -o gameOfLife
Run:
./gameOfLife -input twoGosperGliderGuns -time 100
This will run the game using the input file provided as input and updating the board every 100 milliseconds. Since -gen option was not provided, the program will run indefinitely (until user stops it with CTRL + \).
Here is the resulting simulation:
- Multiple Gliders
Compile:
gcc gameOfLife.c -o gameOfLife
Run:
./gameOfLife -input rainingGliders -time 100
This will run the game the same way as in the previous example.
Here is the resulting simulation:
- Random Board
Compile:
gcc gameOfLife.c -o gameOfLife
Run:
./gameOfLife -random 30 100 -time 150
This will generate a random board (with random dead and alive cells). The board size is 30 rows by 100 columns and the speed will be 150 milliseconds. The game will run for only 1000 generations.
Here is the resulting simulation:
- RLE Board
Compile:
gcc gameOfLife.c -o gameOfLife
Run:
./gameOfLife -input lightspeedoscillator1.rle
This will generate the board using the RLE format. The pattern used is the Light Speed Oscillator 1.
Here is the resulting simulation:
For details on Code of Conduct, Issue and Pull requests and Contributing Guidelines, please see the docs
directory.
Enjoy!