コード例 #1
0
ファイル: World.cs プロジェクト: bittercoder/Conways
        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
ファイル: World.cs プロジェクト: bittercoder/Conways
        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;
        }