4

これは私の最後の投稿のフォローアップです。コードはエラーなしで機能し、次善の策を計算できます。転置テーブルを組み込み、ネガマックス関数に順序を移動して、より高速かつ正確に実行する方法を検討してきましたが、私のような初心者にとってはやや難しく高度なようです。

私のコードはこちらにあります

チェス プログラミング wiki を調べているときに、転置テーブルのサンプル コードを見つけました。

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 キーを使用してハッシュ キーを保存することについても見たことがありますが、それがどのように機能するのかよくわからなかったので、アイデアを取り下げました。現在、これらの問題にいくらか行き詰まっており、次のステップが何であるかわかりません。

4

1 に答える 1