From 1ca3309dad9d412870b2b793f33af7a7ccabd514 Mon Sep 17 00:00:00 2001 From: tslil Date: Thu, 3 Sep 2026 20:17:22 +0100 Subject: 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 --- include/pv.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 include/pv.h (limited to 'include/pv.h') diff --git a/include/pv.h b/include/pv.h new file mode 100644 index 0000000..4be7b24 --- /dev/null +++ b/include/pv.h @@ -0,0 +1,47 @@ +/* + This file is part of ctak. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with ctak. If not, see . +*/ + +#ifndef PV_H +#define PV_H + +#ifdef RECORD_PV + +#include + +#include + +#define PV_MAX_CELLS (6 * 6) + +typedef struct pv_leaf_s { + float head[3]; + uint8_t cells[PV_MAX_CELLS]; + uint8_t current_colour; + uint8_t terminal; + float terminal_value; +} pv_leaf_t; + +// Capture a horizon leaf (winner == 0xFF) or an exact terminal leaf +void pv_capture_leaf(pv_leaf_t *leaf, tak_state_p state, + enum WIN_TYPE winner); + +// Publish and retrieve the leaf selected by the full-depth root search +void pv_publish_leaf(const pv_leaf_t *leaf); +const pv_leaf_t *pv_get_leaf(void); + +#endif + +#endif -- cgit v1.3.1