问题描述
我正在尝试为我的国际象棋引擎程序实现静止搜索和 negamax 算法。 到目前为止我所做的:
def findMoveNegaMaxAlphaBeta(gs,validMoves,depth,alpha,beta,turnMultiplier,nextMove):
if depth == 0 :
requiredMoves = gs.getValidMoves()
actual_score = quiescienceSearch(gs,requiredMoves,1 if gs.whitetoMove else -1)
return actual_score
maxscore = -CHECKMATE
for move in validMoves :
gs.makeMove(move)
nextMoves = gs.getValidMoves()
score = -findMoveNegaMaxAlphaBeta(gs,nextMoves,depth - 1,-beta,-alpha,-turnMultiplier,nextMove)
if score > maxscore:
maxscore = score
if depth == DEPTH :
nextMove.put(move)
gs.undoMove()
if maxscore > alpha: # This is were pruning happens
alpha = maxscore
if alpha >= beta :
break
return maxscore
我在 https://www.chessprogramming.org/Quiescence_Search 上读到“在静止开始时,位置的评估用于建立分数的下限。这在理论上是合理的,因为我们通常可以假设至少有一个移动可以匹配或击败下限。”在我们计算任何进一步的捕获之前,我尝试通过将初始最高分数设置为板的静态评估来实现它。
def quiescienceSearch(gs,turnmultiplier):
quiescienceMoves = []
for move in validMoves:
if "x" in move.getChessNotation():
quiescienceMoves.append(move)
if len(quiescienceMoves) == 0:
return turnmultiplier * scoreBoard(gs)
maxscore = scoreBoard(gs)
for move in quiescienceMoves :
print(move.getChessNotation())
gs.makeMove(move)
nextMoves = gs.getValidMoves()
score = -quiescienceSearch(gs,-turnmultiplier)
if score > maxscore:
maxscore = score
gs.undoMove()
if maxscore > alpha :
alpha = maxscore
if alpha >= beta :
break
return maxscore
但这似乎不起作用。该程序花费了大量时间(它正在考虑很多愚蠢的选项,例如皇后采取一些受保护的棋子,这些选项似乎永远不会结束。)该程序只是继续计算并且即使 DEPTH == 也不给出任何动作1.
如何解决这个问题?我想我在 quiescenceSearch 函数中实现 alpha-beta 修剪时犯了一些错误,我该如何阻止它计算愚蠢的移动,比如捕获受保护的 pawn?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)