Ejemplo n.º 1
0
 private function setNextStatesForDeathCellsInNeigbohrOfLiveCells()
 {
     $cells = $this->desk->getCells();
     foreach ($cells as $cell) {
         $x = $cell->getX();
         $y = $cell->getY();
         foreach ($this->desk->getNeigbohrsCoordinates($x, $y) as $coords) {
             if (!$this->desk->cellExists($coords[0], $coords[1])) {
                 $countOfAliveNeighbors = $this->desk->getCountOfLiveCellsInNeigbohr($coords[0], $coords[1]);
                 $nextStateOfNonExistingCell = $this->rules->getNextState($countOfAliveNeighbors, false);
                 if ($nextStateOfNonExistingCell === true) {
                     $newLiveCell = new \Cell($coords[0], $coords[1], false);
                     $newLiveCell->setNextState($nextStateOfNonExistingCell);
                     $this->desk->addCell($newLiveCell);
                 }
             }
         }
     }
 }