0; $isFirstColumn = $cellPosition % $this->columns === 0; $isLastColumn = $cellPosition % $this->columns === $this->columns - 1; for ($i = 0; $i < 8; $i++) { $currentNeighbour = $cellPosition + $this->neighbourCoordinates[$i]; if ($currentNeighbour > 0 && ($currentNeighbour < $this->boardLength) && $this->currentGeneration[$currentNeighbour]->getState()) { if (($isFirstColumn && !in_array($i, [0, 3, 5])) || ($isLastColumn && !in_array($i, [2, 4, 7])) || !($isFirstColumn || $isLastColumn)) { $aliveCount++; } } } if ($cell->getState() && ($aliveCount < 2 || $aliveCount > 3)) { return false; } else if (!$cell->getState() && $aliveCount === 3) { return true; } else { return $cell->getState(); } }