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); } } }
/** * @since 3.5 * * @param Cell $cell * * @return int */ private function chooseStrategy(Cell $cell) : int { $processor = new PathProcessor($cell->getCoordinate()); $battlefield = $cell->getBattlefield(); foreach (static::$strategyMap as $path => $strategy) { $processor->setPath($path); /** @var Cell $cell */ if (null !== ($cell = $battlefield->getCellByCoordinate($processor->calculateNextCoordinate()))) { if ($cell->hasFlag(CellModel::FLAG_DEAD_SHIP)) { return $strategy; } } } return AIStrategyProcessor::STRATEGY_BOTH; }
/** * @see PathProcessor::reset * @test */ public function reset() { $processor = new PathProcessor('B2'); $processor->setPath(PathProcessor::PATH_DOWN)->calculateNextCoordinate(); $processor->reset('B3'); $this->assertEquals($processor->getCurrentCoordinate(), 'B3'); $this->assertEquals($processor->getCurrentCoordinate(), $processor->getOriginCoordinate()); }