/// <summary> /// This method updates the status of each cell in the Game of Life board /// </summary> /// <param name="matrix">Matrix containing the cells of the Game of Life board</param> /// <returns>The updated board matrix (The next day)</returns> public static Cell[,] MakeMove(Cell[,] matrix) { // Copy all elements in matrix to _bufferMatrix CopyCells(matrix); // Update each cell in _bufferMatrix for (int i = 0; i < matrix.GetLength(0); i++) { for (int j = 0; j < matrix.GetLength(1); j++) { int? cellStatus = matrix[i, j].Status; UpdateCell(matrix, i, j, cellStatus); } } return _bufferMatrix; }
/// <summary> /// Use to copy all elements in matrix to _bufferMatrix /// </summary> /// <param name="matrix">Matrix containing all cells of the Game of Life board</param> /// <remarks>If elements in the parameter are not value types, the following modification is needed: replace contents in first nested loop with outcommented code</remarks> private static void CopyCells(Cell[,] matrix) { int dimensionI = matrix.GetLength(0); int dimensionJ = matrix.GetLength(1); _bufferMatrix = new Cell[dimensionI, dimensionJ]; for (int i = 0; i < dimensionI; i++) { for (int j = 0; j < dimensionJ; j++) { _bufferMatrix[i, j] = matrix[i, j]; //// The following commented lines should replace the line above if Cell becomes a reference type instead of a value type. //_bufferMatrix[i, j] = new Cell(); //_bufferMatrix[i,j].Status = matrix[i,j].Status; } } }