示例#1
0
        private static void TestBestMove(HexGame game, int level, Location expectedBestMove)
        {
            Minimax       hexPlayer = new Minimax(game.Board, game.GoodMoves, new CandidateMovesAll());
            MinimaxResult bestMove  = hexPlayer.DoMinimax(level, true);

            // test the location of the move
            Assert.AreEqual(expectedBestMove, bestMove.Move, "Wrong move at level " + level);

            // test the expected score
            if (level >= 3)
            {
                Assert.AreEqual(Occupied.PlayerX, MoveScoreConverter.Winner(bestMove.Score));
            }
        }
        private Location GetBestMove(MinimaxResult playResult)
        {
            Location result = playResult.Move;

            int moveScore = playResult.Score;

            this.IsGameWon = MoveScoreConverter.IsWin(moveScore) && MoveScoreConverter.WinDepth(moveScore) == 1;

            Occupied opponent   = (!this.hexGame.PlayerX).ToPlayer();
            bool     losingMove = MoveScoreConverter.Winner(playResult.Score) == opponent;

            if (losingMove)
            {
                Location losingLocation = this.MakeLosingMove();
                if (losingLocation != Location.Null)
                {
                    result = losingLocation;
                }
            }

            return(result);
        }
示例#3
0
 private static void AssertWinner(int score, Occupied winner)
 {
     Assert.IsTrue(MoveScoreConverter.IsWin(score), "Should have winner");
     Assert.AreEqual(winner, MoveScoreConverter.Winner(score), "Wrong winner");
 }
示例#4
0
 public void NoWinner()
 {
     Assert.AreEqual(Occupied.Empty, MoveScoreConverter.Winner(0));
 }
示例#5
0
        public void WinnerYIsWinner()
        {
            int score = MoveScoreConverter.ConvertWin(Occupied.PlayerY, 1);

            Assert.AreEqual(Occupied.PlayerY, MoveScoreConverter.Winner(score));
        }