Skip to content

pasdo501/conway-unity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conway's Game of Life (Unity)

Implementation of the famous Conway's Game of Life simulation in C#, using the Unity game engine.

The project is currently deployed at https://conwayunity.azurewebsites.net/

Implementation Notes

Each cell is represented as a byte, with the top 3 bits unused, and next 4 bits used to store a count of the cell's live neighbours, and the lowest bit being used to store the cell's state (alive = high or dead = low).

i.e - XXXN NNNS

Where X is an unused bit; N is the cell's live neighbour count; S is the cell's state.

This implementation is an adapted version of Michael Abrash's optimised version of Life - see Listing 17.5 L17-5.CPP.

Optimisation Notes

Profiling of the initial (very simple) implementation suggested 94% of CPU usage was down to the LiveNeighbourCount function (function used to count how many live neighbours a cell has).

This initial implementation resulted in ~20 - 25 generations / second.

The optimised implementation is heavily based on Michael Abrash's optimised version of the simulation. While not making use of pointer arithmetic and still using a 2D array with a wrapping index function, CPU usage by the main update loop has dropped dramatically (~11%), with the result now ~60 generations / second (possible limited by Unity's framerate?).


General Notes

  • The initial game state is random, and currently cannot be changed in any way. The probability of any given cell being alive at the start of the game is 0.08.
  • No stoppage mechanism of any kind is implemented. The simulation will keep going even if there are no more cells alive or a stable equilibrium has been reached.
  • Implementation details are found in the Scripts directory.

About

Conway's Game of Life implemented in Unity

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages