private void CreateRowsInPreviousState() { for (int row = 0; row < RowCount; row++) { PreviousState.Add(new List <ICell>()); } }
public override bool Update() { // Add the begining state if (PreviousState.Count == 0) { PreviousState.Add(getStateFromCells(CellMatrix)); } // Checking which cells need to be updated // Doing so without inplace updates to exclude grid corruption for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { CellMatrix[i, j].CheckAliveState(); } } // Update the changed cells for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (CellMatrix[i, j].NeedUpdate) { CellMatrix[i, j].IsAlive = CellMatrix[i, j].NewState; CellMatrix[i, j].NeedUpdate = false; } } } if (CheckPreviousStates(getStateFromCells(CellMatrix))) { PreviousState.Add(getStateFromCells(CellMatrix)); return(true); } else { return(false); } }