private void BringToLife(GameCell cell) { int aliveNeighbors = HowManyAliveNeighbors(cell); if (aliveNeighbors == 3) { cell.MarkForLife(); } else { cell.MarkForDeath(); } }
private void Executioner(GameCell cell) { int aliveNeighbors = HowManyAliveNeighbors(cell); if (aliveNeighbors > 3 || aliveNeighbors < 2) { cell.MarkForDeath(); } else { cell.MarkForLife(); } }
/** * Toggles live/dead of a selected cell * Not possible if GameOfLife runs */ public void SelectCell(GameCell cell) { if (!backgroundWorker.IsBusy) { if (!cell.Alive) { cell.IsAlive(); } else { cell.IsDead(); } } }
private void SetNeighbors(GameCell cell) { int rowAbove = IndexDown(cell.Row); int rowBelow = IndexUp(cell.Row); int colRight = IndexUp(cell.Col); int colLeft = IndexDown(cell.Col); List <GameCell> neighbors = new List <GameCell> { FindByRowAndCol(rowAbove, colLeft), FindByRowAndCol(rowAbove, cell.Col), FindByRowAndCol(rowAbove, colRight), FindByRowAndCol(cell.Row, colLeft), FindByRowAndCol(cell.Row, colRight), FindByRowAndCol(rowBelow, colLeft), FindByRowAndCol(rowBelow, cell.Col), FindByRowAndCol(rowBelow, colRight) }; cell.Neighbors = neighbors; }
private int HowManyAliveNeighbors(GameCell cell) { return(cell.Neighbors.Count(neighbor => neighbor.Alive)); }
//Add a cell to the population public void AddCells(GameCell cell) { Cells.Add(cell); }