static void Main(string[] args) { Func <Task4, char[, ]> TaskSolver = task => { int row = task.Board.GetLength(0); int column = task.Board.GetLength(1); char[,] board = new char[row, column]; char[,] old = new char[row, column]; CopyArray(task.Board, board, row, column); for (int i = 0; i < row; i++) { for (int j = 0; j < column; j++) { board[i, j] = GetNextGenerate(task.Board, i, j); } } // GameOfLife(); return(board); }; Task4.CheckSolver(TaskSolver); }
static void Main(string[] args) { Func <Task4, char[, ]> TaskSolver = task => { // Your solution goes here // You can get all needed inputs from task.[Property] // Good luck! char[,] board = task.Board; int m = board.GetLength(0); int n = board.GetLength(1); char[,] nextBoard = board.Clone() as char[, ]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { int aliveNeighbours = IsNeighborAlive(board, i, j, -1, -1) + IsNeighborAlive(board, i, j, -1, 0) + IsNeighborAlive(board, i, j, -1, 1) + IsNeighborAlive(board, i, j, 0, -1) + IsNeighborAlive(board, i, j, 0, 1) + IsNeighborAlive(board, i, j, 1, -1) + IsNeighborAlive(board, i, j, 1, 0) + IsNeighborAlive(board, i, j, 1, 1); nextBoard[i, j] = GetNextIterationValue(board[i, j], aliveNeighbours); } } return(nextBoard); }; Task4.CheckSolver(TaskSolver); }
static void Main(string[] args) { Func <Task4, char[, ]> TaskSolver = task => { // Your solution goes here // You can get all needed inputs from task.[Property] // Good luck! char[,] board = task.Board; int x = board.GetLength(0); int y = board.GetLength(1); char[,] newBoard = new char[x, y]; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { int aliveNeighbors = 0; int leftMargin = i - 1 >= 0 ? i - 1 : i; int rightMargin = i + 1 < x ? i + 1 : i; int topMargin = j - 1 >= 0 ? j - 1 : j; int bottomMargin = j + 1 < y ? j + 1 : j; for (int k = leftMargin; k <= rightMargin; k++) { for (int l = topMargin; l <= bottomMargin; l++) { if (i != k || j != l) { if (board[k, l] == '1') { aliveNeighbors++; } } } } if (aliveNeighbors < 2 || aliveNeighbors > 3) { newBoard[i, j] = '0'; } else if (aliveNeighbors == 3) { newBoard[i, j] = '1'; } else { newBoard[i, j] = board[i, j]; } } } return(newBoard); }; Task4.CheckSolver(TaskSolver); }
static void Main(string[] args) { Func <Task4, char[, ]> TaskSolver = task => { // Your solution goes here // You can get all needed inputs from task.[Property] // Good luck! char[,] board = task.Board; int x = board.GetLength(0); int y = board.GetLength(1); char[,] virtualBoard = new char[x + 2, y + 2]; for (int i = 1; i <= y; i++) { for (int j = 1; j <= x; j++) { virtualBoard[j, i] = board[j - 1, i - 1]; } } char[,] answerBoard = new char[x, y]; for (int i = 1; i <= y; i++) { for (int j = 1; j <= x; j++) { int aliveCells = GetAliveCellsCount(j, i, virtualBoard); if (virtualBoard[j, i] == '1' && (aliveCells == 2 || aliveCells == 3)) { answerBoard[j - 1, i - 1] = '1'; } else if (virtualBoard[j, i] == '0' && aliveCells == 3) { answerBoard[j - 1, i - 1] = '1'; } else { answerBoard[j - 1, i - 1] = '0'; } } } return(answerBoard); }; Task4.CheckSolver(TaskSolver); }
static void Main(string[] args) { Func <Task4, char[, ]> TaskSolver = task => { // Your solution goes here // You can get all needed inputs from task.[Property] // Good luck! char[,] board = task.Board; return(board); }; Task4.CheckSolver(TaskSolver); }
static void Main(string[] args) { Func <Task4, char[, ]> TaskSolver = task => { // Your solution goes here // You can get all needed inputs from task.[Property] // Good luck! char[,] board = task.Board; int rowNum = board.GetLength(0); int coloumnNum = board.GetLength(1); char[,] newBoard = new char[rowNum, coloumnNum]; NextBoard(board, newBoard); return(newBoard); }; Task4.CheckSolver(TaskSolver); }
static void Main(string[] args) { Func <Task4, char[, ]> TaskSolver = task => { char[,] initialBoard = task.Board; char[,] board = (char[, ])initialBoard.Clone(); int height = board.GetLength(1); int width = board.GetLength(0); for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { board[x, y] = ProcessCell(x, y, initialBoard); } } return(board); }; Task4.CheckSolver(TaskSolver); }
static void Main(string[] args) { Func <Task4, char[, ]> TaskSolver = task => { char[,] board = task.Board.Clone() as char[, ]; int n = board.GetLength(0); int m = board.GetLength(1); for (int i = 1; i < n - 1; ++i) { for (int j = 1; j < m - 1; ++j) { if (CheckInnerCell(task.Board, i, j)) { board[i, j] = '1'; } else { board[i, j] = '0'; } } } for (int i = 0; i < n; ++i) { //check top border and corners if (CheckBoundaryCell(task.Board, i, 0)) { board[i, 0] = '1'; } else { board[i, 0] = '0'; } //check down border and corners if (CheckBoundaryCell(task.Board, i, m - 1)) { board[i, m - 1] = '1'; } else { board[i, m - 1] = '0'; } } for (int j = 1; j < m - 1; ++j) { //check left border if (CheckBoundaryCell(task.Board, 0, j)) { board[0, j] = '1'; } else { board[0, j] = '0'; } //check right border if (CheckBoundaryCell(task.Board, n - 1, j)) { board[n - 1, j] = '1'; } else { board[n - 1, j] = '0'; } } return(board); }; Task4.CheckSolver(TaskSolver); }
static void Main(string[] args) { Func <Task4, char[, ]> TaskSolver = task => { // Your solution goes here // You can get all needed inputs from task.[Property] // Good luck! char[,] board = task.Board; uint height = (uint)board.GetLength(0); uint width = (uint)board.GetLength(1); char[,] result = new Char[height, width]; for (uint i = 0; i < height; i++) { for (uint j = 0; j < width; j++) { uint leftEdge; uint rightEdge; uint topEdge; uint bottomEdge; uint numberOfAlives = 0; if (j == 0) { leftEdge = 0; } else { leftEdge = j - 1; } if (j == width - 1) { rightEdge = j; } else { rightEdge = j + 1; } if (i == 0) { topEdge = 0; } else { topEdge = i - 1; } if (i == height - 1) { bottomEdge = i; } else { bottomEdge = i + 1; } for (uint k = leftEdge; k <= rightEdge; k++) { for (uint p = topEdge; p <= bottomEdge; p++) { if (k == j && p == i) { continue; } if (board[p, k] == '1') { numberOfAlives++; } } } if (numberOfAlives < 2) { result[i, j] = '0'; } else if ((numberOfAlives == 2 || numberOfAlives == 3) && board[i, j] == '1') { result[i, j] = '1'; } else if (numberOfAlives == 3 && board[i, j] == '0') { result[i, j] = '1'; } else if (numberOfAlives > 3 && board[i, j] == '1') { result[i, j] = '0'; } else { result[i, j] = '0'; } } } return(result); }; Task4.CheckSolver(TaskSolver); }