Conway's Game of Life
Simulation in Unity3D
By: Nikhil Jolly
This is a simulation project made in Unity3D based on the Conway's Game of Life.
You can read more about it on the wiki page:
Open the "Game" scene in Unity.
Create: Used to create a board of cells with specific dimensions.
Caution: Keep them close to 100*100 (depending upon the system), otherwise you will face memory issues. No 'hardcore' optimizations have been implemented yet.
Create a custom board: After generating a board, touch/cick on the cells to change there states. Clear the board if required.
Next: Used to move to next generation of cells based on Conway's rules.
Start/Stop: Used to start and stop a simulation of the board, creating next generation cells.
Clear: Used to clear the board (kill all the cells).
Camera: Slider to vary the size of camera.
Speed: Slider to vary the speed of simulation.
Gosper's Glider Gun: Used to initiate the cells with seed of Gosper's GG.
- Shows generation number for each generation of cells.
For further understanding:
- Board is created as per the dimensions passed whilst using the offset for apt position.
- Each cell is populated with an array representing all of it's neighbours.
- Sets neighbour as well as state of cells randomly (with 50% probability of dead and alive).
- The generation counter is set to 0.
- Makes a copy of the state of the cells and evaluates the next generation of cells whilst modifying any changes to the new copy.
- Modifies the current cells based on the changes stored in the new copy of states.
- Also increments the generation counter.
- Calls next generation again and again after a delay whilst incrementing the generation counter.
- The board can be modified at any time by clicking/touching a cell, which results in change of state.
Map management (Beta):
- Can only be used in editor to save and load maps for testing of any map of cells.
- By default contains a string representing a map of "Gosper's Glider Gun" which can be loaded via a button in the UI.
- Each is either dead or alive represented by the boolean values as follows; Dead: False, Alive: True
- Each cell contains an array of neighbours (created on creating the board)
- Doesn't use MonoBehaviour, instead is represented a custom class (minor memory optimization).
- Cells start from (0, 0) to (sizeX-1, sizeY-1)
Rules followed to evaluate a cell:
- If cell is alive
- <2 (0 or 1) alive neighbours: Cell dies
3 alive neighbours: Cell dies
- 2 or 3 alive neighbours: Cell lives
- If cell is dead
- 3 alive neighbours: Cell comes to life
- Else stays dead
- If cell is alive
Each script is well documented. Kindly refer to them if a part is not understandable.
The code isn't highly optimized for handling large amount of dimensions for the board. Keep them close to 100x100 (depending upon the system).