/** * @param Battlefield $battlefield * * @return Cell[] */ public function chooseCells(Battlefield $battlefield) : array { foreach ($battlefield->getCells() as $cell) { if (!$cell->hasFlag(CellModel::FLAG_DEAD_SHIP) || CellModel::isShipDead($cell)) { continue; } return $this->processor->process($cell, $this->chooseStrategy($cell)); } return []; }
/** * @since 21.0 * * @param Battlefield $battlefield * @param Player $attacker * @param Cell $cell * * @return bool - true if target battlefield do not have any life ships, otherwise false * @throws GameProcessorException */ protected function processPlayerTurnOnBattlefield(Battlefield $battlefield, Player $attacker, Cell $cell) : bool { /** do not process turn on itself */ if ($battlefield->getPlayer() === $attacker) { throw new GameProcessorException('player attacked itself'); } $cell = $this->processPlayerTurn($battlefield, $cell); if (CellModel::isShipDead($cell)) { BattlefieldModel::flagWaterAroundShip($cell); return !BattlefieldModel::hasUnfinishedShips($battlefield); } return false; }