예제 #1
0
 public void AddAliveCellInNextGeneration(Cell cell)
 {
     if (NewBornShouldBeGrey)
     {
         NextWorld.Add(new Cell(cell.X, cell.Y, DeadOrAlive.Grey));
         NewBornShouldBeGrey = false;
     }
     else
         NextWorld.Add(cell);
 }
예제 #2
0
        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;
        }
예제 #3
0
 public void AliveCellRemainsAlive(Cell cell)
 {
     if (NumberOfAliveNeighbours(cell) == 3 || NumberOfAliveNeighbours(cell) == 2)
     {
         AddAliveCellInNextGeneration(cell);
     }
     else
     {
         AddDeadCellInNextGeneration(cell);
     }
 }
예제 #4
0
 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++;
 }
예제 #5
0
 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)));
 }
예제 #6
0
 public void AddDeadCellInNextGeneration(Cell cell)
 {
     NextWorld.Add(new Cell(cell.X, cell.Y, DeadOrAlive.O));
 }
예제 #7
0
        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;
        }
예제 #8
0
 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);
 }
예제 #9
0
 public void DeadCellRevives(Cell cell)
 {
     if (NumberOfAliveNeighbours(cell) == 3)
     {
         AddAliveCellInNextGeneration(cell);
     }
     else
     {
         AddDeadCellInNextGeneration(cell);
     }
 }