Ejemplo n.º 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);
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 3
0
 public void AliveCellRemainsAlive(Cell cell)
 {
     if (NumberOfAliveNeighbours(cell) == 3 || NumberOfAliveNeighbours(cell) == 2)
     {
         AddAliveCellInNextGeneration(cell);
     }
     else
     {
         AddDeadCellInNextGeneration(cell);
     }
 }
Ejemplo n.º 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++;
 }
Ejemplo n.º 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)));
 }
Ejemplo n.º 6
0
 public void AddDeadCellInNextGeneration(Cell cell)
 {
     NextWorld.Add(new Cell(cell.X, cell.Y, DeadOrAlive.O));
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 9
0
 public void DeadCellRevives(Cell cell)
 {
     if (NumberOfAliveNeighbours(cell) == 3)
     {
         AddAliveCellInNextGeneration(cell);
     }
     else
     {
         AddDeadCellInNextGeneration(cell);
     }
 }