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:
Woody Folsom
2012-05-01 22:24:02 -04:00
parent 924780baaf
commit 3ba0db6ebd
12 changed files with 162 additions and 16 deletions

View 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);
}
}