aboutsummaryrefslogtreecommitdiff
path: root/src/match.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 /src/match.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 'src/match.c')
-rw-r--r--src/match.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/match.c b/src/match.c
index 1c706cd..49ff9c9 100644
--- a/src/match.c
+++ b/src/match.c
@@ -14,7 +14,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with ct. If not, see <https://www.gnu.org/licenses/>.
+ along with ctak. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
@@ -37,7 +37,7 @@
static inline float five_cand(tak_state_p state) {
static float cur_board[FIVE_INP_NUM] NN_ALIGNED;
- nn_prepare_input(cur_board, state);
+ nn_prepare_input(cur_board, state, cand_five_embedding);
return eval_net(cur_board, FIVE_INP_NUM, &cand_five_dense_weights[0][0],
cand_five_dense_biases, cand_five_logit_weights, cand_five_logit_bias,
FIVE_DENSE_NUM);
@@ -46,7 +46,7 @@ static inline float five_cand(tak_state_p state) {
static inline float six_cand(tak_state_p state) {
static float cur_board[SIX_INP_NUM] NN_ALIGNED;
- nn_prepare_input(cur_board, state);
+ nn_prepare_input(cur_board, state, cand_six_embedding);
return eval_net(cur_board, SIX_INP_NUM, &cand_six_dense_weights[0][0],
cand_six_dense_biases, cand_six_logit_weights, cand_six_logit_bias,
SIX_DENSE_NUM);
@@ -107,16 +107,16 @@ static int play_game(const nn_function current_fn, const nn_function cand_fn,
switch (state->won) {
case WIN_DRAW:
- return -1;
- case WIN_FLAT_BLACK:
+ return -1;
+ case WIN_FLAT_BLACK:
case WIN_ROAD_BLACK:
return C_BLACK;
case WIN_FLAT_WHITE:
case WIN_ROAD_WHITE:
return C_WHITE;
default:
- fprintf(stderr, "match: game did not end cleanly (won=%d)\n", state->won);
- return -2;
+ // ply cap reached with no winner: a draw
+ return -1;
}
}
@@ -124,7 +124,7 @@ static int play_game(const nn_function current_fn, const nn_function cand_fn,
// Main
// ===================================================================
-const char *license =
+const char *usage =
"match, one Tak game of the current weights against the candidate.\n\
\n \
usage: match <size> <eps> <depth>\n\
@@ -137,14 +137,11 @@ nn_train.py runs many of these in parallel to score the candidate against the cu
\n\
Copyright (C) 2026, tslil clingman\n\
\n\
-This program is free software: you can redistribute it and/or modify\n\
-it under the terms of the GNU General Public License as published by\n\
-the Free Software Foundation, either version 3 of the License, or\n\
-(at your option) any later version.";
+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.";
int main(int argc, char **argv) {
if (argc != 4) {
- puts(license);
+ puts(usage);
return EXIT_FAILURE;
}
@@ -179,9 +176,7 @@ int main(int argc, char **argv) {
const int winner = play_game(current_fn, cand_fn, current_fn_colour, eps10000);
const char *name;
- if (winner == -2)
- name = "abort";
- else if (winner == -1)
+ if (winner == -1)
name = "draw";
else if (winner == (int)current_fn_colour)
name = "current";