diff options
| author | tslil <tslil@posteo.de> | 2026-05-05 22:06:02 +0100 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-05-05 22:16:39 +0100 |
| commit | 696c3808220ea9d8c604939894a2d509f05cc4c6 (patch) | |
| tree | e185fa56359288e9ab5419d3af17365c1f125b13 /include | |
| parent | 2e5ffeaf928626c81ea3147b57b7ee2c660ebfae (diff) | |
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.
Diffstat (limited to 'include')
| -rw-r--r-- | include/negamax.c | 7 |
1 files changed, 4 insertions, 3 deletions
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) { |
