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