Exemplo n.º 1
0
 public void next_Rabbit_Carrot_Step()
 {
     BioUnit[,] aux = new BioUnit[this.rows, this.cols];
     for (var i = 0; i < this.rows; i++)
     {
         for (var j = 0; j < this.cols; j++)
         {
             aux[i, j] = null; //rule 2, rule 5
             //rule 1
             if (this.specie(this.cell[i, j]) == "Carrot")
             {
                 if (this.surrondingNeighborns(i, j, "Rabbit") == 0)
                 {
                     if (this.cell[i, j].will_I_live())
                     {
                         aux[i, j] = this.cell[i, j];
                     }
                 }
                 else
                 {
                     //rule 3
                     this.firstRabbit(i, j).eat();
                 }
             }
             //rule 4
             else if (this.specie(this.cell[i, j]) == "Rabbit")
             {
                 if (this.cell[i, j].will_I_live())
                 {
                     aux[i, j] = this.cell[i, j];
                 }
             }
             else
             {
                 //rule 6
                 if (this.cell[i, j] == null)
                 {
                     if (this.surrondingNeighborns(i, j, "Rabbit") >= 2)
                     {
                         aux[i, j] = new Rabbit(i, j, this);
                     }
                     else if (this.surrondingNeighborns(i, j, "Carrot") >= 3)
                     {
                         aux[i, j] = new Carrot(i, j, this);
                     }
                 }
             }
         }
     }
     for (var i = 0; i < this.rows; i++)
     {
         for (var j = 0; j < this.cols; j++)
         {
             this.cell[i, j] = aux[i, j];
         }
     }
 }
Exemplo n.º 2
0
 public void nextRabbitCarrotStep()
 {
     BioUnit[,] aux = new BioUnit[this.rows, this.cols];
     for (var i = 0; i < this.rows; i++)
     {
         for (var j = 0; j < this.cols; j++)
         {
             aux[i, j] = null;
             if (this.specie(this.cell[i, j]) == "Carrot")
             {
                 if (this.surroundingNeighbors(i, j, "Rabbit") == 0)
                 {
                     if (this.cell[i, j].willIAlive())
                     {
                         aux[i, j] = this.cell[i, j];
                     }
                 }
                 else
                 {
                     this.firstRabbit(i, j).eat();
                 }
             }
             else if (this.specie(this.cell[i, j]) == "Rabbit")
             {
                 if (this.cell[i, j].willIAlive())
                 {
                     aux[i, j] = this.cell[i, j];
                 }
             }
             else
             {
                 if (this.cell[i, j] == null)
                 {
                     if (this.surroundingNeighbors(i, j, "Rabbit") >= 2)
                     {
                         aux[i, j] = new Rabbit(i, j, this);
                     }
                     else if (this.surroundingNeighbors(i, j, "Carrot") >= 3)
                     {
                         aux[i, j] = new Carrot(i, j, this);
                     }
                 }
             }
         }
     }
     for (var i = 0; i < this.rows; i++)
     {
         for (var j = 0; j < this.cols; j++)
         {
             this.cell[i, j] = aux[i, j];
         }
     }
 }