我正在尝试为我的 negamax AI(不是国际象棋 - 10-10-5 mnk 或名为 Take 5 的五子棋风格的游戏)实现一个简单的静止搜索。它已经有一个转置表。主要的 negamax 算法如下所示:
def negamax(board, depth, alpha, beta, player, ttable):
if board in ttable:
value, vtype = ttable[board]
if vtype == 0:
return value
elif vtype == 1:
beta = min(alpha, value)
else:
alpha = max(beta, value)
score = board.getValue()
if abs(score) == 1000000000000:
return player * score
if depth == 0:
return player * score
oldAlpha = alpha
possibleMoves = board.getBestNextMoves()
value = -1000000000000
for move in possibleMoves:
#child = board#Board(board)
board.place(move, player)
value = max(value, -negamax(board, depth-1, -beta, -alpha,
-player, ttable))
board.place(move, 0)
alpha = max(alpha, value)
if alpha >= beta:
break # alpha beta prune
if value <= oldAlpha:
vtype = 1
elif value >= beta:
vtype = -1
else:
vtype = 0
ttable[board] = (value, vtype)
return value
我在网上寻找了一些静止搜索算法,但它们似乎无法正常工作,但这就是我想出的:
def quiesce(board, alpha, beta, player, ttable):
if board in ttable:
value, vtype = ttable[board]
if vtype == 0:
score = value
else:
score = player * board.getValue()
ttable[board] = (score, 0)
else:
score = board.getValue()
ttable[board] = (score, 0)
if score >= beta:
return score
if alpha < score:
alpha = score
for move in board.getForcedMoves(player):
board.place(move, player)
score = -quiesce(board, -beta, -alpha, -player, ttable)
board.place(move, 0)
if score >= beta:
return score
if score > alpha:
alpha = score
return alpha
你能检查我是否正确地实现了这个算法的静止搜索?