Examples of SGFMove


Examples of com.sgfj.SGFMove

                    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

Examples of com.sgfj.SGFMove

        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

Examples of com.sgfj.SGFMove

        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

Examples of com.sgfj.SGFMove

            String data = "(;PW[White]PB[Me]AW[cb]AW[db]AW[eb]AW[bc]AW[cc]AW[cd]AW[dd]AW[ed]AW[fd]AW[gd]AW[de]AW[fe]AW[df]AW[ef]AB[bb]AB[fb]AB[hb]AB[ac]AB[dc]AB[ec]AB[fc]AB[gc]AB[bd]AB[hd]AB[be]AB[ce]AB[ge]AB[he]AB[cf]AB[ff]AB[hf]AB[cg]AB[dg]AB[eg]AB[fg];B[](;W[ca]CR[ca](;B[ea]CR[ea];W[ab]CR[ab](;B[aa]CR[aa];W[ba]CR[ba]C[RIGHT])(;B[ad]CR[ad];W[ba]CR[ba]C[RIGHT]))(;B[ad]CR[ad];W[ea]CR[ea]C[RIGHT])(;B[ab]CR[ab];W[ea]CR[ea]C[RIGHT]))(;W[ea]CR[ea];B[ca]CR[ca](;W[ab]CR[ab];B[aa]CR[aa])(;W[da]CR[da];B[ab]CR[ab])(;W[ba]CR[ba];B[ab]CR[ab]))(;W[ab]CR[ab];B[aa]CR[aa](;W[ca]CR[ca](;B[ea]CR[ea];W[ba]CR[ba]C[RIGHT])(;B[ad]CR[ad];W[ea]CR[ea]C[RIGHT]))(;W[ea]CR[ea];B[ca]CR[ca]))(;W[ba]CR[ba];B[ab]CR[ab](;W[ca]CR[ca];B[ea]CR[ea])(;W[ea]CR[ea];B[ca]CR[ca]))(;W[da]CR[da];B[ab]CR[ab]))";
            SGFParser parser = new SGFParser(data);
            SGFNode tree = parser.parse();
            DocumentedGame game = new DocumentedGame(tree);
            SGFNode node = game.kifuFirstMove(true);
            SGFMove move = node.getMoveProperty();
            assertEquals(SGFMove.WHITE, move.color);
            assertEquals(2, move.x);
            assertEquals(0, move.y);
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

Examples of com.sgfj.SGFMove

                    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

Examples of com.sgfj.SGFMove

        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

Examples of com.sgfj.SGFMove

public class SGFNodeBoundsVisitorTest extends TestCase {

    public void testWalk() {
        SGFNode node = new SGFNode();
        SGFMove wPass = new SGFMove(SGFMove.WHITE);
        node.addMoveProperty(wPass);
        SGFNode node2 = new SGFNode();
        SGFMove bPlay = new SGFMove(1, 10, SGFMove.BLACK);
        SGFMove wPlay = new SGFMove(3, 4, SGFMove.WHITE);
        node2.addMoveProperty(bPlay);
        node.add(node2);
        SGFNode node3 = new SGFNode();
        node3.addMoveProperty(wPlay);
        node.add(node3);
View Full Code Here

Examples of com.sgfj.SGFMove

    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

Examples of com.sgfj.SGFMove

    }

    public void testAddMove() {
        try {
            SGFNode node = new SGFNode();
            node.addMoveProperty(new SGFMove(16, 3, SGFMove.BLACK));
            assertEquals(new SGFMove(16, 3, SGFMove.BLACK), node.getMoveProperty());
        } catch (Exception e) {
            e.printStackTrace();
            fail("No exceptions are expected.");
        }
    }
View Full Code Here

Examples of com.sgfj.SGFMove

        assertSame(null, v3.iterator().next(false));
    }

    public void testPlay() {
        SGFNode root = new SGFNode();
        SGFMove m1 = new SGFMove(0, 0, SGFMove.WHITE);
        SGFMove m2 = new SGFMove(0, 1, SGFMove.BLACK);
        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();
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.