Package com.sgfj

Examples of com.sgfj.SGFNode


        try {
            String sgf = din.readUTF();

            if (sgf.length() > 0) {
                SGFParser parser = new SGFParser(sgf);
                SGFNode newTree = parser.parse();
                newGame = new DocumentedGame(newTree);

                int depth = din.readShort();
                while (depth-- > 0) {
                    int varNumber = din.readShort();
View Full Code Here


        }
        boolean doPass() {
            return false;
        }
        boolean doUndo() {
            SGFNode lastSetupNode = game.kifuFirstMove(true).iterator().prev(false);
            if (game.kifuLastMove() != lastSetupNode && game.prev()) {
                if (gobanCanvas.showMoveHints) {
                    setCursor(game.kifuLastMove().iterator().next(false));
                } else {
                    if (hasRespondMove && game.kifuLastMove() != lastSetupNode)
View Full Code Here

            }
            return true;
        }
        boolean doRestart() {
            boolean notify = false;
            SGFNode lastSetupNode = game.kifuFirstMove(true).iterator().prev(false);
            while (game.kifuLastMove() != lastSetupNode && game.prev())
                notify = true;
            gobanCanvas.showMoveHints = false;
            //if (notify && gobanCanvas.showMoveHints)
            //    setCursorToNextGoodMove();
View Full Code Here

        while (true) {
            int offset = parser.getCharsConsumed();

            // parse file to get tree
            SGFNode tree = null;
            try {
                tree = parser.parse();
            } catch (SGFEOFException e) {
                // DO NOTHING
                break;
            } catch (SGFParseError e) {
                System.out.println("Parse error " + filePath + ":" + e.getMessage());
                break;
            }
            if (tree == null) {
                System.out.println("Not SGF file or file read error, skip " + filePath + " at " + offset);
                break;
            }

            Problem entry = new Problem();
            entry.path = path;
            entry.subPath = subPath;
            entry.resource = resource;
            entry.offset = offset;

            try {
                entry.genre = tree.getProperty(SGFPropertyName.GE).getText();
            } catch (SGFException e) {
                entry.genre = "undefined";
            }
            int i = genres.indexOf(entry.genre);
            if (i < 0)
                genres.addElement(entry.genre);
            else
                entry.genre = (String)genres.elementAt(i);

            try {
                entry.difficulty = Filter.rank2int(tree.getProperty(SGFPropertyName.DI).getText());
            } catch (SGFException e) {
                entry.difficulty = 0;
            }
            try {
                entry.difficultyP = tree.getProperty(SGFPropertyName.DP).getInt();
            } catch (SGFException e) {
                entry.difficultyP = -1;
            }
            try {
                entry.popularity = tree.getProperty(SGFPropertyName.CO).getInt();
            } catch (SGFException e) {
                entry.popularity = -1;
            }

            entry.tried = 0;
View Full Code Here

            if (fileName.toLowerCase().endsWith(".sgf"))
                try {
                    StringBuffer sb = new StringBuffer();
                    InputStream is = fc.openInputStream();
                    SGFParser parser = new SGFParser(new InputStreamReader(is));
                    SGFNode head = parser.parseHead();
                    is.close();
                    for (Enumeration e = head.getProperties(); e.hasMoreElements(); ) {
                        sb.append(e.nextElement().toString());
                        sb.append("\n");
                    }
                    props.append(new StringItem(T._("SGF Header"), sb.toString()));
                } catch (Exception e) {
View Full Code Here

    }

    public void setHandicap(int handicap) {
        super.setHandicap(handicap);

        SGFNode head = kifu.first(false);
        head.addProperty(new SGFIntProperty(SGFPropertyName.HA, handicap));

        for (int pos = 0; pos < board.maxPos(); pos ++) {
            byte color = board.get(pos);
            if (color != Board.NONE) {
                SGFPropertyName name;
                if (color == Board.WHITE)
                    name = SGFPropertyName.AW;
                else
                    name = SGFPropertyName.AB;
                head.addProperty(new SGFPointProperty(name, board.xy(pos)));
            }
        }
    }
View Full Code Here

                bDead++;
            }
        }
    }

    SGFNode head = kifuHead();
    float komi;
    try {
        komi = head.getProperty(SGFPropertyName.KM).getFloat();
    } catch (Exception e) {
        komi = 0;
    }
    float bScore = bTerr - bCaptured - bDead;
    float wScore = wTerr - wCaptured - wDead + komi;
    float score = bScore - wScore;

    String scoreText;
    if (score == 0)
        scoreText = "Tie";
    else if (score > 0)
        scoreText = "B+" + score;
    else
        scoreText = "W+" + (0.0 - score);
    try {
        String docScore = head.getProperty(SGFPropertyName.RE).getText();
        scoreText += " (" + docScore + ")";
    } catch (Exception e) {
    }

    Score sc = new Score();
View Full Code Here

        else
            super.play(board.pos(move.x, move.y), move.color, allowIllegal);
    }

    protected void playNodeProperties() throws GameOverStoneException {
        SGFNode node = kifu.current();

        for (Enumeration e = node.getProperties(); e.hasMoreElements(); ) {
            SGFProperty prop = (SGFProperty) e.nextElement();
            try {
                if (prop.name() == SGFPropertyName.PL) {
                    char[] t = prop.getText().toCharArray();
                    switch (t[0]) {
View Full Code Here

    }

    public boolean undo() {
        if (!super.undo())
            return false;
        SGFNode node = kifu.current();
        kifu.prev(true);
        node.remove();
        return true;
    }
View Full Code Here

        node.remove();
        return true;
    }

    public boolean next() throws GameException {
        SGFNode node = kifu.next(false);
        if (node == null)
            return false;
        try {
            SGFMove move = node.getMoveProperty();
            boardPlay(move, true);
        } catch (SGFPropertyNotFoundException e) {
            advance();
        }
        kifu.next(true);
View Full Code Here

TOP

Related Classes of com.sgfj.SGFNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.