Consolidated StateEvaluator class into GameState.getResult(). Fixed some issues with komi and normalized score calculation.
This commit is contained in:
@@ -54,8 +54,7 @@ public class CaptureTest {
|
||||
|
||||
System.out.println(gameState);
|
||||
|
||||
GameScore gameScore = new StateEvaluator(gameConfig).scoreGame(gameState);
|
||||
System.out.println(gameScore.getScoreReport());
|
||||
System.out.println(gameState.getResult());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.woodyfolsom.msproj;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import net.woodyfolsom.msproj.GameScore;
|
||||
import net.woodyfolsom.msproj.GameResult;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -10,19 +10,19 @@ public class GameScoreTest {
|
||||
|
||||
@Test
|
||||
public void testGetAggregateScoreZero() {
|
||||
GameScore gameScore = new GameScore(0,0,19,0);
|
||||
assertEquals(gameScore.getNormalizedZeroScore(), gameScore.getAggregateScore());
|
||||
GameResult gameScore = new GameResult(0,0,19,0, true);
|
||||
assertEquals(gameScore.getNormalizedZeroScore(), gameScore.getNormalizedScore());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAggregateScoreBlackWinsNoKomi() {
|
||||
GameScore gameScore = new GameScore(25,2,19,0);
|
||||
assertEquals(425, gameScore.getAggregateScore());
|
||||
GameResult gameScore = new GameResult(25,2,19,0, true);
|
||||
assertEquals(407, gameScore.getNormalizedScore());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAggregateScoreWhiteWinsWithKomi() {
|
||||
GameScore gameScore = new GameScore(10,12,19,6.5);
|
||||
assertEquals(362, gameScore.getAggregateScore());
|
||||
GameResult gameScore = new GameResult(10,12,19,6.5, true);
|
||||
assertEquals(357, gameScore.getNormalizedScore());
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
package net.woodyfolsom.msproj;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class StateEvaluatorTest {
|
||||
|
||||
@Test
|
||||
public void testScoreEmptyBoard() {
|
||||
GameConfig gameConfig = new GameConfig(5);
|
||||
GameState gameState = new GameState(gameConfig);
|
||||
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() {
|
||||
GameConfig gameConfig = new GameConfig(5);
|
||||
GameState gameState = new GameState(gameConfig);
|
||||
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() {
|
||||
GameConfig gameConfig = new GameConfig(5);
|
||||
GameState gameState = new GameState(gameConfig);
|
||||
|
||||
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() {
|
||||
GameConfig gameConfig = new GameConfig(5);
|
||||
GameState gameState = new GameState(gameConfig);
|
||||
|
||||
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() {
|
||||
GameConfig gameConfig = new GameConfig(9);
|
||||
GameState gameState = new GameState(gameConfig);
|
||||
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(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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user