Package com.sgfj

Examples of com.sgfj.SGFNode


            }
            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


            }
        }
    }

    private void notifyGameUpdated() {
        SGFNode node = game.kifuLastMove();

        whiteCaps.setText(Integer.toString(game.whiteCaptures));
        blackCaps.setText(Integer.toString(game.blackCaptures));
        moveStatus.setText(game.getFullMoveStatusText());

        String s;
        try {
            s = node.getCommentProperty();
        } catch (SGFException e) {
            s = "";
        }
        comment.setText(s);
    }
View Full Code Here

        sgfPropsForm.append(sgfNodeProps);
        sgfRootProps.setFont(fontPlain());
        sgfRootProps.setLayout(Item.LAYOUT_2 | Item.LAYOUT_EXPAND | Item.LAYOUT_NEWLINE_BEFORE | Item.LAYOUT_NEWLINE_AFTER);
        sgfPropsForm.append(sgfRootProps);

        SGFNode root = game.kifuHead();
        SGFNode node = game.kifuLastMove();

        StringBuffer sb = new StringBuffer();
        for (Enumeration e = root.getProperties(); e.hasMoreElements(); ) {
            SGFProperty p = (SGFProperty) e.nextElement();
            sb.append(p.toString());
            sb.append("\n");
        }
        sgfRootProps.setText(sb.toString());

        sb.setLength(0);
        if (node != root)
            for (Enumeration e = node.getProperties(); e.hasMoreElements(); ) {
                SGFProperty p = (SGFProperty) e.nextElement();
                sb.append(p.toString());
                sb.append("\n");
            }
        sgfNodeProps.setText(sb.toString());
View Full Code Here

        srcForm.setCommandListener(this);

        srcText.setFont(fontPlain());
        srcForm.append(srcText);

        SGFNode root = game.kifuHead();
        try {
            srcText.setText(SGFWriter.toString(root));
        } catch (IOException e) {
            srcText.setText(e.getMessage());
        }
