【问题标题】:Transposition tables for python chess enginepython国际象棋引擎的转置表
【发布时间】:2022-01-05 18:48:38
【问题描述】:

这是我上一篇文章的后续。 该代码可以正常工作,并且可以计算下一个最佳移动。我一直在研究如何将转置表和排序移动到我的 negamax 函数中,以使其运行得更快、更准确,但对于像我这样的初学者来说,这似乎有些困难和高级。

你可以找到我的代码here

在研究国际象棋编程维基时,我发现了一些转置表的示例代码:

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 = domove(node)
childNodes = orderMoves(childNodes)
bestValue = -99999

for child in childNodes:
    bestValue = max(bestValue, -negamax(child, depth - 1, -beta, -alpha, -color))
    alpha = max(alpha, bestValue)
    if alpha >= beta:
        break

##Transposition Table Store; node is the lookup key for ttEntry 
    ttEntry.value = bestValue
    if bestValue <= alphaOrig:
        ttEntry.flag = UPPERBOUND
    if bestValue >= beta:
        ttEntry.flag = LOWERBOUND
    else:
        ttEntry.flag = EXACT
        ttEntry.depth = depth   
        transpositionTableStore(node, ttEntry)
        return bestValue

我尝试进行一些修改以将其集成到我的代码中,但我没有从中得到任何结果。 我还看到了一些关于使用 Zobrist 键存储位置的哈希键,但我不太了解它是如何工作的,所以我放弃了这个想法。目前有点卡住这些问题,不知道下一步是什么。

【问题讨论】:

    标签: python chess alpha-beta-pruning negamax


    【解决方案1】:

    要使用转置表,您“需要”使用 Zorbrist 散列。散列为每个位置提供了一个(几乎)唯一的代码,您将其连同其评估一起存储在转置表中。然后,为了方便解释,如果您正在搜索的当前位置在您的转置表中找到,您不必再次评估它,您只需使用存储的值。

    Zorbrist 密钥是一场噩梦,很难正确调试。如果有帮助,您可以查看我在 Endamat Chess Engine 中的实现,但由于您可能有不同的方法,因此可能更容易阅读 Zorbrist 密钥的工作原理并尝试使其适合您的实现。

    【讨论】:

    • 谢谢。我一定会看看你的代码。将对此主题进行更多研究,看看我能找到什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-02
    • 1970-01-01
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-22
    相关资源
    最近更新 更多