Python 静态搜索实现中的问题
我正在尝试为我的国际象棋引擎程序实现静态搜索和negamax算法。 我到目前为止所做的: 这是我在代码的主要部分调用的Negamax函数的代码:Python 静态搜索实现中的问题,python,chess,minmax,Python,Chess,Minmax,我正在尝试为我的国际象棋引擎程序实现静态搜索和negamax算法。 我到目前为止所做的: 这是我在代码的主要部分调用的Negamax函数的代码: def findMoveNegaMaxAlphaBeta(gs, validMoves, depth, alpha, beta, turnMultiplier, nextMove): if depth == 0 : requiredMoves = gs.getValidMoves() actual_score = quiescienc
def findMoveNegaMaxAlphaBeta(gs, validMoves, depth, alpha, beta, turnMultiplier, nextMove):
if depth == 0 :
requiredMoves = gs.getValidMoves()
actual_score = quiescienceSearch(gs, requiredMoves, alpha, beta, 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
我读到“在静止期开始时,位置的评估用于确定分数的下限。这在理论上是合理的,因为我们通常可以假设至少有一个动作可以匹配或超过下限。”我试图通过在计算任何进一步的捕获之前将初始最大分数设置为静态评估板来实现它
这是我的静止功能的代码:
def quiescienceSearch(gs, validMoves, alpha, beta, 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, nextMoves, -beta, -alpha, -turnmultiplier)
if score > maxScore:
maxScore = score
gs.undoMove()
if maxScore > alpha :
alpha = maxScore
if alpha >= beta :
break
return maxScore
但这似乎不起作用。该程序花费了大量时间(它正在考虑许多愚蠢的选项,比如皇后拿走了一些受保护的棋子,这些选项似乎永远不会结束。)该程序只是继续计算,即使深度=1,也不会给出任何移动
如何纠正这一点?我想我在quiesceSearch函数中实现alpha-beta剪枝时犯了一些错误,我如何阻止它计算愚蠢的动作,例如捕获受保护的棋子?你链接到一个伟大的代码源,然后在QS中使用完全不同的方法。怎么会?只要使用chessprogramming中的伪代码就行了。Thnx,行了。