井字游戏针对计算机的简单代码-主要问题

时间:2019-05-09 20:54:54

标签: java arrays methods static-methods

我正在完成一个相当简单的井字游戏Java编码程序,其中有一种方法可以使计算机被调用为主程序,并且该程序运行时不会从playerX切换到playerO。

static void computerMoves() {
    int besti = 0;
    int bestj = 0;

    generateScore();
    scoreBoard();


    for (int i = 0; i < 3; ++i) 
        for (int j = 0; j < 3; ++j) {
            if (scoreBoard[i][j] > scoreBoard[besti][bestj]); {
                besti = i;
                bestj = j;
            }
        }
    currentBoard[besti][bestj] = playerO;

}

public static void main(String[] args) {
    int userMove;
    char player;

    initializeBoard();
    player = playerX;
    do {
    printBoard();
    if (player == playerX) {
    userMove = askUserForMove();
    makeMove(userMove, player);}
    else {
        computerMoves();
    }
    if (player == playerX)
        player = playerO;
    else 
        player = playerX;
    } while (isGameOver() == false);

    System.out.println("Game Over");
    printBoard();

结果应该是完整的井字游戏。现在,我得到的是“请在...之间输入数字”,这是askUserForMove方法。

0 个答案:

没有答案