public void ActiveMatrix(int[,] matrix) { liveMatrix = (int[, ])matrix.Clone(); int colLength = liveMatrix.GetLength(0); int rowLength = liveMatrix.GetLength(1); for (int i = 0; i < rowLength; i++) { for (int j = 0; j < colLength; j++) { int numberLiveCells = _conwayMatrixService.GetLiveCells(i, j, liveMatrix); int newCell = _conwayMatrixService.GetCellsBehaviour(matrix[i, j], numberLiveCells); matrix[i, j] = newCell; } } oldMatrix = (int[, ])matrix.Clone(); DisplayMatrix(matrix); Console.WriteLine("Enter y to continue: "); string option = Console.ReadLine(); option = option.ToLower(); if (option == "y") { ActiveMatrix(oldMatrix); } else { return; } }
public JsonResult GetConveyMatrix(int[,] matrix) { if (matrix == null) { matrix = new int[, ] { { 1, 0, 0, 0 }, { 0, 0, 1, 0 }, { 1, 1, 1, 0 }, { 0, 1, 0, 0 }, }; } liveMatrix = (int[, ])matrix.Clone(); int colLength = liveMatrix.GetLength(0); int rowLength = liveMatrix.GetLength(1); for (int i = 0; i < rowLength; i++) { for (int j = 0; j < colLength; j++) { int numberLiveCells = _conwayMatrixService.GetLiveCells(i, j, liveMatrix); int newCell = _conwayMatrixService.GetCellsBehaviour(matrix[i, j], numberLiveCells); matrix[i, j] = newCell; } oldMatrix = (int[, ])matrix.Clone(); } string json = JsonConvert.SerializeObject(matrix); return(Json(json, "application/json", JsonRequestBehavior.AllowGet)); }
public void GetLiveCells_WithNullInput_ThrowsException() { _conwayMatrixService = new ConwayMatrixService(); int matrixRow = 0; int matrixCol = 0; int[,] matrix = null; var liveCeels = _conwayMatrixService.GetLiveCells(matrixRow, matrixCol, matrix); }
public void GetLiveCells_WithinputMatrix_ReturnsZeroCells() { _conwayMatrixService = new ConwayMatrixService(); int matrixRow = 0; int matrixCol = 0; int[,] matrix = new int[, ] { { 1, 0, 0, 0 }, { 0, 0, 1, 0 }, { 1, 1, 1, 0 }, { 0, 1, 0, 0 }, }; var liveCeels = _conwayMatrixService.GetLiveCells(matrixRow, matrixCol, matrix); Assert.IsTrue(liveCeels == 0); }