public static void CalculateNextGeneration(Cell thisCell) { if (thisCell != null) { thisCell.SetNextState(); CalculateNextGeneration(thisCell.nextCell); thisCell.currentCellState = thisCell.nextCellState; } }
// recursive method to calculate the next state of every cell based on the current state of all neighbors public static void CalculateNextGeneration(Cell thisCell) { // base case is if we reached thisCell.nextCell == null if (thisCell != null) { // calculate the next state for the current cell thisCell.SetNextState(); // recurse through the whole linked list of thisCell.nextCell (moves through all cells to the "right") CalculateNextGeneration(thisCell.nextCell); // after all next states have been calculated for the organism // unfold the calling stack for every cell // and set the current state = the next state // (these are structures, so they can be copied by value) thisCell.currentCellState = thisCell.nextCellState; } }