/** * @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); }
public static function flagWaterAroundShip(Cell $cell) { $processor = new PathProcessor($cell->getCoordinate()); $battlefield = $cell->getBattlefield(); $cells = $processor->getAdjacentCells($cell->getBattlefield(), 4, CellModel::FLAG_SHIP); $cells[$cell->getCoordinate()] = $cell; foreach ($cells as $cell) { foreach ($processor->reset($cell->getCoordinate())->getAdjacentCells($battlefield, 1, 0, CellModel::FLAG_SHIP) as $waterCell) { CellModel::switchPhase($waterCell, CellModel::FLAG_SKIP); } } }
/** * @see CellModel::switchPhase * @test * * @depends switchPhase */ public function switchPhaseWithAdditionalFlag() { $this->iterateCellFlags([CellModel::FLAG_NONE => CellModel::FLAG_SKIP, CellModel::FLAG_DEAD => CellModel::FLAG_DEAD, CellModel::FLAG_SHIP => CellModel::FLAG_SKIP | CellModel::FLAG_SHIP, CellModel::FLAG_DEAD_SHIP => CellModel::FLAG_DEAD_SHIP, CellModel::FLAG_SKIP => CellModel::FLAG_SKIP], function ($cell) { return CellModel::switchPhase($cell, CellModel::FLAG_SKIP); }); }
/** * @param Battlefield $battlefield * @param Cell $cell - this cell will be attacked if attacker is human * * @return Cell */ protected function processPlayerTurn(Battlefield $battlefield, Cell $cell) : Cell { return PlayerModel::isAIControlled($battlefield->getPlayer()) ? CellModel::switchPhase($cell) : $this->ai->processCPUTurn($battlefield); }