private void checkFile() throws ErrorMessage {
   InputStream in = null;
   try {
     in = new FileInputStream(m_file);
   } catch (FileNotFoundException e) {
     throwError("file not found");
   }
   SgfReader reader = new SgfReader(in, m_file, null, 0);
   GameTree tree = reader.getTree();
   if (tree.getBoardSize() != m_size) throwError("size is not " + m_size);
   ConstNode root = tree.getRoot();
   GoColor toMove = BLACK;
   for (ConstNode node = root; node != null; node = node.getChildConst()) {
     if (node.hasSetup()) {
       if (m_allowSetup) {
         if (node == root) toMove = EMPTY;
         else throw new ErrorMessage("setup stones" + " in non-root position");
       } else throw new ErrorMessage("contains setup stones");
     }
     Move move = node.getMove();
     if (move != null) {
       if (toMove == EMPTY) toMove = move.getColor();
       if (move.getColor() != toMove) throwError("non-alternating moves");
       toMove = toMove.otherColor();
     }
   }
 }
Exemple #2
0
 /** Create a game tree with the current board position as setup stones. */
 public static GameTree makeTreeFromPosition(ConstGameInfo info, ConstBoard board) {
   if (info == null) info = new GameInfo();
   GameTree tree =
       new GameTree(
           board.getSize(),
           info.getKomi(),
           null,
           info.get(StringInfo.RULES),
           info.getTimeSettings());
   Node root = tree.getRoot();
   for (GoPoint p : board) {
     GoColor c = board.getColor(p);
     if (c.isBlackWhite()) root.addStone(c, p);
   }
   root.setPlayer(board.getToMove());
   return tree;
 }