use of suite.uct.UctSearch in project suite by stupidsing.
the class UctWeiqiMain method main.
public static void main(String[] args) {
InputStreamReader isr = new InputStreamReader(System.in, Constants.charset);
BufferedReader br = new BufferedReader(isr);
DecimalFormat df = new DecimalFormat("0.000");
int nThreads = Constants.nThreads;
int nSimulations = 10000 * nThreads;
int boundedTime = 30000;
Weiqi.adjustSize(7);
Board board = new Board();
MovingGameSet gameSet = new MovingGameSet(board, startingPlayer);
boolean auto = false;
boolean quit = false;
String status = "LET'S PLAY!";
while (!quit) {
GameSet gameSet1 = new GameSet(gameSet);
UctVisitor<Coordinate> visitor = UctWeiqi.newVisitor(gameSet1);
UctSearch<Coordinate> search = new UctSearch<>(visitor);
search.setNumberOfThreads(nThreads);
search.setNumberOfSimulations(nSimulations);
search.setBoundedTime(boundedTime);
if (auto || gameSet.getNextPlayer() == computerPlayer) {
System.out.println("THINKING...");
Stopwatch<Coordinate> sw = Stopwatch.of(search::search);
Coordinate coord = sw.result;
if (coord != null) {
status = //
gameSet.getNextPlayer() + " " + //
coord + " " + //
df.format(search.getWinningChance()) + " " + sw.duration + "ms";
gameSet.play(coord);
if (auto)
display(gameSet, status);
} else {
System.out.println("I LOSE");
quit = true;
}
}
while (!auto && !quit && gameSet.getNextPlayer() == humanPlayer) try {
display(gameSet, status);
String line = br.readLine();
if (line != null)
switch(line) {
case "auto":
auto = true;
break;
case "load":
gameSet = loadGameSet(br);
break;
case "undo":
gameSet.undo();
gameSet.undo();
status = "AFTER UNDO:";
break;
default:
if (!String_.isBlank(line)) {
Pair<String, String> pos = String_.split2(line, ",");
int x = Integer.parseInt(pos.t0);
int y = Integer.parseInt(pos.t1);
gameSet.play(Coordinate.c(x, y));
}
}
else
quit = true;
} catch (Exception ex) {
LogUtil.error(ex);
}
}
}
use of suite.uct.UctSearch in project suite by stupidsing.
the class UctTest method testUctGame.
@Test
public void testUctGame() {
new Profiler().profile(() -> {
DecimalFormat df = new DecimalFormat("0.000");
// 20000
int nSimulations = 5000;
int boundedTime = 300000;
int seed = new Random().nextInt();
System.out.println("RANDOM SEED = " + seed);
ShuffleUtil.setSeed(seed);
Board board = new Board();
GameSet gameSet = new GameSet(board, Occupation.BLACK);
while (true) {
GameSet gameSet1 = new GameSet(gameSet);
UctVisitor<Coordinate> visitor = UctWeiqi.newVisitor(gameSet1);
UctSearch<Coordinate> search = new UctSearch<>(visitor);
search.setNumberOfThreads(Constants.nThreads);
search.setNumberOfSimulations(nSimulations);
search.setBoundedTime(boundedTime);
Stopwatch<Coordinate> timed = Stopwatch.of(search::search);
Coordinate move = timed.result;
if (move == null)
break;
Occupation player = gameSet.getNextPlayer();
search.dumpPrincipalVariation();
System.out.println(//
player + " " + //
move + " " + //
df.format(search.getWinningChance()) + " " + timed.duration + "ms");
gameSet.play(move);
UserInterface.display(gameSet);
}
});
}
Aggregations