Пример #1
0
 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();
     }
   }
 }
Пример #2
0
 /**
  * Construct reader and read a game.
  *
  * @param progressShow Callback to show progress, can be null
  */
 public GameReader(File file, ProgressShow progressShow) throws ErrorMessage {
   m_gameFile = new GameFile();
   GameFile.Format format = detectFormat(file);
   m_gameFile.m_file = file;
   m_gameFile.m_format = format;
   InputStream in;
   try {
     in = new FileInputStream(file);
   } catch (FileNotFoundException e) {
     throw new ErrorMessage("File \"" + file + "\"not found");
   }
   switch (format) {
     case XML:
       {
         XmlReader reader = new XmlReader(in, progressShow, file.length());
         m_tree = reader.getTree();
         m_warnings = reader.getWarnings();
       }
       break;
     case SGF:
       {
         SgfReader reader = new SgfReader(in, file, progressShow, file.length());
         m_tree = reader.getTree();
         m_warnings = reader.getWarnings();
       }
       break;
   }
 }