Example #1
0
 public static void main(String[] args) {
   RandomList r = new RandomList(RandomList.FillType.fillInt, 10);
   List l = r.fill();
   sort_az(l);
   System.out.println(l);
   sort_za(l);
   System.out.println(l);
 }
Example #2
0
 public static void main(String[] args) {
   RandomList<String> rs = new RandomList<String>();
   for (String s : ("lla asssa aa asa saa saa s asas").split(" ")) {
     rs.add(s);
   }
   for (int i = 0; i < rs.size(); i++) {
     System.out.println(rs.select());
   }
 }
Example #3
0
  static Collection<EndPoint> randomEndPoints(Node caller, int total) {

    Set<EndPoint> res = new HashSet<EndPoint>();

    if (seeds.isEmpty()) res.add(nodes.randomElement().endpoint);
    else
      while (res.size() < Math.min(total, seeds.size())) {
        res.add(seeds.randomElement().endpoint);
      }

    seeds.add(caller);
    return res;
  }
Example #4
0
 static void dispose(Node n) {
   if (n != null) {
     seeds.remove(n);
     nodes.remove(n);
     n.dispose();
   }
 }
Example #5
0
  @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);
    }
  }
Example #6
0
  @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);
  }
Example #7
0
 static Node randomNode() {
   return nodes.randomElement();
 }
Example #8
0
 static int size() {
   return nodes.size();
 }
Example #9
0
 static void store(Node n) {
   nodes.add(n);
 }