Files
cs6601p1/test/net/woodyfolsom/msproj/StateEvaluatorTest.java
cs6601 2e40440838 Refactoring in progress.
Player and Action classes are now singletons (factory pattern) rather than String values.
Implementing more general treesearch code for minimax, alpha-beta, monte carlo using simplified backup logic.
2012-08-30 08:41:03 -04:00

98 lines
3.1 KiB
Java

package net.woodyfolsom.msproj;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class StateEvaluatorTest {
GameConfig gameConfig = new GameConfig();
@Test
public void testScoreEmptyBoard() {
GameState gameState = new GameState(5);
GameScore gameScore = new StateEvaluator(gameConfig)
.scoreGame(gameState);
assertEquals(0.0, gameScore.getWhiteScore(), 0.5);
assertEquals(0.0, gameScore.getBlackScore(), 0.5);
}
@Test
public void testScoreFirstMove() {
GameState gameState = new GameState(5);
gameState.playStone(Player.BLACK, Action.getInstance("B3"));
GameScore gameScore = new StateEvaluator(gameConfig)
.scoreGame(gameState);
System.out.println(gameScore.getScoreReport());
assertEquals(0.0, gameScore.getWhiteScore(), 0.5);
assertEquals(25.0, gameScore.getBlackScore(), 0.5);
}
@Test
public void testScoreTiedAtMove2() {
GameState gameState = new GameState(5);
gameState.playStone(Player.BLACK, Action.getInstance("B3"));
gameState.playStone(Player.WHITE, Action.getInstance("A1"));
GameScore gameScore = new StateEvaluator(gameConfig)
.scoreGame(gameState);
System.out.println(gameScore.getScoreReport());
assertEquals(1.0, gameScore.getWhiteScore(), 0.5);
assertEquals(1.0, gameScore.getBlackScore(), 0.5);
}
@Test
public void testScoreTerritory() {
GameState gameState = new GameState(5);
gameState.playStone(Player.BLACK, Action.getInstance("A2"));
gameState.playStone(Player.BLACK, Action.getInstance("B3"));
gameState.playStone(Player.BLACK, Action.getInstance("C2"));
gameState.playStone(Player.BLACK, Action.getInstance("B1"));
gameState.playStone(Player.WHITE, Action.getInstance("E5"));
System.out.println(gameState);
GameScore gameScore = new StateEvaluator(gameConfig)
.scoreGame(gameState);
System.out.println(gameScore.getScoreReport());
assertEquals(1.0, gameScore.getWhiteScore(), 0.5);
assertEquals(6.0, gameScore.getBlackScore(), 0.5);
// Black should be up by 5 if Black's territory at A1 & B2 is scored
// correctly.
}
@Test
public void testCaptureAggScore() {
GameState gameState = new GameState(9);
gameState.playStone(Player.WHITE, Action.getInstance("A2"));
gameState.playStone(Player.WHITE, Action.getInstance("B1"));
gameState.playStone(Player.WHITE, Action.getInstance("C2"));
gameState.playStone(Player.BLACK, Action.getInstance("B2"));
GameState moveToA1 = new GameState(gameState);
GameState capAtB3 = new GameState(gameState);
moveToA1.playStone(Player.WHITE, Action.getInstance("A1"));
capAtB3.playStone(Player.WHITE, Action.getInstance("B3"));
System.out.println(moveToA1);
System.out.println(capAtB3);
StateEvaluator eval = new StateEvaluator(new GameConfig());
int scoreA1 = eval.scoreGame(moveToA1).getAggregateScore();
int scoreB3 = eval.scoreGame(capAtB3).getAggregateScore();
System.out.println("Score at A1: " + scoreA1);
System.out.println("Score at B3: " + scoreB3);
// moving as white, lower is better
assertTrue(scoreA1 > scoreB3);
}
}