Conway's game of life is a simulation that uses simple rules to imitate cellular reproduction.
This program is an emulation of Conway's game of life in the console, created using C#.
In this program, the game takes place in a grid, which is a 2D array of cells. The dimensions of the grid are specified by the user. Try catches are combined with while loops to force the user to input a suitable value, meaning a non-negative integer. This prevents the program from crashing if the user accidentally inputs letters, symbols, or other invalid inputs that the program can't interpret.
After the user specifies the dimensions, the grid is randomly populated, with each cell having a value of 1 or 0. A value of 1 represents a live cell, whereas a value of 0 represents a dead cell.
The user then specifies how many times they want to run the game, as in how many generations will be simulated. The same try catch + while loop is applied to once again prevent incorrect inputs.
To get the next generation, the rules of the game of life are applied to each cell individually.
The rules determine whether a cell lives based on it's neighbours. Neighbours are defined as the 8 cells that surround the cell in the grid. Cells on the edges and corners of the grid do not have a full 8 neighbours, but the rules are still applied in the same way.
The rules are as follows:
- A live cell with less than 2 neighbours will die
- A live cell with 2 - 3 live neighbours will live
- A live cell with more than 3 neighbours will die
- A dead cell with exactly 3 neighbours becomes a live cell
To accomplish this, the program uses 2 2D cell arrays: a main array, and an interim array.
The interim array exists as a copy of the main array. To find what the next state of a cell in the main array will be, the program looks at the corresponding cell at the same coordinates in the interim array and its neighbours. It then applies the rules accordingly, and updates the state of the cell in the main array. This is done because the rules of the game must be applied to every cell at once; i.e. all cells should change state based off their neighbours in the previous generation.
Once the program has run the given amount of generations, it will print the message "The simulation has ended." and shut down.
This project was completed as part of the ICS4U course at Milton District High School.
Credit to GitHub user kmorcinek for the .gitignore file found here.
R.I.P. John Horton Conway (26 December 1937 - 11 April 2020)