コード例 #1
0
 /**
  * @param string $asciiBoard
  * @param array  $movesAndRanking
  *
  * @dataProvider getRankedMoves()
  */
 public function testRank($asciiBoard, array $movesAndRanking)
 {
     $game = $this->createGameFromAsciiBoard($asciiBoard);
     foreach ($movesAndRanking as $data) {
         list($from, $to, $expectedRanking) = $data;
         $move = new Move($from, $to);
         $actualRanking = $this->moveRanker->rank($move, $game, $this->moveCalculator);
         $this->assertEquals($expectedRanking, $actualRanking, sprintf('Actual ranking should match expected ranking for move from %s to %s', $move->getFromLabel(), $move->getToLabel()));
     }
 }
コード例 #2
0
ファイル: MoveRanker.php プロジェクト: cleentfaar/windmill
 /**
  * @param MoveInterface[]         $moves
  * @param GameInterface           $game
  * @param MoveCalculatorInterface $moveCalculator
  * @param int                     $depth
  *
  * @return MoveInterface
  */
 public static function best(array $moves, GameInterface $game, MoveCalculatorInterface $moveCalculator, $depth = 0)
 {
     $highestRanking = null;
     $highestRankingMove = null;
     foreach ($moves as $move) {
         $ranking = MoveRanker::rank($move, $game, $moveCalculator, $depth);
         if (!isset($highestRanking) || $ranking > $highestRanking) {
             $highestRanking = $ranking;
             $highestRankingMove = $move;
         }
     }
     if ($highestRankingMove === null) {
         throw new \RuntimeException('The highest ranking move should have been determined at this point');
     }
     $highestRankingMove->setRanking($highestRanking);
     return $highestRankingMove;
 }