All MoveGenerators default to 1 move lookahead.
Made MoveGenerators protected for unit testing. Added unit test for some analysis of MoveGenerator speeds. Fixed MDP to consider all states where #turns = maxTurns terminal.
This commit is contained in:
114
test/model/comPlayer/SpeedTest.java
Normal file
114
test/model/comPlayer/SpeedTest.java
Normal file
@@ -0,0 +1,114 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user