/** * @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()); }