aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authortslil <tslil@posteo.de>2026-05-05 22:06:02 +0100
committertslil <tslil@posteo.de>2026-08-28 19:37:41 +0100
commitc415ed2a0bbab890fc1fdd2179c8f1405940c15a (patch)
treee185fa56359288e9ab5419d3af17365c1f125b13 /include
parentf0139acd1d648dd1db93ee3d3b75546fb7b24c77 (diff)
fix longstanding negamax bugHEADmain
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.c7
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) {