From b15185054c042153d0cf1b71ceb5c48dd4d18a13 Mon Sep 17 00:00:00 2001 From: tslil clingman Date: Wed, 20 Jan 2021 15:38:03 -0500 Subject: Can't stop half-way through turn --- src/ct1986.c | 2 +- src/ctaklm.c | 47 +++++++++++++++++++++++++---------------------- 2 files changed, 26 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/ct1986.c b/src/ct1986.c index b265b57..2e57ea6 100644 --- a/src/ct1986.c +++ b/src/ct1986.c @@ -167,7 +167,7 @@ main(int argc, char **argv) { if (lcd == NULL) return EXIT_FAILURE; human = 0; - search_depth = 3; + search_depth = 1; new_game(5); char *line = NULL; diff --git a/src/ctaklm.c b/src/ctaklm.c index eb2a788..24613e9 100644 --- a/src/ctaklm.c +++ b/src/ctaklm.c @@ -309,28 +309,31 @@ ct1986_display_progress(const uint8_t depth) { static int ct1986_turn(const uint8_t search_depth) { - // Prepare progress bar - fputs("Computing [", stdout); - for (int k = 0; k < board_size * board_size; k++) putchar(' '); - fputs("]\033[26D",stdout); - fflush(stdout); - // Run the minimax - sum_depth = 0; num_check = 0; - float minimax = ct1986_generate(search_depth); - fputs("\033[1C ", stdout); - // Failed to find a move? - if ((minimax <= -infty && (ply & 1) == 1) - ||(minimax >= infty && (ply & 1) == 0)) { - puts("Opponent concedes!"); - return EXIT_FAILURE; + if (won == 0xFF) { + // Prepare progress bar + fputs("Computing [", stdout); + for (int k = 0; k < board_size * board_size; k++) putchar(' '); + fputs("]\033[26D",stdout); + fflush(stdout); + // Run the minimax + sum_depth = 0; num_check = 0; + float minimax = ct1986_generate(search_depth); + fputs("\033[1C ", stdout); + // Failed to find a move? + if (minimax <= -infty) { + puts("Opponent concedes!"); + return EXIT_FAILURE; + } else { + printf("Result: %s (%.2f, %.1e, %.2f)\n", + ct1986_ptn, + minimax*100.0, + num_check, + sum_depth/num_check); + handle_turn(ct1986_ptn); + return EXIT_SUCCESS; + } } else { - printf("Result: %s (%.2f, %.1e, %.2f)\n", - ct1986_ptn, - minimax*100.0, - num_check, - sum_depth/num_check); - handle_turn(ct1986_ptn); - return EXIT_SUCCESS; + return EXIT_FAILURE; } } @@ -415,7 +418,7 @@ main(int argc, char **argv) { (void)(argv); human = 0; - search_depth = 3; + search_depth = 1; new_game(5); char *line = NULL; -- cgit v1.2.3