/// <summary> /// Determines the state of each cell in the next generation /// </summary> /// <param name="currentGrid"></param> /// <returns>New grid containing cells in their new state</returns> public static Grid NextGeneration(this Grid currentGrid) { Grid newGrid = new Grid(currentGrid.Rows, currentGrid.Columns); for (int i = 0; i < currentGrid.Rows; i++) { for (int j = 0; j < currentGrid.Columns; j++) { Cell currentCell = currentGrid.Cells[i, j]; int aliveNeighbours = currentCell.CountAliveNeigbours(currentGrid); newGrid.Cells[i, j].State = Rules.GetNewState(currentCell.State, aliveNeighbours); } } return(newGrid); }