private void updateNeighbourCounterAndStatusOnGridCell( CellShape gridCell[][], int row, int column, CellStatus newCellStatus) { // a) update neighbour counter of adyacent cells CellShape cellNeighbour = null; for (int neighbourRow = row - 1; neighbourRow <= row + 1; neighbourRow++) { for (int neighbourColumn = column - 1; neighbourColumn <= column + 1; neighbourColumn++) { if (!isCaseIncreasingSameCellLookingForNeighbours( neighbourRow, neighbourColumn, row, column) && !isOutOfGrid(neighbourRow, neighbourColumn)) { cellNeighbour = gridCell[neighbourRow][neighbourColumn]; cellNeighbour.neighboursNumber = (newCellStatus == CellStatus.LIVE) ? cellNeighbour.neighboursNumber + 1 : cellNeighbour.neighboursNumber - 1; } } } // b) update new cell status gridCell[row][column].status = newCellStatus; }
@Override protected Object clone() throws CloneNotSupportedException { CellShape cellCloned = new CellShape(this.status); cellCloned.neighboursNumber = this.neighboursNumber; return cellCloned; }