Added feedback when computer is thinking is StandAloneGame mode.
This commit is contained in:
@@ -21,7 +21,8 @@ public class Referee {
|
||||
} else if (Player.WHITE.equals(player)) {
|
||||
return whitePolicy;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Player must be one of {Player.WHITE, Player.BLACK}.");
|
||||
throw new IllegalArgumentException(
|
||||
"Player must be one of {Player.WHITE, Player.BLACK}.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,34 +32,44 @@ public class Referee {
|
||||
} else if (Player.WHITE.equals(player)) {
|
||||
whitePolicy = policy;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Player must be one of {Player.WHITE, Player.BLACK}.");
|
||||
throw new IllegalArgumentException(
|
||||
"Player must be one of {Player.WHITE, Player.BLACK}.");
|
||||
}
|
||||
}
|
||||
|
||||
public void play() {
|
||||
System.out.println("Game started.");
|
||||
|
||||
Player currentPlayer = Player.BLACK;
|
||||
// Player currentPlayer = Player.BLACK;
|
||||
|
||||
try {
|
||||
while (!gameState.isTerminal()) {
|
||||
System.out.println(gameState);
|
||||
|
||||
Action action = getPolicy(currentPlayer).getAction(gameConfig, gameState, currentPlayer);
|
||||
Player currentPlayer = gameState.getPlayerToMove();
|
||||
Action action = getPolicy(currentPlayer).getAction(gameConfig,
|
||||
gameState, currentPlayer);
|
||||
gameState.playStone(currentPlayer, action);
|
||||
currentPlayer = GoGame.getNextPlayer(currentPlayer);
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
System.out
|
||||
.println("Game halted early due to the following Exception:");
|
||||
ex.printStackTrace();
|
||||
return;
|
||||
}
|
||||
System.out.println("Game over. Result: " + gameState.getResult());
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyMMddHHmmssZ");
|
||||
|
||||
try {
|
||||
|
||||
File sgfFile = new File("gogame-" + dateFormat.format(new Date())+ ".sgf");
|
||||
File sgfFile = new File("gogame-" + dateFormat.format(new Date())
|
||||
+ ".sgf");
|
||||
FileOutputStream fos = new FileOutputStream(sgfFile);
|
||||
try {
|
||||
SGFWriter.writeSGF(gameState, fos);
|
||||
System.out.println("Game saved as " + sgfFile.getAbsolutePath());
|
||||
System.out
|
||||
.println("Game saved as " + sgfFile.getAbsolutePath());
|
||||
} finally {
|
||||
try {
|
||||
fos.close();
|
||||
@@ -67,7 +78,8 @@ public class Referee {
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
System.out.println("Unable to save game file due to IOException: " + ioe.getMessage());
|
||||
System.out.println("Unable to save game file due to IOException: "
|
||||
+ ioe.getMessage());
|
||||
}
|
||||
|
||||
System.out.println("Game finished.");
|
||||
|
||||
@@ -12,7 +12,7 @@ public class StandAloneGame {
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Policy player1 = new HumanKeyboardInput();
|
||||
Policy player2 = new MonteCarloUCT(new RandomMovePolicy(), 5000L);
|
||||
Policy player2 = new MonteCarloUCT(new RandomMovePolicy(), 10000L);
|
||||
|
||||
Referee referee = new Referee();
|
||||
referee.setPolicy(Player.BLACK, player1);
|
||||
|
||||
@@ -35,6 +35,7 @@ public abstract class MonteCarlo implements Policy {
|
||||
@Override
|
||||
public Action getAction(GameConfig gameConfig, GameState gameState,
|
||||
Player player) {
|
||||
System.out.println(player + " is thinking for up to " + (searchTimeLimit / 1000.0) + " seconds...");
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
if (gameState.getPlayerToMove() != player) {
|
||||
|
||||
Reference in New Issue
Block a user