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); }
private static void AssertWinner(int score, Occupied winner) { Assert.IsTrue(MoveScoreConverter.IsWin(score), "Should have winner"); Assert.AreEqual(winner, MoveScoreConverter.Winner(score), "Wrong winner"); }
public void NoWinner() { Assert.AreEqual(Occupied.Empty, MoveScoreConverter.Winner(0)); }
public void WinnerYIsWinner() { int score = MoveScoreConverter.ConvertWin(Occupied.PlayerY, 1); Assert.AreEqual(Occupied.PlayerY, MoveScoreConverter.Winner(score)); }