示例#1
0
        bool TryBringCellBackToLife(Position position, out Cell newLiveCell)
        {
            Cell deadCell = Cell.DeadAt(position);

            int liveNeighbourCount = GetLiveNeighbours(position);

            newLiveCell = deadCell.Tick(liveNeighbourCount);

            return newLiveCell.IsAlive;
        }
示例#2
0
        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;
        }