这是我上一篇文章的后续内容。该代码运行时没有任何错误,并且可以计算下一个最佳移动。我一直在研究如何将换位表和移动排序合并到我的 negamax 函数中,以使其运行得更快、更准确,但对于像我这样的初学者来说,这似乎有些困难和先进。
你可以在这里找到我的代码。
在研究国际象棋编程维基时,我发现了一些换位表的示例代码:
def negamax(node, depth, alpha, beta, color):
alphaOrig = alpha
## Transposition Table Lookup; node is the lookup key for ttEntry
ttEntry = transpositionTableLookup(node)
if ttEntry.is_valid is True and ttEntry.depth >= depth:
if ttEntry.flag == EXACT :
return ttEntry.value
if ttEntry.flag == LOWERBOUND:
alpha = max(alpha, ttEntry.value)
if ttEntry.flag == UPPERBOUND:
beta = min(beta, ttEntry.value)
if alpha >= beta:
return ttEntry.value
if depth == 0 or node is terminal_node:
return color* heuristic_value_of_node
childNodes = …Run Code Online (Sandbox Code Playgroud)