我一直在努力为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是完整的可运行内容。
答案 0 :(得分:1)
*this = returnedBoard;
这可能是你的问题。您永远不会分配给*this
。