⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sgfadapter1.java

📁 Java编写的小游戏扫雷代码,可以在多种环境下运行
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        buf.append(c);
                        break;
                }

                if (stop) {
                    break;
                }
            }
        }
        catch (SgfException sgf_e) {
            sgf_e.printStackTrace();
            return null;
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        Movement root = last;
        while (root.getParent() != null) {
            root = (Movement) root.getParent();
        }
        match.setMovements(root);

        return match;
    }

    protected static void parseAttribute(Match match, Movement current, String attrName, String attrValue) {
        if (attrName.equals("B")) {
            if (attrValue.length() != 2) {
                return;
            }
            current.player = GoPlayer.BLACK;
            char xx = attrValue.charAt(0);
            char yy = attrValue.charAt(1);
            current.col = xx - 'a';
            current.row = yy - 'a';
        }
        else if (attrName.equals("W")) {
            if (attrValue.length() != 2) {
                return;
            }
            current.player = GoPlayer.WHITE;
            char xx = attrValue.charAt(0);
            char yy = attrValue.charAt(1);
            current.col = xx - 'a';
            current.row = yy - 'a';
        }
        else if (attrName.equals("AB")) {
            if (attrValue.length() != 2) {
                return;
            }
            char xx = attrValue.charAt(0);
            char yy = attrValue.charAt(1);
            current.addForce(xx-'a', yy-'a', GoPlayer.BLACK);
        }
        else if (attrName.equals("AW")) {
            if (attrValue.length() != 2) {
                return;
            }
            char xx = attrValue.charAt(0);
            char yy = attrValue.charAt(1);
            current.addForce(xx-'a', yy-'a', GoPlayer.WHITE);
        }
        else if (attrName.equals("AE")) {
            if (attrValue.length() != 2) {
                return;
            }
            char xx = attrValue.charAt(0);
            char yy = attrValue.charAt(1);
            current.addForce(xx-'a', yy-'a', GoPlayer.UNKNOWN);
        }
        else if (attrName.equals("C")) {
            current.setComment(attrValue);
        }
        else if (attrName.equals("CR")) {
            if (attrValue.length() != 2) {
                return;
            }
            char xx = attrValue.charAt(0);
            char yy = attrValue.charAt(1);
            current.addTip(xx-'a', yy-'a', GoPoint.CIRCLE);
        }
        else if (attrName.equals("TR")) {
            if (attrValue.length() != 2) {
                return;
            }
            char xx = attrValue.charAt(0);
            char yy = attrValue.charAt(1);
            current.addTip(xx-'a', yy-'a', GoPoint.TRIANGLE);
        }
        else if (attrName.equals("LB")) {
            if (attrValue.length() != 4) {
                return;
            }
            char xx = attrValue.charAt(0);
            char yy = attrValue.charAt(1);
            char tip = attrValue.charAt(3);
            current.addTip(xx-'a', yy-'a', tip);
        }
        else if (attrName.equals("SQ")) {
            if (attrValue.length() != 4) {
                return;
            }
            char xx = attrValue.charAt(0);
            char yy = attrValue.charAt(1);
            current.addTip(xx-'a', yy-'a', GoPoint.SQUARE);
        }
        else if (attrName.equals("SZ")) {
            match.boardSize = Integer.parseInt(attrValue);
        }
        else if (attrName.equals("PB")) {
            match.blackName = attrValue;
        }
        else if (attrName.equals("PW")) {
            match.whiteName = attrValue;
        }
        else if (attrName.equals("BR")) {
            match.blackRank = attrValue;
        }
        else if (attrName.equals("WR")) {
            match.whiteRank = attrValue;
        }
        else if (attrName.equals("EV")) {
            match.matchName = attrValue;
        }
        else if (attrName.equals("DT")) {
            match.matchDate = attrValue;
        }
        else if (attrName.equals("PC")) {
            match.place = attrValue;
        }
        else if (attrName.equals("RE")) {
            match.result = attrValue;
        }
        else if (attrName.equals("SO")) {
            match.source = attrValue;
        }
        else if (attrName.equals("TM")) {
            match.timeLen = Integer.parseInt(attrValue);
        }
    }

/**************************************************************************************
 *
 * private methods for write sgf file
    private String comment;
    private Vector tips;

    protected int col, row;
    protected int player;

    private Vector captives;
    private Vector forcePut; *
 **************************************************************************************/

    protected static String movementTreeToString(Movement root) {
        String output = "";
        System.out.println("saving movement!");

        output += movementToString(root);

        if (root.getChildCount() == 0) {
            output += ")\n";
            return output;
        }
        else if (root.getChildCount() == 1) {
            output += ";\n";
            output += movementTreeToString((Movement)root.getChildAt(0));
            return output;
        }
        else {
            for (int i = 0; i < root.getChildCount(); i++) {
                output += "\n(;";
                output += movementTreeToString((Movement)root.getChildAt(i));
            }
            output += ")\n";
        }
        System.out.println("movement string is " + output);
        return output;
    }

    protected static String movementToString(Movement move) {

        String output = "";

        // write move
        if ((move.col != -1) && (move.row != -1)) {
            if (move.player == GoPlayer.BLACK) {
                output += ("B[" + (char)(move.col+'a') + (char)(move.row+'a') + "]");
            }
            else {
                output += ("W[" + (char)(move.col+'a') + (char)(move.row+'a') + "]");
            }
        }

        // write comment
        if (move.getComment() != null) {
            output += ("C[" + move.getComment() + "]");
        }

        // write tips
        for (int i = 0; i < move.getTipCount(); i++) {
            Movement.HandTip t = move.tipAt(i);
            if (t.tip == GoPoint.TRIANGLE) {
                output += ("TR[" + (char)(t.col+'a') + (char)(t.row+'a') + "]");
            }
            else if (t.tip == GoPoint.CIRCLE) {
                output += ("CR[" + (char)(t.col+'a') + (char)(t.row+'a') + "]");
            }
            else if (t.tip == GoPoint.CROSS) {
                output += ("MA[" + (char)(t.col+'a') + (char)(t.row+'a') + "]");
            }
            else if (t.tip == GoPoint.SQUARE) {
                output += ("SQ[" + (char)(t.col+'a') + (char)(t.row+'a') + "]");
            }
            else {
                output += ("LB[" + (char)(t.col+'a') + (char)(t.row+'a') + ":" + (char)t.tip + "]");
            }
        }

        //write force put
        for (int i = 0; i < move.getForceCount(); i++) {
            Movement.HandTip t = move.forceAt(i);
            if (t.tip == GoPlayer.BLACK) {
                output += ("AB[" + (char)(t.col+'a') + (char)(t.row+'a') + "]");
            }
            else {
                output += ("AW[" + (char)(t.col+'a') + (char)(t.row+'a') + "]");
            }
        }

        return output;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -