Skip to content

A terminal-based version of the Game Of Life, written in C.

License

Notifications You must be signed in to change notification settings

bluekeybo/GameOfLife

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conway's Game of Life

A terminal-based implementation in C

This program implements The Game of Life by John Conway, in C.

The rules are:

  1. Any live cell with fewer than two live neighbours dies (underpopulation).
  2. Any live cell with two or three live neighbours lives to next generation.
  3. Any live cell with more than three live neighbours dies (overpopulation).
  4. Any dead cell with exactly three live neighbours comes alive.
Game Board

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.

Custom Game Board: '1' represents an alive cell; '0' represents a dead cell
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.

Printed Board: 'o' represents an alive cell; ' ' represents a dead cell
..........................
.            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.

Usage:

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.

Examples:

  1. 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:
Two Gosper Glider Guns

  1. 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:
Multiple Gliders

  1. 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:
Random Board

  1. 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:
RLE Format Board

For details on Code of Conduct, Issue and Pull requests and Contributing Guidelines, please see the docs directory.

Enjoy!

About

A terminal-based version of the Game Of Life, written in C.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages