为什么 .equals() 会失败???跳棋游戏

Why does .equals() fail??? Checkers Game

我目前正在为一个学校项目开发跳棋游戏。棋盘是一个二维字符串数组,用于表示棋盘上的棋子。目前我正在编写游戏规则,但由于某些原因 .equals() 在 while 循环中失败。

 private static String redPawn = "redPawn";
 private static String blackPawn = "blackPawn";
 private static String redKing = "redKing";
 private static String blackKing = "blackKing"
 private static String[][] checkerPieces = new String[row][col];

 while(!redPawn.equals(checkerPieces[r][c]) || !redKing.equals(checkerPieces[r][c]))
    {
        System.out.println("You can only move the red pawns");
        playerInput.selectPiece();
    }

仅调试和放置时:

while(!redPawn.equals(checkerPieces[r][c]))
    {
        System.out.println("You can only move the red pawns");
        playerInput.selectPiece();
    }

在我添加检查 redKing 的条件语句之前它一直有效。谁能帮忙。

for some reasons .equals() fails in the while loop.

这是因为您使用了 OR ||,而是使用了 AND &&

while(!redPawn.equals(checkerPieces[r][c]) && !redKing.equals(checkerPieces[r][c]))