为什么循环内的循环没有运行完成?

时间:2015-10-02 12:15:28

标签: java loops for-loop

我需要循环遍历A1,A2..A8..B8 ...... H8,但由于某种原因它停在C3处。对于我的生活,我无法弄清楚为什么循环中的这个循环没有运行。

P.S字母只是字母{A,B,C ... Z}的一个列表,而getValue()只返回一个值,取决于字母值多少。

int bestMove = 0;

for(int i = 0; i < 8; i++){
    for(int x = 0; x < 8; x++){
        System.out.println(letters.get(i) + "" + (x+1));

        int distanceRow = currentRow - i;
        int distanceCol = currentCol - x;
        distanceRow = Math.abs(distanceRow);
        distanceCol = Math.abs(distanceCol);

        if(currentRow == i && currentCol == x){
            System.out.println("if");
        } else if (distanceRow - distanceCol == 0) {
            bestMove = getValue(getPiece(i, x));
            System.out.print("else if");
            System.out.println(letters.get(i) + "" + (x+1));
        } else {
            System.out.print(letters.get(i) + "" + (x+1));
            System.out.println("else");
        }
    }

编辑:我按照建议进行了测试,看起来这个方法出现了错误,虽然我不知道是什么,因为它只返回一个值

 public int getValue(String piece) {

        if (piece.equals(w1)) {
            return 1;
        } else if (piece.equals(w2)) {
            return 3;
        } else if (piece.equals(w3)) {
            return 3;
        } else if (piece.equals(w4)) {
            return 5;
        } else if (piece.equals(w5)) {
            return 9;
        }
        return 0;
    }

0 个答案:

没有答案
相关问题