Example #1
0
 /// <summary>
 /// calculate the new generation using the given rules
 /// </summary>
 /// <param name="rules">what rules to use for the calculation</param>
 public void NextGeneration(LifeRules rules)
 {
     bool[,] nextGen = new bool[_width, _height];
     for (int h = 0; h < _height; h++)
     {
         for (int w = 0; w < _width; w++)
         {
             bool[,] neigbors = { { this[h - 1, w - 1], this[h, w - 1], this[h + 1, w - 1] },
                                  { this[h - 1, w],     this[h, w],     this[h + 1, w]     },
                                  { this[h - 1, w + 1], this[h, w + 1], this[h + 1, w + 1] } };
             nextGen[h, w] = rules.IsCellAlive(neigbors);
         }
     }
     SetWorld(nextGen);
 }