public void AddAliveCellInNextGeneration(Cell cell) { if (NewBornShouldBeGrey) { NextWorld.Add(new Cell(cell.X, cell.Y, DeadOrAlive.Grey)); NewBornShouldBeGrey = false; } else NextWorld.Add(cell); }
public bool CellHasNeighboursOnRightAndLeftSide(Cell cellToBeVerified,Cell cell) { return ((cellToBeVerified.Y == (cell.Y - 1) || cellToBeVerified.Y == (cell.Y + 1)) && (cellToBeVerified.X == cell.X)); //if ((cellToBeVerified.Y == (cell.Y - 1) || cellToBeVerified.Y == (cell.Y + 1)) && (cellToBeVerified.X == cell.X)) //{ // return true; //} //return false; }
public void AliveCellRemainsAlive(Cell cell) { if (NumberOfAliveNeighbours(cell) == 3 || NumberOfAliveNeighbours(cell) == 2) { AddAliveCellInNextGeneration(cell); } else { AddDeadCellInNextGeneration(cell); } }
public void CountNumberOfWhiteAndBlackCells(Cell cell,ref int white,ref int black) { if (cell.State.Equals(DeadOrAlive.White)) white++; if (cell.State.Equals(DeadOrAlive.Black)) black++; }
public bool CellHasNeighboursUnder(Cell cellToBeVerified , Cell unit ) { return ((cellToBeVerified.X == unit.X - 1) && ((cellToBeVerified.Y == (unit.Y - 1) || cellToBeVerified.Y == (unit.Y + 1) || cellToBeVerified.Y == unit.Y))); }
public void AddDeadCellInNextGeneration(Cell cell) { NextWorld.Add(new Cell(cell.X, cell.Y, DeadOrAlive.O)); }
public int NumberOfAliveNeighbours(Cell cellToBeVerified) { var numberOfAliveNeighbours = 0; var black = 0; var white = 0; foreach (var unit in CurrentWorld) { if (unit.State.Equals(DeadOrAlive.White) || unit.State.Equals(DeadOrAlive.Black) || unit.State.Equals(DeadOrAlive.Grey)) { if(CellHasNeighboursOnRightAndLeftSide(cellToBeVerified, unit)) { IncreaseNumberOfAliveNeighbours(ref numberOfAliveNeighbours); CountNumberOfWhiteAndBlackCells(unit, ref white, ref black); } if (CellHasNeighboursUnder(cellToBeVerified, unit)) { IncreaseNumberOfAliveNeighbours(ref numberOfAliveNeighbours); CountNumberOfWhiteAndBlackCells(unit, ref white, ref black); } if (CellHasNeighboursOnTop(cellToBeVerified, unit)) { IncreaseNumberOfAliveNeighbours(ref numberOfAliveNeighbours); CountNumberOfWhiteAndBlackCells(unit, ref white, ref black); } } } DecideIfNewBornShouldBeGrey(black, white); return numberOfAliveNeighbours; }
public void DecideIfCellBecomesDeadOrAlive(Cell cell) { if (cell.State.Equals(DeadOrAlive.White) || cell.State.Equals(DeadOrAlive.Black) || cell.State.Equals(DeadOrAlive.Grey)) { AliveCellRemainsAlive(cell); } else DeadCellRevives(cell); }
public void DeadCellRevives(Cell cell) { if (NumberOfAliveNeighbours(cell) == 3) { AddAliveCellInNextGeneration(cell); } else { AddDeadCellInNextGeneration(cell); } }