public void TestCalculateMove3PathLength() { HexBoard board = new HexBoard(5); PlayFourMoves(board); // test score at this point PathLengthLoop pathLength = new PathLengthLoop(board); int playerScore = pathLength.PlayerScore(true); Assert.AreEqual(3, playerScore); playerScore = pathLength.PlayerScore(false); Assert.AreEqual(3, playerScore); // no advantage int moveScore = pathLength.SituationScore(); Assert.AreEqual(moveScore, 0); }
public void SpeedTest() { const int RandSeed = 24; const int BoardCount = 100; const int BoardSize = 12; Random rands = new Random(RandSeed); HexBoard[] boards = new HexBoard[BoardCount]; // make some boards for (int loopIndex = 0; loopIndex < BoardCount; loopIndex++) { boards[loopIndex] = RandomBoard(BoardSize, 10 + loopIndex, rands); } // time it the old way DateTime oldStart = DateTime.Now; foreach (HexBoard board in boards) { PathLengthLoop oldPath = new PathLengthLoop(board); oldPath.PlayerScore(true); oldPath.PlayerScore(false); } DateTime oldEnd = DateTime.Now; // and the new way DateTime newStart = DateTime.Now; foreach (HexBoard board in boards) { PathLengthAStar newPath = new PathLengthAStar(board); newPath.PlayerScore(true); newPath.PlayerScore(false); } DateTime newEnd = DateTime.Now; TimeSpan oldDuration = oldEnd - oldStart; TimeSpan newDuration = newEnd - newStart; double ratio = newDuration.Milliseconds / (double)oldDuration.Milliseconds; Assert.IsTrue(ratio < 1.0); }
public void TestCalculateMove3PlayerY() { HexBoard board = new HexBoard(5); PlayFourMoves(board); Minimax minimax = MakeMinimaxForBoard(board); // test score at this point PathLengthLoop pathLength = new PathLengthLoop(board); int playerScore = pathLength.PlayerScore(true); Assert.AreEqual(3, playerScore); playerScore = pathLength.PlayerScore(false); Assert.AreEqual(3, playerScore); MinimaxResult secondPlayerResult = minimax.DoMinimax(4, false); Location secondPlayerExpectedMove = new Location(1, 2); Assert.AreEqual(secondPlayerExpectedMove, secondPlayerResult.Move, "Wrong second player location"); }
private static double GetRatio(int cellFilledCount) { const int RandSeed = 24; const int BoardCount = 50; const int BoardSize = 12; Random rands = new Random(RandSeed + cellFilledCount); HexBoard[] boards = new HexBoard[BoardCount]; // make some boards for (int loopIndex = 0; loopIndex < BoardCount; loopIndex++) { boards[loopIndex] = RandomBoard(BoardSize, cellFilledCount, rands); } // time it the old way DateTime oldStart = DateTime.Now; foreach (HexBoard board in boards) { PathLengthLoop oldPath = new PathLengthLoop(board); oldPath.PlayerScore(true); oldPath.PlayerScore(false); } DateTime oldEnd = DateTime.Now; // and the new way DateTime newStart = DateTime.Now; foreach (HexBoard board in boards) { PathLengthAStar newPath = new PathLengthAStar(board); newPath.PlayerScore(true); newPath.PlayerScore(false); } DateTime newEnd = DateTime.Now; TimeSpan oldDuration = oldEnd - oldStart; TimeSpan newDuration = newEnd - newStart; double ratio = newDuration.Milliseconds / (double)oldDuration.Milliseconds; return ratio; }
private static void CheckPathLength(HexBoard board, int boardIndex) { // first do it with the old path length PathLengthLoop oldPath = new PathLengthLoop(board); int oldX = oldPath.PlayerScore(true); int oldY = oldPath.PlayerScore(false); // now the new PathLengthAStar newPath = new PathLengthAStar(board) { UseNeighbours2 = false }; int newX = newPath.PlayerScore(true); int newY = newPath.PlayerScore(false); Assert.AreEqual(oldX, newX, "X not equal at board index" + boardIndex); Assert.AreEqual(oldY, newY, "Y not equal at board index" + boardIndex); }
public void TestCalculateMove2Situation() { HexBoard board = new HexBoard(3); PlayTwoMoves(board); // test score at this point PathLengthLoop pathLength = new PathLengthLoop(board); int playerScoreX = pathLength.PlayerScore(true); Assert.AreEqual(2, playerScoreX, "playerScoreX"); int playerScoreY = pathLength.PlayerScore(false); Assert.AreEqual(2, playerScoreY, "playerScoreY"); // no advantage int moveScore = pathLength.SituationScore(); Assert.AreEqual(0, moveScore, "moveScore"); }
public void TestCalculateMove4() { HexBoard board = new HexBoard(3); board.PlayMove(0, 0, true); // playerX board.PlayMove(0, 1, false); // PlayerY board.PlayMove(0, 2, true); // playerX board.PlayMove(1, 0, false); // PlayerY board.PlayMove(1, 1, true); // PlayerX board.PlayMove(1, 2, false); // playerY Minimax minimax = MakeMinimaxForBoard(board); // test score at this point PathLengthLoop pathLength = new PathLengthLoop(board); int playerScore = pathLength.PlayerScore(true); Assert.AreEqual(1, playerScore); playerScore = pathLength.PlayerScore(false); Assert.AreEqual(1, playerScore); // only 3 cells are vacant minimax.DoMinimax(1, false); minimax.DoMinimax(1, true); minimax.DoMinimax(2, false); minimax.DoMinimax(2, true); minimax.DoMinimax(3, false); minimax.DoMinimax(3, true); minimax.DoMinimax(4, false); minimax.DoMinimax(4, true); minimax.DoMinimax(5, false); minimax.DoMinimax(5, true); }