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)) {
|
} else if (Player.WHITE.equals(player)) {
|
||||||
return whitePolicy;
|
return whitePolicy;
|
||||||
} else {
|
} 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)) {
|
} else if (Player.WHITE.equals(player)) {
|
||||||
whitePolicy = policy;
|
whitePolicy = policy;
|
||||||
} else {
|
} 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() {
|
public void play() {
|
||||||
System.out.println("Game started.");
|
System.out.println("Game started.");
|
||||||
|
|
||||||
Player currentPlayer = Player.BLACK;
|
// Player currentPlayer = Player.BLACK;
|
||||||
|
|
||||||
|
try {
|
||||||
while (!gameState.isTerminal()) {
|
while (!gameState.isTerminal()) {
|
||||||
System.out.println(gameState);
|
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);
|
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());
|
System.out.println("Game over. Result: " + gameState.getResult());
|
||||||
|
|
||||||
DateFormat dateFormat = new SimpleDateFormat("yyMMddHHmmssZ");
|
DateFormat dateFormat = new SimpleDateFormat("yyMMddHHmmssZ");
|
||||||
|
|
||||||
try {
|
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);
|
FileOutputStream fos = new FileOutputStream(sgfFile);
|
||||||
try {
|
try {
|
||||||
SGFWriter.writeSGF(gameState, fos);
|
SGFWriter.writeSGF(gameState, fos);
|
||||||
System.out.println("Game saved as " + sgfFile.getAbsolutePath());
|
System.out
|
||||||
|
.println("Game saved as " + sgfFile.getAbsolutePath());
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
fos.close();
|
fos.close();
|
||||||
@@ -67,7 +78,8 @@ public class Referee {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException ioe) {
|
} 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.");
|
System.out.println("Game finished.");
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public class StandAloneGame {
|
|||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Policy player1 = new HumanKeyboardInput();
|
Policy player1 = new HumanKeyboardInput();
|
||||||
Policy player2 = new MonteCarloUCT(new RandomMovePolicy(), 5000L);
|
Policy player2 = new MonteCarloUCT(new RandomMovePolicy(), 10000L);
|
||||||
|
|
||||||
Referee referee = new Referee();
|
Referee referee = new Referee();
|
||||||
referee.setPolicy(Player.BLACK, player1);
|
referee.setPolicy(Player.BLACK, player1);
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ public abstract class MonteCarlo implements Policy {
|
|||||||
@Override
|
@Override
|
||||||
public Action getAction(GameConfig gameConfig, GameState gameState,
|
public Action getAction(GameConfig gameConfig, GameState gameState,
|
||||||
Player player) {
|
Player player) {
|
||||||
|
System.out.println(player + " is thinking for up to " + (searchTimeLimit / 1000.0) + " seconds...");
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
if (gameState.getPlayerToMove() != player) {
|
if (gameState.getPlayerToMove() != player) {
|
||||||
|
|||||||
Reference in New Issue
Block a user