Files
cs6601p1/src/net/woodyfolsom/msproj/GameScore.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

73 lines
1.8 KiB
Java

package net.woodyfolsom.msproj;
public class GameScore {
public static final int NORMALIZED_ZERO_SCORE = 379;
private double komi;
private int blackScore;
private int whiteScore;
public GameScore(int blackScore, int whiteScore, double komi) {
this.blackScore = blackScore;
this.komi = komi;
this.whiteScore = whiteScore;
}
public double getBlackScore() {
return (double)blackScore - komi;
}
/**
* Gets a representation for the game score as an integer. Lower numbers are better for white.
* The minimum value is 0 (Chinese scoring - white owns every intersection on 19x19 and has 9 stone komi).
* Likewise, the maximum value if 379x2 (black owns every intersection with zero komi).
* @return
*/
public int getAggregateScore() {
return NORMALIZED_ZERO_SCORE + 2 * blackScore - ((int)(2 * (whiteScore + komi)));
}
public double getScore(Player color) {
if (color == Player.BLACK) {
return getBlackScore();
} else if (color == Player.WHITE) {
return getWhiteScore();
} else {
return 0.0;
}
}
public double getWhiteScore() {
return (double)whiteScore + komi;
}
public boolean isWinner(String color) {
if ("w".equals(color)) {
return getWhiteScore() < NORMALIZED_ZERO_SCORE;
} else {
return getBlackScore() > NORMALIZED_ZERO_SCORE;
}
}
public String toString() {
return "B: " + blackScore + "W: "+ whiteScore+"K:" + komi;
}
public String getScoreReport() {
double blackScore = getBlackScore();
double whiteScore = getWhiteScore();
boolean gameTied = Math.abs(blackScore - whiteScore) < 0.5;
if (gameTied) {
return "Black +0 (tie)";
} else if (blackScore > whiteScore) {
return "Black +"
+ (blackScore - whiteScore - komi);
} else {
return "White +"
+ (whiteScore + komi - blackScore);
}
}
}