public static function isShipDead(Cell $cell) : bool { if (!$cell->hasFlag(static::FLAG_DEAD_SHIP)) { return false; } foreach ((new PathProcessor($cell->getCoordinate()))->getAdjacentCells($cell->getBattlefield(), 4, static::FLAG_SHIP) as $cell) { if (!$cell->hasFlag(static::FLAG_DEAD_SHIP)) { return false; } } return true; }
/** * @param Cell $cell * * @return Cell * @throws AIException */ private static function attackCell(Cell $cell) : Cell { if ($cell->hasFlag(CellModel::FLAG_DEAD)) { throw new AIException("cell: {$cell->getId()} already flagged as *DEAD*"); } return CellModel::switchPhase($cell); }