/// <summary> /// Board constructor /// </summary> /// <param name="nbCellX">number of current cell on x</param> /// <param name="nbCellY">number of current cell on y</param> /// <param name="maxCellX">maximum number of cell on x (for precompute cell array)</param> /// <param name="maxCellY">maximum number of cell on y (for precompute cell array)</param> public Board(int nbCellX, int nbCellY, int maxCellX, int maxCellY) { NbCellX = nbCellX; NbCellY = nbCellY; MAX_BOARD_SIZE_X = maxCellX; MAX_BOARD_SIZE_Y = maxCellY; board = new Cell[MAX_BOARD_SIZE_X, MAX_BOARD_SIZE_Y]; InitBoard(); BoardStatistics = new BoardStatistics(this); }
/// <summary> /// Compute the next board state. /// The simulation rules are implemented here. /// If no changes are made the simulation is finish /// </summary> public void NextIteration() { IsEnd = true; int[,] boardNeighbours = ComputeBoardNeighbours();//get the neighboor array for (int i = 0; i < NbCellX; i++) { for (int j = 0; j < NbCellY; j++) { int nbNeighbours = boardNeighbours[i, j]; if (board[i, j].IsAlive) { board[i, j].Age++; if (nbNeighbours < 2) { board[i, j].IsAlive = false; IsEnd = false; } if (nbNeighbours > 3) { board[i, j].IsAlive = false; IsEnd = false; } } else { if (nbNeighbours == 3) { board[i, j].IsAlive = true; IsEnd = false; } } } } BoardStatistics.IncIteration(); }