コード例 #1
0
 /**
  * @param int   $colorToMove
  * @param Board $board
  *
  * @return array
  */
 private function getSimplifiedActualMoves($colorToMove, Board $board)
 {
     $moves = [];
     $moveCalculator = new MoveCalculator();
     foreach ($moveCalculator->possibleMovesBy($colorToMove, $board) as $actualMove) {
         $moves[] = [$actualMove->getFrom(), $actualMove->getTo()];
     }
     return $moves;
 }
コード例 #2
0
ファイル: Game.php プロジェクト: cleentfaar/windmill
 /**
  * {@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;
 }