From 2a7b485265997d62625dc0ee5d8e91ede1c5f99f Mon Sep 17 00:00:00 2001 From: tslil Date: Thu, 14 Jan 2021 13:00:18 -0500 Subject: So after a small tweak, it actually plays well! --- include/ct1986.c | 10 ++++++---- include/ct1986.h | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/ct1986.c b/include/ct1986.c index 706640e..8378f8c 100644 --- a/include/ct1986.c +++ b/include/ct1986.c @@ -4,6 +4,7 @@ // Globals // =================================================================== +const float infty = 3.0; char ct1986_ptn[9]; void (*ct1986_display_progress)(const uint8_t); @@ -121,16 +122,17 @@ previous_ply(void) { if ((min == 0) && (w == WIN_ROAD_BLACK \ || w == WIN_FLAT_BLACK \ || w == WIN_DRAGON)) { \ - this = +3; \ + this = infty; \ } else if ((min > 0) \ && (w == WIN_ROAD_WHITE \ || w == WIN_FLAT_WHITE \ || w == WIN_DRAGON)) { \ - this = -3; \ + this = -infty; \ } /* Otherwise decide what to do based on our depth */ \ } else if (cur_depth == max_depth) { \ /* We're at the bottom, evaluate */ \ this = ct1986_evaluate_black_win(); \ + if (min == 0) this = this - 1.0;\ } else { \ /* We're not at the bottom, recurse first */ \ next_ply(); \ @@ -160,7 +162,7 @@ ct1986_minimax(const uint8_t cur_depth, const uint8_t max_depth, black_count_backup = black_count; // 1.0 is a `certain' black win, -1.0 is a `certain' white win. - float this = 0, optimal = (min) ? 2.0 : -2.0; + float this = 0, optimal = (min) ? infty : -infty; // Step across the board for (uint8_t row = 0; row < board_size; row++) { @@ -269,5 +271,5 @@ ct1986_minimax(const uint8_t cur_depth, const uint8_t max_depth, inline float ct1986_generate(const uint8_t max_depth) { - return ct1986_minimax(0, max_depth, 0, -10, 10); + return ct1986_minimax(0, max_depth, (ply & 1) ? 0 : 1, -infty, infty); } diff --git a/include/ct1986.h b/include/ct1986.h index ef56c1f..3f2568d 100644 --- a/include/ct1986.h +++ b/include/ct1986.h @@ -2,6 +2,7 @@ #include "tak.h" #include "weights.h" +extern const float infty; extern char ct1986_ptn[9]; extern void (*ct1986_display_progress)(const uint8_t); -- cgit v1.2.3