From d684096f8c1609f27d1a19ae34f4036de8b60ef0 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Wed, 10 Feb 2010 05:48:49 +0100 Subject: [PATCH] time_stop_conditions(): Merge max/recommended setup and TT_TOTAL processing --- timeinfo.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/timeinfo.c b/timeinfo.c index 37ecd28..c49014a 100644 --- a/timeinfo.c +++ b/timeinfo.c @@ -185,17 +185,24 @@ time_stop_conditions(struct time_info *ti, struct board *b, int fuseki_end, int double max_time; /* Ideal/reasonable time to spend on the move. */ double recommended_time; - /* Set up initial recommendations. */ + if (!ti->len.t.main_time) { + /* We are in byoyomi! */ + assert(ti->period == TT_MOVE); + max_time = ti->len.t.byoyomi_time; assert(ti->len.t.byoyomi_stones > 0); recommended_time = ti->len.t.byoyomi_time / ti->len.t.byoyomi_stones; + } else { + /* We are in main time. */ + assert(ti->period == TT_TOTAL); + max_time = recommended_time = ti->len.t.main_time; - } - if (ti->period == TT_TOTAL) { int moves_left = board_estimated_moves_left(b); + /* If we have byoyomi available, plan to extend our thinking + * time to make use of it. */ if (ti->len.t.byoyomi_time > 0) { assert(ti->len.t.byoyomi_stones > 0); /* Time for one move in byoyomi. */ @@ -225,14 +232,10 @@ time_stop_conditions(struct time_info *ti, struct board *b, int fuseki_end, int moves_left = 1; } } - ti->period = TT_MOVE; + recommended_time /= moves_left; } - // To simplify the engine code, do not leave negative times: - if (recommended_time < 0) - recommended_time = 0; - if (max_time < 0) - max_time = 0; + assert(recommended_time > 0 && max_time > 0); assert(recommended_time <= max_time + 0.001); /* Use a larger safety margin if we risk losing on time on this move: */ @@ -254,8 +257,6 @@ time_stop_conditions(struct time_info *ti, struct board *b, int fuseki_end, int /*** Setup desired/worst time limits based on recommended/max time. */ - assert(ti->period == TT_MOVE); - double desired_time = recommended_time; double worst_time; if (time_in_byoyomi(ti)) { -- 2.11.4.GIT