Conway's Game of Life is a classic cellular automaton that simulates the evolution of a group of cells on a grid based on simple rules. Here's an implementation in C#:
main.cs2006 chars75 lines
This program defines a GameOfLife class that implements the basic logic of the simulation. The initBoard()
method initializes the board with random values, and the printBoard()
method prints the board to the console.
The nextGeneration()
method computes the next generation of the board based on the number of neighbors each cell has. The countNeighbors()
method computes the number of live neighbors of a given cell, accounting for the wrap-around edges of the grid.
Finally, the Main()
method creates a GameOfLife
object, initializes the board and runs the simulation for 10 generations, printing the board and waiting for one second between each generation.
gistlibby LogSnag