几天来,我一直在努力为Tic tac toe AI实现miniMax算法。现在,我遇到的问题是,当我调用minimax()函数时,在“ returnBoard”输入中得到了一块空板。我知道我的算法正在经历一系列电路板,因为我在打印出孩子的同时就将它们打印出来,并且我看到计算机正在移动并给电路板打分。有什么建议么?

void board::getBestMove()
{
board returnBoard;
miniMax(INT_MIN + 1, INT_MAX -1, returnBoard);
*this = returnBoard;
}

int board::miniMax(int alpha, int beta, board & childWithMaximum)
{
if (checkDone())
    return boardScore();

vector<board> children = getChildren();
for (int i = 0; i < children.size(); ++i)
{
    board curr = children[i];
    //children.pop_back();

    board dummyBoard;
    int score = curr.miniMax(alpha, beta, dummyBoard);

    if (computerTurn)
    {
        if (beta > score)
        {
            beta = score;
            childWithMaximum = curr;
            if (alpha >= beta) break;
        }
    }

    else
    {
        if (alpha < score)
        {
            alpha = score;
            childWithMaximum = curr;
            if (alpha >= beta) break;
        }
    }

}
return computerTurn? alpha : beta;
}

vector<board> board::getChildren()
{
vector<board> children;

for (int i = 0; i < 3; ++i)
{   for (int j = 0; j < 3; ++j)
    {
        if (getPosition(i, j) == '*') //move not made here
        {
            board moveMade(*this);
            moveMade.setPosition(i, j);
            children.push_back(moveMade);
        }
    }
}

return children;
}


Here是整个可运行内容。

最佳答案

*this = returnedBoard;


这可能是您的问题。您永远不要分配给*this

关于c++ - Tic Tac Toe Minimax算法返回空板,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21371915/

10-10 10:04