持有人变量不变值

时间:2019-01-22 01:16:23

标签: java variables minimax

我正在尝试为Tic Tac Toe游戏的无与伦比的AI构建简单的minimax算法。代码可以正常工作,但是holder变量flag不会在代码末尾更改值。这是相关的部分:

int minimax (String[] board, boolean OTurn, int Depth)
{
    int flag = -1;
    int[] x = getAvailableMoves(board);
    ArrayList<Integer> results = new ArrayList<Integer>();
    ArrayList<Integer> pos = new ArrayList<Integer>();
    int arrayListSize = 0;

    if(Depth == maxDepth)
    {

        flag = Score(checkForGameState(board));
        System.out.println("set flag to score");

    }
    else if(OTurn)
    {
        System.out.println("entered oturn");
        iteration = 0;
        int[] j = getAvailableMoves(board);
        for(int i = 0; i < j.length; i++)
        {

            board[i] = "X";
            results.add(minimax(board, false, Depth + 1));
            arrayListSize++;
            pos.add(i);
            board[i] = "";
            iteration++;

        }

    }
    else if(!OTurn)
    {
        System.out.println("entered Xturn");
        iteration = 0;
        int[] k = getAvailableMoves(board);
        for(int i = 0; i < k.length; i++)
        {

            board[i] = "O";
            /*results.add(*/minimax(board, true, Depth + 1)/*)*/;
            //pos.add(i);
            board[i] = "";
            iteration++;

        }

    }
    return flag;        
}

与以下电路板一起运行时,此方法返回-1:

X |  | 
  |  |
  |  |

(也就是用{ "X", "" , "" , "" , "" , "" , "" , "" , ""}填充的板数组)。

0 个答案:

没有答案