Substantial refactoring to implement correct Naive, UCT Monte Carlo tree search methods.

Removed unnecessary distinction between policy and tree search (tree search is a special kind of policy).
Calculation of all valid moves / arbitrary sets of moves is now a seperate class, as it serves a different purpose than a policy.
Introduced regression error in AlphaBeta test.
This commit is contained in:
cs6601
2012-08-28 10:40:37 -04:00
parent 36291171e5
commit bb5990a04f
39 changed files with 550 additions and 431 deletions

View File

@@ -0,0 +1,65 @@
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(String color) {
if ("w".equals(color)) {
return getWhiteScore();
} else if ("b".equals(color)) {
return getBlackScore();
} else {
return 0.0;
}
}
public double getWhiteScore() {
return (double)whiteScore + komi;
}
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);
}
}
}