View Full Code Here

        infoText.setFont(fontPlain());
        infoForm.append(infoText);

        StringBuffer sb = new StringBuffer();

        SGFNode root = game.kifuHead();

        for (Enumeration e = root.getProperties(); e.hasMoreElements(); ) {
            SGFProperty p = (SGFProperty) e.nextElement();
            // skip point and comment properties in this screen
            if (!p.name().hasPoint() && p.name() != SGFPropertyName.C) {
                sb.append(p.toString());
                sb.append("\n");
View Full Code Here

import junit.framework.TestCase;

public class SGFNodeIteratorTest extends TestCase {

    public void testWalk() {
        SGFNode n1 = new SGFNode();
        SGFNode n2v1 = new SGFNode();
        SGFNode n2v2 = new SGFNode();
        n1.add(n2v1);
        n1.add(n2v2);

        SGFNodeIterator iterator = n2v2.iterator();
        assertSame(n2v2, iterator.current());
        assertSame(n1, iterator.prev(true));
        assertSame(null, iterator.prev(true));
        assertSame(n2v2, iterator.next(true));
        assertSame(null, iterator.next(true));
View Full Code Here

        assertSame(n2v2, iterator.nextVariant(true));
        assertSame(null, iterator.nextVariant(true));
    }

    public void testWalk2() {
        SGFNode n1 = new SGFNode();
        SGFNode n2v1 = new SGFNode();
        SGFNode n2v2 = new SGFNode();
        SGFNode n3 = new SGFNode();
        n1.add(n2v1);
        n1.add(n2v2);
        n2v1.add(n3);

        SGFNodeIterator it = n1.iterator();
View Full Code Here

                        getWit(sgfp).addMark(WIT.HOSHI);
                }
            setupCells = false;
        }

        SGFNode lastMoveNode = game.kifuLastMove();

        // draw marks from properties
        for (Enumeration e = lastMoveNode.getProperties(); e.hasMoreElements(); ) {
            SGFProperty prop = (SGFProperty) e.nextElement();
            try {
                SGFPoint sgfp = prop.getPoint();
                if (isInView(sgfp)) {
                    WIT wit = getWit(sgfp);
                    if (prop.name() == SGFPropertyName.TR)
                        wit.addMark(WIT.TRIANGLE);
                    else if (prop.name() == SGFPropertyName.SQ)
                        wit.addMark(WIT.SQUARE);
                    else if (prop.name() == SGFPropertyName.CR)
                        wit.addMark(WIT.CIRCLE);
                    else if (prop.name() == SGFPropertyName.MA)
                        wit.addMark(WIT.CROSS);
                    else if (prop.name() == SGFPropertyName.SL)
                        wit.addMark(WIT.SELECTED);
                    else if (prop.name() == SGFPropertyName.DD)
                        wit.addMark(WIT.DIMMED);
                    else if (prop.name() == SGFPropertyName.TW)
                        wit.addMark(WIT.WHITE_TER);
                    else if (prop.name() == SGFPropertyName.TB)
                        wit.addMark(WIT.BLACK_TER);
                    else if (prop.name() == SGFPropertyName.LB)
                        wit.setLabel(prop.getText());
                    else if (prop.name() == SGFPropertyName.VW)
                        wit.addMark(WIT.VIEW);
                }
            } catch (SGFInvalidDataRequestException e1) {
            }
        }

        // mark last move (if not marked in props)
        if (game.lastMove >= 0) {
            SGFPoint sgfp = game.board.xy(game.lastMove);
            if (isInView(sgfp) && (getWit(sgfp).bits & WIT.PURE_MARK) == 0)
                getWit(sgfp).addMark(WIT.CIRCLE);
        }

        // mark next move (if not marked in props)
        if (showNextMove) {
            SGFNodeIterator i = lastMoveNode.iterator();
            if (i.next(true) != null) {
                try {
                    SGFMove m = i.current().getMoveProperty();
                    if (isInView(m) && (getWit(m).bits & WIT.PURE_MARK) == 0)
                        getWit(m).addMark(WIT.CIRCLE);
                } catch (SGFPropertyNotFoundException e) {
                    // DO NOTHING
                }
            }
        }

        // mark ko move (if not marked in props)
        if (game.koMove >= 0) {
            SGFPoint sgfp = game.board.xy(game.koMove);
            if (isInView(sgfp) && (getWit(sgfp).bits & WIT.PURE_MARK) == 0)
                getWit(sgfp).addMark(WIT.SQUARE);
        }

        // mark variations
        if (showVariants) {
            SGFNodeIterator i = lastMoveNode.iterator();
            i.firstVariant(true);
            do {
                SGFNode node = i.current();
                if (node != lastMoveNode)
                    try {
                        SGFMove m = node.getMoveProperty();
                        if (isInView(m))
                            getWit(m).addMark(WIT.VARIANT);
                    } catch (SGFPropertyNotFoundException e) {
                        // DO NOTHING
                    }
            } while (i.nextVariant(true) != null);
        }

        // mark hints
        if (showMoveHints) {
            SGFNodeIterator i = lastMoveNode.iterator();
            if (i.next(true) != null) {
                i.firstVariant(true);
                do {
                    SGFNode node = i.current();
                    try {
                        SGFMove m = node.getMoveProperty();
                        if (isInView(m)) {
                            if ((node.bits & SGFNode.GOOD_MOVE) != 0)
                                getWit(m).addMark(WIT.GOOD_MOVE);
                            else if ((node.bits & SGFNode.BAD_MOVE) != 0)
                                getWit(m).addMark(WIT.BAD_MOVE);
View Full Code Here

    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[Белые]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.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

        if (showMoveStatus)
            moveStatus = game.getFullMoveStatusText();

        if (showMoveStatus && commentLines > 1 || commentLines > 0) {
            SGFNode node = game.kifuLastMove();

            drawSolvedFailedIndicator = showSolvedFailedIndicator;
            goodMove = (node.bits & SGFNode.GOOD_MOVE) != 0;
            drawColorToPlayIndicator = showColorToPlayIndicator;

            // show solve/fail indicator if
            // 1) it's visible
            // 2) it's last node
            //    or no hints for next node
            //    or first fail node we want to see immediately
            // else show color to play indicator

            if (drawSolvedFailedIndicator) {
                SGFNodeIterator nextMoves = node.iterator();
                int bits = 0;
                if (nextMoves.next(true) != null) {
                    nextMoves.firstVariant(true);
                    do {
                        bits |= nextMoves.current().bits;
                    } while (nextMoves.nextVariant(true) != null);
                }

                //#ifdef debug
                System.out.println("Next move bits: " + bits);
                //#endif
                drawSolvedFailedIndicator =
                       ((bits & (SGFNode.GOOD_MOVE | SGFNode.BAD_MOVE)) == 0)
                    || (showFailedImmediately && (bits & SGFNode.BAD_MOVE) != 0);
            }

            try {
                comment = node.getCommentProperty();
            } catch (SGFException e) {
                // DO NOTHING
            }
        }
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.