From def3b5979b4fbf51e1e5baabb574625a2b1e98d1 Mon Sep 17 00:00:00 2001 From: Woody Folsom Date: Wed, 26 Sep 2012 12:01:09 -0400 Subject: [PATCH] Added PASS. --- src/net/woodyfolsom/msproj/Action.java | 18 ++++++------------ src/net/woodyfolsom/msproj/GameConfig.java | 5 +++++ src/net/woodyfolsom/msproj/GameScore.java | 13 ++----------- src/net/woodyfolsom/msproj/GoGame.java | 10 ++++++---- .../msproj/policy/MonteCarloUCT.java | 16 ++++++++-------- 5 files changed, 27 insertions(+), 35 deletions(-) diff --git a/src/net/woodyfolsom/msproj/Action.java b/src/net/woodyfolsom/msproj/Action.java index 8bdde8f..3f1f7cd 100644 --- a/src/net/woodyfolsom/msproj/Action.java +++ b/src/net/woodyfolsom/msproj/Action.java @@ -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)); diff --git a/src/net/woodyfolsom/msproj/GameConfig.java b/src/net/woodyfolsom/msproj/GameConfig.java index d4d7d61..761f8ae 100644 --- a/src/net/woodyfolsom/msproj/GameConfig.java +++ b/src/net/woodyfolsom/msproj/GameConfig.java @@ -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; diff --git a/src/net/woodyfolsom/msproj/GameScore.java b/src/net/woodyfolsom/msproj/GameScore.java index e7557a9..1515f0e 100644 --- a/src/net/woodyfolsom/msproj/GameScore.java +++ b/src/net/woodyfolsom/msproj/GameScore.java @@ -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; } } diff --git a/src/net/woodyfolsom/msproj/GoGame.java b/src/net/woodyfolsom/msproj/GoGame.java index 2dc2c42..a1646e1 100644 --- a/src/net/woodyfolsom/msproj/GoGame.java +++ b/src/net/woodyfolsom/msproj/GoGame.java @@ -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: diff --git a/src/net/woodyfolsom/msproj/policy/MonteCarloUCT.java b/src/net/woodyfolsom/msproj/policy/MonteCarloUCT.java index 11d6458..1418ba7 100644 --- a/src/net/woodyfolsom/msproj/policy/MonteCarloUCT.java +++ b/src/net/woodyfolsom/msproj/policy/MonteCarloUCT.java @@ -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; } }