Package com.sgfj

Examples of com.sgfj.SGFNodeIterator


            dout.writeUTF(sgfText);

            if (sgfText.length() > 0) {
                Stack variants = new Stack();
                int depth = 0;
                SGFNodeIterator i = game.kifuLastMove().iterator();
                do {
                    SGFNodeIterator ii = i.current().iterator();
                    int varNumber = 0;
                    while (ii.prevVariant(true) != null)
                        varNumber++;
                    variants.push(new Integer(varNumber));
                    depth++;
                } while (i.prev(true) != null);
                dout.writeShort(depth);
View Full Code Here


                case Canvas.KEY_NUM6:
                    notify |= game.next();
                    break;
                case Canvas.KEY_NUM7:
                    {
                        SGFNodeIterator i = game.kifuLastMove().iterator();
                        // skip to node with some variants
                        while (i.prev(true) != null
                                && i.nextVariant(false) == null
                                && i.prevVariant(false) == null)
                            // DO NOTHING
                            ;
                        if (!(i.nextVariant(false) == null && i.prevVariant(false) == null)
                                && i.current() != game.kifuLastMove()) {
                            // play game to found node
                            while (i.current() != game.kifuLastMove())
                                game.prev();
                            notify = true;
                        }
                    }
                    break;
                case Canvas.KEY_NUM8:
                    notify |= game.nextVariant();
                    break;
                case Canvas.KEY_NUM9:
                    {
                        SGFNodeIterator i = game.kifuLastMove().iterator();
                        // skip to node with some variants
                        while (i.next(true) != null
                                && i.nextVariant(false) == null
                                && i.prevVariant(false) == null)
                            // DO NOTHING
                            ;
                        if (!(i.nextVariant(false) == null && i.prevVariant(false) == null)
                                && i.current() != game.kifuLastMove()) {
                            // play game to found node
                            while (i.current() != game.kifuLastMove())
                                game.next();
                            notify = true;
                        }
                    }
                    break;
View Full Code Here

        // TODO: not passing
        try {
            String data = "(;SZ[19](;B[da]C[RIGHT];W[ab])(;B[ad]))";
            SGFParser parser = new SGFParser(data);
            SGFNode tree = parser.parseProblem();
            SGFNodeIterator i = tree.iterator();
            SGFNode node = i.current();
            assertTrue((node.bits & SGFNode.GOOD_MOVE) != 0 && (node.bits & SGFNode.BAD_MOVE) != 0);
            node = i.next(true);
            assertTrue((node.bits & SGFNode.GOOD_MOVE) != 0 && (node.bits & SGFNode.BAD_MOVE) == 0);
            node = i.nextVariant(false);
            assertTrue((node.bits & SGFNode.GOOD_MOVE) == 0 && (node.bits & SGFNode.BAD_MOVE) != 0);
            node = i.next(true);
            assertTrue((node.bits & SGFNode.GOOD_MOVE) != 0 && (node.bits & SGFNode.BAD_MOVE) == 0);
            node = i.next(true);
            assertTrue((node.bits & SGFNode.GOOD_MOVE) != 0 && (node.bits & SGFNode.BAD_MOVE) == 0);
        } catch (Exception e) {
            e.printStackTrace();
            fail("Unexpected!");
        }
View Full Code Here

        try {
            SGFParser reader = new SGFParser(problemData);
            SGFNode tree = reader.parseProblem();
            assertNotNull("Emty tree received.", tree);

            SGFNodeIterator i = tree.iterator();
            SGFNode node;
            node = i.next(true);
            assertTrue((node.bits & SGFNode.GOOD_MOVE) != 0 && (node.bits & SGFNode.BAD_MOVE) == 0);
            node = i.nextVariant(false);
            assertTrue((node.bits & SGFNode.GOOD_MOVE) == 0 && (node.bits & SGFNode.BAD_MOVE) != 0);
            node = i.next(true);
            assertTrue((node.bits & SGFNode.GOOD_MOVE) != 0 && (node.bits & SGFNode.BAD_MOVE) == 0);
            node = i.nextVariant(true);
            assertTrue((node.bits & SGFNode.GOOD_MOVE) == 0 && (node.bits & SGFNode.BAD_MOVE) != 0);
            node = i.nextVariant(true);
            assertTrue((node.bits & SGFNode.GOOD_MOVE) == 0 && (node.bits & SGFNode.BAD_MOVE) != 0);

        } catch (Exception e) {
            e.printStackTrace();
            fail("No exceptions are expected.");
View Full Code Here

    }

    public void testGetMove() {
        try {
            setUp();
            SGFNodeIterator i = tree.iterator();
            assertEquals(new SGFMove(16, 3, SGFMove.BLACK), i.next(true).getMoveProperty());
            assertEquals(new SGFMove(14, 15, SGFMove.WHITE), i.next(true).getMoveProperty());
            assertEquals(null, i.next(true));
        } catch (Exception e) {
            e.printStackTrace();
            fail("No exceptions are expected.");
        }
    }
View Full Code Here

        SGFMove m3 = new SGFMove(1, 0, SGFMove.BLACK);
        root.play(m1);
        root.iterator().next(false).play(m2);
        root.iterator().next(false).play(m3);
        root.iterator().next(false).play(m2);
        SGFNodeIterator it = root.iterator();
        try {
            assertEquals(m1, it.next(true).getMoveProperty());
            assertEquals(m2, it.next(true).getMoveProperty());
            assertEquals(m3, it.nextVariant(true).getMoveProperty());
            assertEquals(null, it.nextVariant(true));
        } catch (SGFPropertyNotFoundException e) {
            e.printStackTrace();
            fail("Unexpected!");
        }
    }
