package model.comPlayer; import org.junit.Ignore; import org.junit.Test; import model.Board; import model.Board.TileColor; import model.playerModel.PlayerModel; import model.CellPointer; public class SpeedTest { private static final Board board = new Board(); private static final int nTestRounds = 10; private static final int lookahead = 3; static { board.playTile(new CellPointer(2,2), TileColor.BLUE); } @Test public void testRandom() { long testTime = 0L; RandomComPlayer player = new RandomComPlayer(); PlayerModel model = new PlayerModel("test"); for (int testRound = 0; testRound < nTestRounds; testRound++) { Board newBoard = new Board(board); long testStart = System.currentTimeMillis(); player.getMove(newBoard, model); long testEnd = System.currentTimeMillis(); testTime += testEnd - testStart; } double avgTime = testTime / (nTestRounds * 1000.0); System.out.println("Average time for RandomMoveGenerator.genMove() over " + nTestRounds + " tests: " + avgTime); } @Test public void testMonteCarlo() { long testTime = 0L; MonteCarloComPlayer player = new MonteCarloComPlayer(); player.moveGenerator.setLookahead(lookahead); PlayerModel model = new PlayerModel("test"); for (int testRound = 0; testRound < nTestRounds; testRound++) { Board newBoard = new Board(board); long testStart = System.currentTimeMillis(); player.getMove(newBoard, model); long testEnd = System.currentTimeMillis(); testTime += testEnd - testStart; } double avgTime = testTime / (nTestRounds * 1000.0); System.out.println("Average time for MonteCarloGenerator.genMove() over " + nTestRounds + " tests: " + avgTime); } @Ignore public void testMinimax() { long testTime = 0L; MinimaxComPlayer player = new MinimaxComPlayer(); player.moveGenerator.setLookahead(lookahead); PlayerModel model = new PlayerModel("test"); for (int testRound = 0; testRound < nTestRounds; testRound++) { Board newBoard = new Board(board); long testStart = System.currentTimeMillis(); player.getMove(newBoard, model); long testEnd = System.currentTimeMillis(); testTime += testEnd - testStart; } double avgTime = testTime / (nTestRounds * 1000.0); System.out.println("Average time for MinimaxMoveGenerator.genMove() over " + nTestRounds + " tests: " + avgTime); } @Test public void testAlphaBeta() { long testTime = 0L; AlphaBetaComPlayer player = new AlphaBetaComPlayer(); player.moveGenerator.setLookahead(lookahead); PlayerModel model = new PlayerModel("test"); for (int testRound = 0; testRound < nTestRounds; testRound++) { Board newBoard = new Board(board); long testStart = System.currentTimeMillis(); player.getMove(newBoard, model); long testEnd = System.currentTimeMillis(); testTime += testEnd - testStart; } double avgTime = testTime / (nTestRounds * 1000.0); System.out.println("Average time for AlphaBetaMoveGenerator.genMove() over " + nTestRounds + " tests: " + avgTime); } }