Examples of SGFParser


Examples of com.sgfj.SGFParser

    }

    public void testParseHead() {
        try {
            String data = "(;GM[1]FF[4]CA[UTF-8]AP[CGoban:3]ST[2]RU[Japanese]SZ[9]HA[3]KM[5.50]PW[Белые]PB[Черные]AB[gc][cg][gg];W[ed]CR[ee]TR[cc][gc](;B[ec]CR[ec]LB[dd:A])(;B[eg]CR[eg];W[];B[ge]))";
            SGFParser reader = new SGFParser(data);
            SGFNode tree = reader.parseHead();
            assertNotNull("Emty tree received.", tree);

            assertNull(tree.iterator().next(false));
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

Examples of com.sgfj.SGFParser

    }

    public void testParseUnicode() {
        try {
            String data = "(;GM[1]FF[4]CA[UTF-8]AP[CGoban:3]ST[2]RU[Japanese]PW[\u0403\u0490\u00ab\u043b\u0490])";
            SGFParser reader = new SGFParser(data);
            SGFNode tree = reader.parseHead();
            assertNotNull("Emty tree received.", tree);

            assertNull(tree.iterator().next(false));
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

Examples of com.sgfj.SGFParser

    /* (non-Javadoc)
     * @see junit.framework.TestCase#setUp()
     */
    protected void setUp() throws Exception {
        super.setUp();
        SGFParser reader = new SGFParser(moveData);
        tree = reader.parse();
        assertNotNull("Emty tree received.", tree);
    }
View Full Code Here

Examples of com.sgfj.SGFParser

public class SGFWriterTest extends TestCase {

    public void testWrite() {
        try {
            String data = "(;GM[1]FF[4]CA[UTF-8]AP[CGoban:3]ST[2]RU[Japanese]SZ[9]HA[3]KM[5.50]PW[White]PB[Black]AB[gc][cg][gg];W[ed]CR[ee]TR[cc][gc](;B[ec]CR[ec]LB[dd:A])(;B[eg]CR[eg];W[];B[ge]))";
            SGFParser reader = new SGFParser(data);
            SGFNode tree = reader.parse();
            assertNotNull("Emty tree received.", tree);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            OutputStreamWriter w = new OutputStreamWriter(baos);
            SGFWriter.write(w, tree);
            w.close();

            //System.out.println(baos.toString());
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            reader = new SGFParser(new InputStreamReader(bais));
            SGFNode tree2 = reader.parse();

            assertEquals(tree, tree2);
            assertEquals(SGFWriter.toString(tree), SGFWriter.toString(tree2));
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

Examples of com.sgfj.SGFParser

        return loadGame(is, 0);
    }

    public DocumentedGame loadGame(InputStream is, int offset) throws Exception {
        is.skip(offset);
        SGFParser parser = new SGFParser(new InputStreamReader(is));
        SGFNode newTree = parser.parse();
        is.close();

/*    SGFCup parser = new SGFCup(new SGFLex(isr));
        parser.tree = new SGFTree(2048);
        try {
View Full Code Here

Examples of com.sgfj.SGFParser

        DocumentedGame newGame = null;
        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

Examples of com.sgfj.SGFParser

            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");
                    }
View Full Code Here

Examples of com.sgfj.SGFParser

        } else {
            path = topDir;
            subPath = filePath.substring(topDir.length());
        }

        SGFParser parser = new SGFParser(new InputStreamReader(is));

        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());
View Full Code Here

Examples of com.sgfj.SGFParser

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

Examples of com.sgfj.SGFParser

            if (fileName.toLowerCase().endsWith(".sgf"))
                try {
                    StringBuffer sb = new StringBuffer();
                    InputStream is = fc.openInputStream();
                    InputStreamReader isr = new InputStreamReader(is);
                    SGFParser parser = new SGFParser(isr);
                    SGFNode head = parser.parseHead();
                    is.close();
                    for (Enumeration e = head.getProperties(); e.hasMoreElements(); ) {
                        sb.append(e.nextElement().toString());
                        sb.append("\n");
                    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.