Пример #1
0
  /**
   * Test load all sg ffiles.
   *
   * @throws IOException Signals that an I/O exception has occurred.
   */
  public void testLoadAllSGFfiles() throws IOException {
    Stack<String> files = new Stack<String>();
    files.push("sgf/2004-12");
    int count = 0;

    while (files.size() > 0 && count <= 10) {
      String filename = files.pop();
      File file = new File(filename);
      count++;
      if (DEBUG) System.err.println("examining \"" + filename + "\"");
      if (file.exists()) {
        if (!file.isDirectory()) {
          // System.err.println("\"" + filename + "\" is not a
          // directory, parsing as an SGF file");

          Game game = Game.loadFromFile(file);
          if (game.getSize() == 19) {
            Iterator<Move> i = game.getMoves();
            Move move = null;
            BoardI board = new SmallerBoard(game.getSize());
            // System.err.println("board size is: \"" +
            // goGame.getSize()
            // + "\"");
            while (i.hasNext()) {
              move = i.next();
              assertNotNull(move);
              // System.err.print("move: \"" + move + "\"");
              // assertTrue("" + board + "\n" +
              // move.toString(),board.isLegalMove(move));
              board = board.newBoard(move);
              // System.err.println(" board size is: \"" +
              // board.getSize() + "\"");
            }
            // System.err.println();

          }
        } else {
          if (DEBUG) System.err.println("\"" + filename + "\" is a directory");
          if (!file.getName().contains(".svn")) {
            String[] children = file.list();
            for (int i = 0; i < children.length; i++) {
              // System.err.println("pushing \"" + children[i] +
              // "\"");
              files.push(filename + "/" + children[i]);
            }
          }
        }
      }
    }
  }
  private void gamesCsv(Round round) {
    File gamesCSV = new File(names[2]);

    if (gamesCSV.isFile() && gamesCSV.canRead()) {
      gamesCSV.delete();
    }

    if (round.getSize() == 0) {
      return;
    }

    try {
      gamesCSV.createNewFile();

      FileWriter fw = new FileWriter(gamesCSV.getAbsoluteFile());
      BufferedWriter bw = new BufferedWriter(fw);

      bw.write(
          "gameId;gameName;status;gameSize;gameLength;lastTick;"
              + "weatherLocation;weatherDate;logUrl;brokerId;brokerBalance;"
              + separator);

      String tourneyUrl = properties.getProperty("tourneyUrl");
      String baseUrl = properties.getProperty("actionIndex.logUrl", "download?game=%d");
      for (Game game : round.getGameMap().values()) {
        String logUrl = "";
        if (game.isComplete()) {
          if (baseUrl.startsWith("http://")) {
            logUrl = String.format(baseUrl, game.getGameId());
          } else {
            logUrl = tourneyUrl + String.format(baseUrl, game.getGameId());
          }
        }

        String content =
            String.format(
                "%d;%s;%s;%d;%d;%d;%s;%s;%s;",
                game.getGameId(),
                game.getGameName(),
                game.getState(),
                game.getSize(),
                game.getGameLength(),
                game.getLastTick(),
                game.getLocation(),
                game.getSimStartTime(),
                logUrl);
        for (Agent agent : game.getAgentMap().values()) {
          content = String.format("%s%d;%f;", content, agent.getBrokerId(), agent.getBalance());
        }

        bw.write(content + separator);
      }

      bw.close();

      copyFile(gamesCSV, names[3]);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Пример #3
0
  /**
   * Test load simple gnugo.
   *
   * @throws IOException Signals that an I/O exception has occurred.
   */
  public void testLoadSimpleGnugo() throws IOException {

    Game game = Game.loadFromFile(new File("sgf/testing/simpleGnuGo.sgf"));
    Iterator<Move> i = game.getMoves();
    Move move = null;
    BoardI board = new SmallerBoard(game.getSize());
    while (i.hasNext()) {
      move = i.next();
      assertNotNull(move);
      board = board.newBoard(move);
    }
    // System.err.println(g);
  }