View Full Code Here

            SGFParser reader = new SGFParser(cgobanData);
            //FileInputStream is = new FileInputStream("data/1850-11-17-Shusaku-Ito.Showa.sgf");
            SGFNode tree = reader.parse();
            assertNotNull("Emty tree received.", tree);

            SGFNodeIterator i = tree.iterator();
            SGFPointProperty move;

            assertFalse(i.current().hasProperty(SGFPropertyName.W));
            assertFalse(i.current().hasProperty(SGFPropertyName.B));
            assertNull(i.prev(false));
            assertNull(i.prevVariant(false));
            assertNull(i.nextVariant(false));

            i.next(true);
            move = (SGFPointProperty) i.current().getProperty(SGFPropertyName.W);
            assertEquals(new SGFPointProperty(SGFPropertyName.W, new SGFPoint(4, 3)), move);
            assertFalse(i.current().hasProperty(SGFPropertyName.B));
            assertSame(tree, i.prev(false));
            assertNull(i.prevVariant(false));
            assertNull(i.nextVariant(false));

            i.next(true);
            move = (SGFPointProperty) i.current().getProperty(SGFPropertyName.B);
            assertEquals(move, new SGFPointProperty(SGFPropertyName.B, new SGFPoint(4, 2)));
            assertFalse(i.current().hasProperty(SGFPropertyName.W));
            //assertSame(p.getParent(), tree);
            assertNull(null, i.next(false));
            assertNull(null, i.prevVariant(false));
            //assertNotSame(p.getNext(), null);

            i.nextVariant(true);
            move = (SGFPointProperty) i.current().getProperty(SGFPropertyName.B);
            assertEquals(new SGFPointProperty(SGFPropertyName.B, new SGFPoint(4, 6)), move);
            assertFalse(i.current().hasProperty(SGFPropertyName.W));
            //assertSame(p.getParent(), tree);
            //assertSame(p.next(), null);
            assertNull(i.nextVariant(false));
            //assertNotSame(p.getNext(), null);

        } catch (Exception e) {
            e.printStackTrace();
            fail("No exceptions are expected.");
View Full Code Here

        } else
            return false;
    }

    private boolean setCursorToNextGoodMove() {
        SGFNodeIterator i = game.kifuLastMove().iterator();
        if (i.next(true) != null) {
            i.firstVariant(true);
            do {
                SGFNode node = i.current();
                if ((node.bits & SGFNode.GOOD_MOVE) != 0) {
                    return setCursor(node);
                }
            } while (i.nextVariant(true) != null);
            // no good moves found, set cursor to any move
            return setCursor(i.current());
        }
        return false;
    }
