问题描述
我已经为国际象棋引擎编写了以下代码:
double AlphaBetaPruning(int currentDepth,bool maximizingPlayer,double alpha,double beta)
{
try
{
// Terminating condition. i.e leaf node is reached
if (currentDepth == maxDepth)
{
var leafVal = Evaluation(); //@StackExchange: Redundant line,but wanted to make clear,what happens here.
return leafVal;
}
if (maximizingPlayer)
{
return Iteration(currentDepth,maximizingPlayer,alpha,beta);
}
else
{
return Iteration(currentDepth,beta);
}
}
catch (Exception e)
{
//Program is never here
}
}
打电话给这个
private double Iteration (int currentDepth,double beta)
{
double best = maximizingPlayer ? -1_000: 1_000;
foreach (var optMove in PruneOpt.OrderedMoves(maximizingPlayer))
{
//Play actual move:
Gameboard.TryMove(optMove);
var val = AlphaBetaPruning(currentDepth + 1,(!maximizingPlayer),beta);
//Clean up:
Gameboard.TryRevertLastMove();
if (maximizingPlayer)
{
best = Math.Max(best,val);
alpha = Math.Max(alpha,best);
}
else
{
best = Math.Min(best,val);
beta = Math.Min(beta,best);
}
// Alpha Beta Pruning
if (beta <= alpha) // !! Removing this makes a classic
{ // !! MinMax,but changes the
return best; // !! outcome of the scores in
} // !! lower depths. The "best move" changes.
}
return best;
}
然后,我将在“最低”深度(意味着可以播放的下一个层)上看到许多移动(33个,仅供参考(无关紧要,它们是恒定的))。以及它们各自的分数(从深叶节点向上取)。
问题是:如果删除“修剪”,则这33个最低节点的分数将改变。如果一个修剪不是为“
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)