From c415ed2a0bbab890fc1fdd2179c8f1405940c15a Mon Sep 17 00:00:00 2001 From: tslil Date: Tue, 5 May 2026 22:06:02 +0100 Subject: fix longstanding negamax bug we needed to be saving the alpha before the search loop in which we modified it. At this point, though i can't remember, i expect that this is the cause of whatever "instability" the comment was talking about that would have prevented us from using >= in the TT lookup. --- include/negamax.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'include/negamax.c') diff --git a/include/negamax.c b/include/negamax.c index dd769ad..995caa6 100644 --- a/include/negamax.c +++ b/include/negamax.c @@ -89,8 +89,7 @@ static float negamax(tak_state_p state, const uint8_t cur_depth, tt_entry_t *entry = tt_seek(hash); - // CAUTION: ≥ breaks search stability (vs =) on shallow depths - if (entry != NULL && entry->depth == cur_depth) { + if (entry != NULL && entry->depth >= cur_depth) { if (entry->flag == TT_EXACT) { return entry->value; } else if (entry->flag == TT_LOWERBOUND && entry->value > alpha) { @@ -116,6 +115,8 @@ static float negamax(tak_state_p state, const uint8_t cur_depth, action_move_to_front(negamax_best_action, actions, num_actions); } + const float orig_alpha = alpha; + action_t best_action = actions[0]; float best_value = -infty; @@ -162,7 +163,7 @@ static float negamax(tak_state_p state, const uint8_t cur_depth, flag = TT_EXACT; if (best_value >= beta) flag = TT_LOWERBOUND; - else if (best_value <= alpha) + else if (best_value <= orig_alpha) flag = TT_UPPERBOUND; if (entry == NULL) { -- cgit v1.2.3