View Full Code Here

            dout.writeUTF(sgfText);

            if (sgfText.length() > 0) {
                Stack variants = new Stack();
                int depth = 0;
                SGFNodeIterator i = game.kifuLastMove().iterator();
                do {
                    SGFNodeIterator ii = i.current().iterator();
                    int varNumber = 0;
                    while (ii.prevVariant(true) != null)
                        varNumber++;
                    variants.push(new Integer(varNumber));
                    depth++;
                } while (i.prev(true) != null);
                dout.writeShort(depth);
View Full Code Here

        boolean doPlay() {
            try {
                if (!freePlay) {
                    // This code doesn't allow to play undocumented moves
                    //
                    SGFNodeIterator i = game.kifuLastMove().iterator();
                    if (i.next(true) == null)
                        return false;

                    // search for appropriate variant
                    SGFMove newMove = new SGFMove(cursorX, cursorY, game.colorToPlay);
                    SGFMove variantMove;
                    i.firstVariant(true);
                    do {
                        variantMove = i.current().getMoveProperty();
                    } while (!newMove.equals(variantMove) && i.nextVariant(true) != null);

                    if (!newMove.equals(variantMove))
                        return false;
                }

                game.play(cursorX, cursorY);
                snd.playStoneSound(game.colorToPlay == Board.WHITE);
                // show player's move
                notifyGameUpdated();

                if (!probStarted) {
                    if (probCurrent != null)
                        probCurrent.tried++;
                    probStarted = true;
                    statusScreen.setProblem(probCurrent, probEnum);
                }

                if (gobanCanvas.showMoveHints)
                    setCursorToNextGoodMove();
                else {
                    hasRespondMove = false;

                    SGFNodeIterator i = game.kifuLastMove().iterator();
                    if (i.next(true) != null) {
                        // play randomized response move

                        i.firstVariant(true);
                        int nGoodVariants = 0;
                        int nBadVariants = 0;

                        do {
                            if ((i.current().bits & SGFNode.GOOD_MOVE) != 0)
                                nGoodVariants++;
                            else if ((i.current().bits & SGFNode.BAD_MOVE) != 0)
                                nBadVariants++;
                        } while (i.nextVariant(true) != null);

                        // play response if there is good/bad hint
                        if (nGoodVariants > 0 || nBadVariants > 0) {
                            int k;
                            int mask;
                            Random rand = new Random();

                            if (nGoodVariants > 0) {
                                k = rand.nextInt(nGoodVariants);
                                mask = SGFNode.GOOD_MOVE;
                            } else {
                                k = rand.nextInt(nBadVariants);
                                mask = SGFNode.BAD_MOVE;
                            }
                            // k = 0 is valid good variant number, so in while it's >= 0
                            do {
                                if ((i.current().bits & mask) != 0)
                                    k--;
                            } while (k >= 0 && i.prevVariant(true) != null);

                            SGFMove variantMove = i.current().getMoveProperty();
                            game.play(variantMove.x, variantMove.y, variantMove.color);
                            snd.playStoneSound(game.colorToPlay == Board.WHITE);
                            // show response
                            notifyGameUpdated();

                            hasRespondMove = true;
                        }
                    }
                }

                if (!probFinished) {
                    SGFNodeIterator i = game.kifuLastMove().iterator();
                    boolean haveGoodMove = (i.current().bits & SGFNode.GOOD_MOVE) != 0;
                    probFinished = i.next(false) == null || !haveGoodMove;
                    if (probFinished) {
                        if (haveGoodMove) {
                            if (probCurrent != null)
                                probCurrent.solved++;
                            statusScreen.setProblem(probCurrent, probEnum);
View Full Code Here

TOP

Related Classes of com.sgfj.SGFNodeIterator

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.