Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $game = $this->getGame($input->getArgument('id'), $input->getOption('storage'));
     $moves = [];
     $moveCalculator = new MoveCalculator();
     foreach ($input->getArgument('moves') as $move) {
         list($from, $to) = explode('->', $move);
         $moves[] = new Move($from, $to);
     }
     $bestMove = MoveRanker::best($moves, $game, $moveCalculator);
     $output->writeln(sprintf('Best move is: %s from %s to %s', $bestMove->getPiece()->getTypeLabel(), $bestMove->getFromLabel(), $bestMove->getToLabel()));
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function doEngineMove(MoveCalculator $moveCalculator)
 {
     $currentPlayer = $this->getCurrentPlayer();
     if ($currentPlayer->isHuman()) {
         throw new \LogicException('Can\\t make an engine-move with a human player');
     }
     $possibleMoves = $moveCalculator->possibleMovesBy($currentPlayer->getColor(), $this->getBoard());
     if (empty($possibleMoves)) {
         throw new \RuntimeException('Failed to find a move for the engine... probably because this scenario wasn\'t worked out yet');
     }
     $highestRankingMove = MoveRanker::best($possibleMoves, $this, $moveCalculator);
     MoveHelper::apply($highestRankingMove, $this);
     $this->addState($this->createStateFromMove($highestRankingMove));
     return $highestRankingMove;
 }