bool TryBringCellBackToLife(Position position, out Cell newLiveCell) { Cell deadCell = Cell.DeadAt(position); int liveNeighbourCount = GetLiveNeighbours(position); newLiveCell = deadCell.Tick(liveNeighbourCount); return newLiveCell.IsAlive; }
IEnumerable<Cell> ReanimateDeadNeighbours(Cell cell, ConcurrentDictionary<Position, bool> positionsWeAlreadyChecked) { var newCells = new List<Cell>(); VisitNeighbours(cell.Position, position => { if (HaveVisitedAlready(positionsWeAlreadyChecked, position)) return; Cell newLiveCell; if (TryBringCellBackToLife(position, out newLiveCell)) { newCells.Add(newLiveCell); } }); return newCells; }