Package com.sgfj

Examples of com.sgfj.SGFMove


            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


        return false;
    }

    private boolean setCursor(SGFNode node) {
        try {
            SGFMove m = node.getMoveProperty();
            return setCursor(m.x, m.y);
        } catch (SGFPropertyNotFoundException e) {
            // DO NOTHING
        }
        return false;
View Full Code Here

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

        // 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

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

        // 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

            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

        // 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 SGFNode kifuFirstMove(boolean skipPass) {
        SGFNodeIterator i = kifu.first(false).iterator();
        do {
            try {
                SGFMove move = i.current().getMoveProperty();
                if (!skipPass || move.x >= 0)
                    break;
            } catch (SGFPropertyNotFoundException e) {
            }
        } while (i.next(true) != null);
View Full Code Here

    }

    public void play(int pos, byte color, boolean allowIllegal) throws GameException {
        // play on board to check exceptions first
        boardPlay(pos, color, allowIllegal);
        kifu.current().play(new SGFMove(board.xy(pos), color));
        kifu.next(true);
        playNodeProperties();
    }
View Full Code Here

TOP

Related Classes of com.sgfj.SGFMove

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.