From 7ef68374e8a58684b299b0f46f7ed850d5a87190 Mon Sep 17 00:00:00 2001 From: tslil Date: Sun, 6 Sep 2026 17:24:44 +0100 Subject: cleanup, match now plays pairs of symmetric games --- src/match.c | 60 +++++++++++++++++++++++++++++------------------------------- 1 file changed, 29 insertions(+), 31 deletions(-) (limited to 'src/match.c') diff --git a/src/match.c b/src/match.c index 94afe48..6ae9fa7 100644 --- a/src/match.c +++ b/src/match.c @@ -57,10 +57,6 @@ static inline float six_cand(tak_state_p state) { static tak_state_p state; -// =================================================================== -// negamax progress hook (silent) -// =================================================================== - void negamax_display_progress(const uint8_t cur_depth, const uint8_t init_depth, const uint32_t length) { @@ -116,11 +112,34 @@ static int play_game(const nn_function current_fn, const nn_function cand_fn, } } -// =================================================================== -// Main -// =================================================================== +void do_game(const uint8_t size, const uint8_t random_opening_length, const enum COLOUR current_fn_colour) { + state = new_tak_state(size); + negamax_init(size); + + const nn_function current_fn = + (size == 5) ? &five_nn_fn : &six_nn_fn; + const nn_function cand_fn = (size == 5) ? &five_cand : &six_cand; + + const int winner = play_game(current_fn, cand_fn, current_fn_colour, random_opening_length); -const char *usage = + const char *name; + if (winner == -1) + name = "draw"; + else if (winner == (int)current_fn_colour) + name = "current"; + else + name = "candidate"; + printf("%s %u\n", name, state->ply); + + negamax_free(); + free_tak_state(state); +} + + // =================================================================== + // Main + // =================================================================== + + const char *usage = "match, one Tak game of the current weights against the candidate.\n\n\ usage: match \n\n\ This binary is linked with both the include/weight_* files and the include/cand_weight_* files. It plays a single x game, with a random side choice and both sides using random moves at the start of the game. The result format is:\n\n\ @@ -147,29 +166,8 @@ int main(int argc, char **argv) { 0x9E3779B97F4A7C15ULL + 0xC0FFEE; - state = new_tak_state(size); - negamax_init(size); - - const nn_function current_fn = - (size == 5) ? &five_nn_fn : &six_nn_fn; - const nn_function cand_fn = - (size == 5) ? &five_cand - : &six_cand; - - const enum COLOUR current_fn_colour = rand32() % 2 ? C_WHITE : C_BLACK; - const int winner = play_game(current_fn, cand_fn, current_fn_colour, random_opening_length); - - const char *name; - if (winner == -1) - name = "draw"; - else if (winner == (int)current_fn_colour) - name = "current"; - else - name = "candidate"; - printf("%s %u\n", name, state->ply); - - negamax_free(); - free_tak_state(state); + do_game(size, random_opening_length, C_BLACK); + do_game(size, random_opening_length, C_WHITE); return EXIT_SUCCESS; } -- cgit v1.3.1