Package com.sgfj

Examples of com.sgfj.SGFNode


        }
    }

    public void testWriteSynth() {
        try {
            SGFNode root = new SGFNode();
            root.addProperty(new SGFIntProperty(SGFPropertyName.SZ, 9));
            root.addProperty(new SGFIntProperty(SGFPropertyName.HA, 0));

            SGFNode n;
            String s;

            n = new SGFNode();
            n.addMoveProperty(new SGFMove(0, 0, SGFMove.BLACK));
            root.add(n);
            s = SGFWriter.toString(root);
            assertEquals("(;SZ[9]HA[0];B[aa])", s);

            n = new SGFNode();
            n.addMoveProperty(new SGFMove(1, 1, SGFMove.WHITE));
            root.add(n);
            s = SGFWriter.toString(root);
            assertEquals("(;SZ[9]HA[0](;B[aa])(;W[bb]))", s);
        } catch (IOException e) {
            e.printStackTrace();
View Full Code Here


        while (ni.prev(false) != null) {
            moves.push(ni.current());
            ni.prev(true);
        }

        SGFNode head = ni.current();
        kifu = current.iterator();

        // Read size and init board
        int size;
        try {
            size = head.getProperty(SGFPropertyName.SZ).getInt();
        } catch (SGFPropertyNotFoundException e) {
            size = 19;
        }
        super.init(size);

        // Read handicap property, stones added with AW/AB
        try {
            handicap  = head.getProperty(SGFPropertyName.HA).getInt();
        } catch (SGFPropertyNotFoundException e) {
            handicap = 0;
        }

        playNodeProperties();

        // Find color to play for first nodes without move
        do {
            try {
                byte color = ni.current().getMoveProperty().color;
                if (color != Board.NONE) {
                    colorToPlay = color;
                    break;
                }
            } catch (SGFPropertyNotFoundException e) {
            }
        } while (ni.next(true) != null);

        // Play moves from head to provided node
        while (!moves.empty()) {
            SGFNode node = (SGFNode) moves.pop();
            try {
                SGFMove move = node.getMoveProperty();
                boardPlay(move, true);
            } catch (SGFPropertyNotFoundException e) {
                advance();
            }
            playNodeProperties();
View Full Code Here

        }
    }

    public void init(int size) {
        super.init(size);
        SGFNode head = new SGFNode();
        head.addProperty(new SGFIntProperty(SGFPropertyName.GM, 1));
        head.addProperty(new SGFIntProperty(SGFPropertyName.FF, 4));
        head.addProperty(new SGFTextProperty(SGFPropertyName.CA, charset.toCharArray()));
        head.addProperty(new SGFTextProperty(SGFPropertyName.AP, application.toCharArray()));
        head.addProperty(new SGFIntProperty(SGFPropertyName.SZ, size));
        kifu = head.iterator();
    }
View Full Code Here

        kifu = head.iterator();
    }

    public void init(int size, float komi, String ruleSet, String white, String black) {
        init(size);
        SGFNode head = kifuHead();
        head.addProperty(new SGFFloatProperty(SGFPropertyName.KM, komi));
        head.addProperty(new SGFTextProperty(SGFPropertyName.RU, ruleSet.toCharArray()));
        head.addProperty(new SGFTextProperty(SGFPropertyName.PW, white.toCharArray()));
        head.addProperty(new SGFTextProperty(SGFPropertyName.PB, black.toCharArray()));
    }
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

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.