// Bring cells with three living neighbors to life public void CheckBringCellToLife(List<Cell> deadNeighbors) { CellEqualityComparer cellComparer = new CellEqualityComparer(); Dictionary<Cell, int> neighborDict = new Dictionary<Cell, int>(cellComparer); foreach (var neighbor in deadNeighbors) { if (neighborDict.ContainsKey(neighbor)) { neighborDict[neighbor] += 1; } else { neighborDict.Add(neighbor, 1); } } foreach (var cell in neighborDict) { if (cell.Value == 3) { AliveCells.Add(cell.Key); } } }
public TCell this[int x, int y] { get { CheckLocation(ref x, ref y); TGridBlock block = null; ShortPoint blockLocation = default(ShortPoint); int cellX, cellY; int blockSize = BlockSize; GridBlock.GetBlockCellLocation(ref x, ref y, ref blockSize, out blockLocation, out cellX, out cellY); if (Blocks.TryGetItem(blockLocation, out block)) { return(block.GetCell(cellX, cellY)); } return(default(TCell)); } set { CheckLocation(ref x, ref y); TGridBlock block = null; ShortPoint blockLocation = default(ShortPoint); int tileX, tileY; int blockSize = BlockSize; GridBlock.GetBlockCellLocation(ref x, ref y, ref blockSize, out blockLocation, out tileX, out tileY); if (!Blocks.TryGetItem(blockLocation, out block)) { if (CellEqualityComparer.Equals(value, default(TCell))) { return; } block = CreateBlock(blockLocation); AddBlock(block); } var currentValue = block.GetCell(tileX, tileY); if (block.SetCell(tileX, tileY, value)) { OnCellContentChanged(tileX, tileY, block, currentValue, value); } } }