aboutsummaryrefslogtreecommitdiff
path: root/src/match.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/match.c')
-rw-r--r--src/match.c60
1 files changed, 29 insertions, 31 deletions
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 <size> <random_opening_length> <depth>\n\n\
This binary is linked with both the include/weight_* files and the include/cand_weight_* files. It plays a single <size>x<size> game, with a random side choice and both sides using <random_opening_length> 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;
}