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); }
private bool IsNeighbor(ICellIndex c) { if (!c.IsLifeCell) { return(false); } if (c.Generation <= 0) { return(true); } return(!_playData.Params.UseGenerations); }
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); } } } }
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); } }
protected abstract IEnumerable <ICellIndex> NeighborCellIndexEnum(ICellIndex cellIndex);
public int GetLifeNeighborhoodCount(ICellIndex cellIndex) { return(NeighborCellIndexEnum(cellIndex).Count(IsNeighbor)); }
protected override bool CheckNeighborsCountForSurvivals(ICellIndex cellIndex, int neighborhoodCount) { return(_survivalsNeighborsCount.Contains(neighborhoodCount)); }
protected override bool CheckNeighborsCountForNewCell(ICellIndex cellIndex, int neighborhoodCount) { return(_newNeighborsCount.Contains(neighborhoodCount)); }
public bool IsNewCellPolicy(ICellIndex cellIndex, int neighborhoodCount) { return(cellIndex.IsEmptyCell && CheckNeighborsCountForNewCell(cellIndex, neighborhoodCount)); }
protected abstract bool CheckNeighborsCountForSurvivals(ICellIndex cellIndex, int neighborhoodCount);
public bool IsDyingCellPolicy(ICellIndex cellIndex, int neighborhoodCount, int maxGenerations) { return(cellIndex.IsLifeCell && (!CheckNeighborsCountForSurvivals(cellIndex, neighborhoodCount) || cellIndex.Generation > maxGenerations)); }
protected abstract bool CheckNeighborsCountForNewCell(ICellIndex cellIndex, int neighborhoodCount);