コード例 #1
0
        public bool TryMakeCellIndex(int col, int row, out ICellIndex cellIndex)
        {
            cellIndex = col >= 0 && col < Cols && row >= 0 && row < Rows
                ? new CellIndex(col, row, this)
                : null;

            return(cellIndex != null);
        }
コード例 #2
0
        private bool IsNeighbor(ICellIndex c)
        {
            if (!c.IsLifeCell)
            {
                return(false);
            }

            if (c.Generation <= 0)
            {
                return(true);
            }

            return(!_playData.Params.UseGenerations);
        }
コード例 #3
0
        protected override IEnumerable <ICellIndex> NeighborCellIndexEnum(ICellIndex cellIndex)
        {
            for (int deltaCol = -1; deltaCol <= 1; deltaCol++)
            {
                for (int deltaRow = -1; deltaRow <= 1; deltaRow++)
                {
                    if (deltaCol == 0 && deltaRow == 0)
                    {
                        continue;
                    }

                    int tmpCol = cellIndex.Col + deltaCol;
                    int tmpRow = cellIndex.Row + deltaRow;

                    if (PlayData.Area.TryMakeCellIndex(tmpCol, tmpRow, out ICellIndex tmpCellIndex))
                    {
                        yield return(tmpCellIndex);
                    }
                }
            }
        }
コード例 #4
0
        protected override IEnumerable <ICellIndex> NeighborCellIndexEnum(ICellIndex cellIndex)
        {
            if (PlayData.Area.TryMakeCellIndex(cellIndex.Col + 1, cellIndex.Row, out ICellIndex tmpCellIndex))
            {
                yield return(tmpCellIndex);
            }

            if (PlayData.Area.TryMakeCellIndex(cellIndex.Col - 1, cellIndex.Row, out tmpCellIndex))
            {
                yield return(tmpCellIndex);
            }

            if (PlayData.Area.TryMakeCellIndex(cellIndex.Col, cellIndex.Row + 1, out tmpCellIndex))
            {
                yield return(tmpCellIndex);
            }

            if (PlayData.Area.TryMakeCellIndex(cellIndex.Col, cellIndex.Row - 1, out tmpCellIndex))
            {
                yield return(tmpCellIndex);
            }
        }
コード例 #5
0
 protected abstract IEnumerable <ICellIndex> NeighborCellIndexEnum(ICellIndex cellIndex);
コード例 #6
0
 public int GetLifeNeighborhoodCount(ICellIndex cellIndex)
 {
     return(NeighborCellIndexEnum(cellIndex).Count(IsNeighbor));
 }
コード例 #7
0
 protected override bool CheckNeighborsCountForSurvivals(ICellIndex cellIndex, int neighborhoodCount)
 {
     return(_survivalsNeighborsCount.Contains(neighborhoodCount));
 }
コード例 #8
0
 protected override bool CheckNeighborsCountForNewCell(ICellIndex cellIndex, int neighborhoodCount)
 {
     return(_newNeighborsCount.Contains(neighborhoodCount));
 }
コード例 #9
0
 public bool IsNewCellPolicy(ICellIndex cellIndex, int neighborhoodCount)
 {
     return(cellIndex.IsEmptyCell && CheckNeighborsCountForNewCell(cellIndex, neighborhoodCount));
 }
コード例 #10
0
 protected abstract bool CheckNeighborsCountForSurvivals(ICellIndex cellIndex, int neighborhoodCount);
コード例 #11
0
 public bool IsDyingCellPolicy(ICellIndex cellIndex, int neighborhoodCount, int maxGenerations)
 {
     return(cellIndex.IsLifeCell && (!CheckNeighborsCountForSurvivals(cellIndex, neighborhoodCount) || cellIndex.Generation > maxGenerations));
 }
コード例 #12
0
 protected abstract bool CheckNeighborsCountForNewCell(ICellIndex cellIndex, int neighborhoodCount);