@Test public void testUctSearch() { GameSet gameSet = new GameSet(new Board(), Occupation.BLACK); gameSet.move(Coordinate.c(3, 3)); Visitor visitor = new Visitor(gameSet); UctSearch<Coordinate> search = new UctSearch<Coordinate>(visitor); search.setNumberOfSimulations(1000); Coordinate bestMove = search.search(); search.dumpSearch(); System.out.println("BEST MOVE = " + bestMove); }
@Test public void testUctGame() { DecimalFormat df = new DecimalFormat("0.000"); int nThreads = 2; int nSimulations = 200; // 20000 int boundedTime = 300000; int seed = new Random().nextInt(); System.out.println("RANDOM SEED = " + seed); RandomList.setSeed(seed); Board board = new Board(); GameSet gameSet = new GameSet(board, Occupation.BLACK); long current = System.currentTimeMillis(); while (true) { Visitor visitor = new Visitor(new GameSet(gameSet)); UctSearch<Coordinate> search = new UctSearch<Coordinate>(visitor); search.setNumberOfThreads(nThreads); search.setNumberOfSimulations(nSimulations); search.setBoundedTime(boundedTime); Coordinate move = search.search(); if (move == null) break; long current0 = current; current = System.currentTimeMillis(); Occupation player = gameSet.getNextPlayer(); search.dumpPrincipalVariation(); System.out.println( player // + " " + move // + " " + df.format(search.getWinningChance()) // + " " + (current - current0) + "ms"); gameSet.move(move); UserInterface.display(gameSet); } }
@Test public void testUctSearchTime() { int nSimulations = 1000; long start = 0, end = 0; for (int time = 0; time < 2; time++) { Board board = new Board(); Visitor visitor = new Visitor(new GameSet(board, Occupation.BLACK)); UctSearch<Coordinate> search = new UctSearch<Coordinate>(visitor); search.setNumberOfSimulations(nSimulations); start = System.currentTimeMillis(); search.search(); end = System.currentTimeMillis(); } float duration = end - start; float ms = duration / nSimulations; System.out.println("UCT: " + ms + "ms/simulation"); }
@Test public void testUctFirstMove() { int seed = 760903274; System.out.println("RANDOM SEED = " + seed); RandomList.setSeed(seed); GameSet gameSet = new GameSet(new Board(), Occupation.BLACK); Visitor visitor = new Visitor(gameSet); UctSearch<Coordinate> search = new UctSearch<Coordinate>(visitor); search.setNumberOfThreads(1); search.setNumberOfSimulations(80000); Coordinate move = search.search(); gameSet.move(move); System.out.println(move); assertTrue(move.getX() >= 2); assertTrue(move.getY() >= 2); assertTrue(move.getX() < Weiqi.size - 2); assertTrue(move.getY() < Weiqi.size - 2); }