Java:connect 4,二进制运算符错误的操作数类型错误

Java:connect 4,二进制运算符错误的操作数类型错误,java,arrays,operator-keyword,Java,Arrays,Operator Keyword,我得到一些奇怪的坏操作数错误,我似乎无法解决 public class Model { // Keep track of whether a move animation is currently playing. // When a move animation is busy then no new moves are allowed. private boolean moveInProgress = false; private int[][] pieces = new int[7][7

我得到一些奇怪的坏操作数错误,我似乎无法解决

public class Model {

// Keep track of whether a move animation is currently playing.
// When a move animation is busy then no new moves are allowed.
private boolean moveInProgress = false;
private int[][] pieces = new int[7][7];
private boolean gameOver = false;


public void checkGameOver() {
    // TODO (step 3): implement this correctly.
    gameOver = true;
}

/**
 * Check if a new disk can be inserted in the current column.
 * @param column
 * @return true if and only if a move in this column is allowed.
 */
public boolean playableMove(int column) {
    // No new moves are allowed when an animation is busy.
    if (getMoveInProgress()) {
        return false;
    }
    // TODO (step 3) No moves are allowed when the game is over.
    if (gameOver) {
        return false;
    }
    // TODO: Check if this move is playable.
    if (pieces[column] > 6) {
        return false;
    }
    return true;
}

/**
 * Compute the final destination row of a candidate move.
 * @param column
 * @return the row.
 */
public int moveDestination(int column) {
    // TODO: implement this method properly.
    int positie = 6 - pieces[column];
    return positie;
}

/**
 * Commit the insertion of a new disk in a given column.
 * @param column
 */
public void playMove(int column) {
    // TODO: Verify the following preconditions:
    // assert (isGameOver() == false);
    // assert (playableMove(column) == true);

    // TODO: Update the model to reflect the new move.

    // TODO (step 3): Also check for termination conditions.

    // TODO (step 3): Notify subscribers about important model changes.

    if (!gameOver && playableMove(column)) {

        pieces[column]++;
    }
}
}
错误在

76,28二进制运算符'>'的错误运算符 第一类int[] 第二类int

相同的错误重复4次

有谁能帮我解决这个问题吗

您已经定义了private int[]pieces=new int[7][7];。因此,当您使用片段[column]访问它时,您只剩下一个数组,因此无法将其与int进行比较


您可能指的是片段[column].length?

如果要对数组的每个元素执行任何算术运算,则必须显式执行

比如说,

if (!gameOver && playableMove(column)) {
    for (int i=0; i < pieces[column].length; i++) {
        pieces[column][i]++;
    }
}

关于其他检查,6条[column]意味着生成一个整数,而6条[column]>6意味着不清楚此条件是应用于所有元素还是至少一个元素,因为未知的前提条件,我无法帮助您。

错误消息中有什么您不明白的?您正在尝试检查碎片[column]>6,但碎片[column]是数组,因为碎片是2D数组,询问数组是否大于6是没有意义的。谢谢您的输入,我只是简单地吮吸数组,使用.lenght解决这个问题的任何想法都没有完全奏效。我最初制作这个程序是为了使用1d数组,但后来我不得不使用2d数组,因为我不擅长数组,所以无法解决它。无论如何,谢谢你的建议,我会尝试一下。除了片段[column]++还有什么建议吗?同样,片段[column]是一个数组。您不能将1添加到数组中。@Eludum您认为分段[column]++是什么意思?@glglgl将+1添加到列中,但这不是int,所以无法工作,唯一的问题是我需要将+1添加到列中,但不知道如何在二维数组中执行此操作。