I've been writing my chess engine for 2 months now, and I've come across this bug that I can't manage to solve. Basically, when I disable my transposition table, the engine plays fine and the minimax search selects one of the best options every time. With that said, when I enable them once again, it results in the selection of different moves than the optimal, which should not be happening (as their purpose is efficiency oriented).
if maximizing_player:
max_eval = -1*10**5
for state in possible_states:
node+= 1
eval = hawkins.minimax(self, state, depth-1, alpha, beta, False, castling_chance, last_move, quiet)
if eval[0] > max_eval:
max_eval = eval[0]
chosen = state
alpha = max(alpha, eval[0])
if beta <= alpha:
cut += 1
break
transposition_table[mx] = (max_eval, chosen)
return (max_eval, chosen)
else:
min_eval = 1*10**5
for state in possible_states:
node += 1
eval = hawkins.minimax(self, state, depth-1, alpha, beta, True, castling_chance, last_move, quiet)
if eval[0] < min_eval:
min_eval = eval[0]
chosen = state
beta = min(beta, eval[0])
if beta <= alpha:
cut += 1
break
transposition_table[mx] = (min_eval, chosen)
return (min_eval, chosen)
This is a simple minimax search implementation. When the depth reaches zero, I have a separate call to return a static evaluation. With that said, in my mind, I'm recording the best move possible and its score into a transposition table that has "mx" (the string that contains my game state) as a key. A little bit above the code snippet embedded, I wrote the following:
if mx in transposition_table.keys():
return transposition_table[mx]
So when we would find our "mx" once again, it would not spend resources trying to the best move possible. Could you please help me find what wrong with my implementation?