aboutsummaryrefslogtreecommitdiff
path: root/include/tt.c
diff options
context:
space:
mode:
authortslil <tslil@posteo.de>2026-09-03 20:17:22 +0100
committertslil <tslil@posteo.de>2026-09-04 21:03:59 +0100
commit1ca3309dad9d412870b2b793f33af7a7ccabd514 (patch)
tree15ce96557f04a7eded89193f12065dcd64c33ec8 /include/tt.c
parentf11793dc0fddfcaad04b89827634cbb40fa98e59 (diff)
TD-leaf and another negamax bug
TD-lambda and TD-leaf are separated by the observation that minimax with a parameterised leaf heuristic is differentiable* in the parameters. "All" that had to be done was to extract the "principal variation": which one position survived all of the pruning to become the reported value. This was a bit fiddly and uncovered a subtle bug (again) in negamax.c: we were not being complete in our overriding of the TT entry and by omitting key it was possible that later searches would find incorrect values. The more interesting question to me was: how do we introduce enough variety while not corrupting the PV chain? I settled on having selfplay have one of the players be epsilon-random but the other greedy (minimax) and simply report only the greedy portion PV chain. This appears to work well enough in practice and doesn't introduce nonsense training data for the net (we don't force its actions to be nonsensical). I also deciced, perhaps in a departure from tradition, that we had good supervised labels for PVs that happened to be winning states, so the training overrides the targets in that case. Finally rolled back some of the ambition in nn_train.py default arguments. *almost always
Diffstat (limited to 'include/tt.c')
-rw-r--r--include/tt.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/include/tt.c b/include/tt.c
index b1f583e..8ad6c56 100644
--- a/include/tt.c
+++ b/include/tt.c
@@ -43,18 +43,28 @@ tt_entry_t *tt_seek(const uint64_t key) {
return NULL;
}
-int tt_insert(const uint64_t key, const enum TT_FLAG flag,
- const uint8_t depth, const float value,
- const action_t action) {
+tt_entry_t *tt_store(const uint64_t key, const enum TT_FLAG flag,
+ const uint8_t depth, const float value,
+ const action_t action) {
tt_entry_t *e = &table[key & TT_SIZE];
- // Replacement scheme: keep a stale-but-deeper entry over a shallower new one.
+ if (e->gen == tt_gen && e->key == key) {
+ // The slot holds this very position: update it (gen and key are already
+ // correct).
+ e->flag = flag;
+ e->value = value;
+ e->depth = depth;
+ e->action = action;
+ return e;
+ }
+ // Empty slot, stale generation, or a different position: keep a deeper search
+ // of a foreign position over this shallower one.
if (e->gen == tt_gen && e->depth > depth)
- return EXIT_SUCCESS;
+ return NULL;
e->key = key;
e->value = value;
e->action = action;
e->gen = tt_gen;
e->flag = flag;
e->depth = depth;
- return EXIT_SUCCESS;
+ return e;
}