Examples of SGFNodeIterator


Examples of com.sgfj.SGFNodeIterator

        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

Examples of com.sgfj.SGFNodeIterator

                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

Examples of com.sgfj.SGFNodeIterator

        } 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

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

Examples of com.sgfj.SGFNodeIterator

        } 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

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

Examples of com.sgfj.SGFNodeIterator

            fail("Unexpected!");
        }
        assertNotNull("Emty tree received.", tree);

        try {
            SGFNodeIterator ni = tree.iterator();
            while (ni.next(true) != null)
                // DO NOTHING
                ;

            DocumentedGame game = new DocumentedGame(ni.current());
            //System.out.print(game.board.toString());
            assertEquals(wCaptures, game.whiteCaptures);
            assertEquals(bCaptures, game.blackCaptures);
            for (int pos = 0; pos < result.length; pos++) {
                SGFPoint p = game.board.xy(pos);
View Full Code Here

Examples of com.sgfj.SGFNodeIterator

        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

Examples of com.sgfj.SGFNodeIterator

                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

Examples of com.sgfj.SGFNodeIterator

        } 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
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.