2
我一直在稳步研究国际象棋程序,并有极小的搜索,迭代加深和换位表即将到来。然而,目前,我有一个我孤立在我的静止搜索中的错误。我很沮丧,因为我直接复制了一个伪代码实现,但它似乎并没有为我工作。我在网上找到的其他实现给了我类似的结果。静态错误搜索
这个错误似乎错误地计算了对手“最佳”捕获时,当多个recaptures可用,并作为结果返回一个值通常有利于调用搜索一侧。
发动机分别用C#编写
public static double Quiet(Game game, double alpha, double beta, int depth)
{
double eval = Evaluation.evaluate(game);
if(depth == 0)
{
return eval;
}
// Pseudo-legal sorted moves (Captures first)
List<SerializedMove> moves = MoveGenerator.ListAllMoves(game, false);
foreach(SerializedMove move in moves)
{
// If the move is not a capture
if(move.taken_type == SerializedMove.NONE)
{
// Because of move ordering break if not a capture (Captures are first)
break;
}
// Make move and alternate side to move
game.MakeMove(move);
if(game.whiteMoves)
{
double score = Quiet(game, alpha, beta, depth - 1);
if(score > alpha)
{
alpha = score;
}
}
else
{
double score = Quiet(game, alpha, beta, depth - 1);
if(score < beta)
{
beta = score;
}
}
game.UnmakeMove(move);
if(beta <= alpha)
{
break;
}
}
if(game.whiteMoves)
{
if(beta == Evaluation.KING)
{
return eval;
}
else
{
return beta;
}
}
else
{
if(alpha == -Evaluation.KING)
{
return eval;
}
else
{
return alpha;
}
}
}
我的评价函数返回值+/-赞成白色或黑色。
不能证明这一点,但我认为你是对的。因此,使用Negamax而不是Minimax更为常见。然后阿尔法总是意味着“坏”,而贝塔总是意味着“好”。 –
@ Philipp有趣的是,我总是发现negamax令人困惑,因此总是把我的搜索编码为直接的alpha-beta。因此,这段代码对我来说比较熟悉。 –
@Kyle我同意...谢谢。我想我的一部分很高兴我的bug非常简单:p谢谢! – Alan