Added PASS.
This commit is contained in:
@@ -22,25 +22,19 @@ public class Action {
|
||||
this.row = row;
|
||||
}
|
||||
|
||||
public static final Action getInstance(/*String playerName,*/ String move) {
|
||||
if (move == null || "NONE".equals(move) || "PASS".equals(move)) {
|
||||
public static final Action getInstance(String move) {
|
||||
if (move == null || "NONE".equals(move)) {
|
||||
throw new IllegalArgumentException("Illegal move: " + move);
|
||||
}
|
||||
|
||||
if ("PASS".equals(move)) {
|
||||
return Action.PASS;
|
||||
}
|
||||
|
||||
if (actionMap.containsKey(move)) {
|
||||
return actionMap.get(move);
|
||||
}
|
||||
|
||||
/*
|
||||
Player player;
|
||||
if ("b".equals(playerName)) {
|
||||
player = Player.BLACK;
|
||||
} else if ("w".equals(playerName)) {
|
||||
player = Player.WHITE;
|
||||
} else {
|
||||
return Action.NONE;
|
||||
}*/
|
||||
|
||||
char col = move.charAt(0);
|
||||
int row = Integer.valueOf(move.substring(1));
|
||||
|
||||
|
||||
@@ -5,6 +5,11 @@ public class GameConfig {
|
||||
private int size;
|
||||
private int timeLimit;
|
||||
|
||||
public GameConfig(int size, double komi) {
|
||||
this(size);
|
||||
this.komi = komi;
|
||||
}
|
||||
|
||||
public GameConfig(int size) {
|
||||
timeLimit = 0;
|
||||
this.size = size;
|
||||
|
||||
@@ -49,19 +49,10 @@ public class GameScore {
|
||||
}
|
||||
|
||||
public boolean isWinner(Player player) {
|
||||
double blackScore = getBlackScore();
|
||||
double whiteScore = getWhiteScore();
|
||||
|
||||
/* This should work but is currently bugged
|
||||
if (Player.WHITE == player) {
|
||||
return getWhiteScore() < normalizedZeroScore;
|
||||
return whiteScore + komi > blackScore;
|
||||
} else {
|
||||
return getBlackScore() > normalizedZeroScore;
|
||||
}*/
|
||||
if (Player.WHITE == player) {
|
||||
return whiteScore > blackScore;
|
||||
} else {
|
||||
return blackScore > whiteScore;
|
||||
return blackScore > whiteScore + komi;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class GoGame implements Runnable {
|
||||
.getName());
|
||||
|
||||
private boolean shutDown = false;
|
||||
private GameConfig gameConfig = new GameConfig(9);
|
||||
private GameConfig gameConfig = new GameConfig(9,7.5);
|
||||
private GameState gameState = new GameState(gameConfig);
|
||||
private GtpClient client = null;
|
||||
private Policy moveGenerator;
|
||||
@@ -80,7 +80,7 @@ public class GoGame implements Runnable {
|
||||
public static void main(String[] args) throws IOException {
|
||||
configureLogging();
|
||||
if (args.length == 0) {
|
||||
Policy defaultMoveGenerator = new MonteCarloUCT(new RandomMovePolicy(), 2000L);
|
||||
Policy defaultMoveGenerator = new MonteCarloUCT(new RandomMovePolicy(), 5000L);
|
||||
LOGGER.info("No MoveGenerator specified. Using default: " + defaultMoveGenerator.toString());
|
||||
|
||||
GoGame goGame = new GoGame(defaultMoveGenerator, PROPS_FILE);
|
||||
@@ -111,7 +111,7 @@ public class GoGame implements Runnable {
|
||||
} else if ("alphabeta".equals(policyName)) {
|
||||
return new AlphaBeta();
|
||||
} else if ("montecarlo".equals(policyName)) {
|
||||
return new MonteCarloUCT(new RandomMovePolicy(), 10000L);
|
||||
return new MonteCarloUCT(new RandomMovePolicy(), 5000L);
|
||||
} else {
|
||||
LOGGER.info("Unable to create Policy for unsupported name: " + policyName);
|
||||
System.exit(INVALID_MOVE_GENERATOR);
|
||||
@@ -136,7 +136,9 @@ public class GoGame implements Runnable {
|
||||
localOutput.println("=\n");
|
||||
break;
|
||||
case final_status_list:
|
||||
LOGGER.info(new StateEvaluator(gameConfig).scoreGame(gameState));
|
||||
System.out.println("Final game score: ");
|
||||
System.out.println(new StateEvaluator(gameConfig).scoreGame(gameState));
|
||||
System.out.println();
|
||||
localOutput.println("=\n");
|
||||
break;
|
||||
case genmove:
|
||||
|
||||
@@ -141,16 +141,16 @@ public class MonteCarloUCT extends MonteCarlo {
|
||||
|
||||
GameScore gameScore = stateEvaluator.scoreGame(rolloutGameState);
|
||||
if (gameScore.isWinner(player)) {
|
||||
System.out.println();
|
||||
System.out.println("Win for " + player + ":\n" + rolloutGameState);
|
||||
System.out.println(gameScore.getScoreReport());
|
||||
System.out.println();
|
||||
//System.out.println();
|
||||
//System.out.println("Win for " + player + ":\n" + rolloutGameState);
|
||||
//System.out.println(gameScore.getScoreReport());
|
||||
//System.out.println();
|
||||
return 1;
|
||||
} else {
|
||||
System.out.println();
|
||||
System.out.println("Loss for " + player + ":\n" + rolloutGameState);
|
||||
System.out.println(gameScore.getScoreReport());
|
||||
System.out.println();
|
||||
//System.out.println();
|
||||
//System.out.println("Loss for " + player + ":\n" + rolloutGameState);
|
||||
//System.out.println(gameScore.getScoreReport());
|
||||
//System.out.println();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user