From a64d11baeb138ea170b838c9d4faf83bbd81b946 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Wed, 10 Feb 2010 05:55:41 +0100 Subject: [PATCH] time_stop_conditions(): Simplify safety margin code --- timeinfo.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/timeinfo.c b/timeinfo.c index c49014a..3b1a289 100644 --- a/timeinfo.c +++ b/timeinfo.c @@ -194,6 +194,15 @@ time_stop_conditions(struct time_info *ti, struct board *b, int fuseki_end, int assert(ti->len.t.byoyomi_stones > 0); recommended_time = ti->len.t.byoyomi_time / ti->len.t.byoyomi_stones; + /* Use a larger safety margin if we risk losing on time on + * this move; it makes no sense to have 30s byoyomi and wait + * until 28s to play our move). */ + if (recommended_time >= max_time - net_lag) { + double safe_margin = RESERVED_BYOYOMI_PERCENT * recommended_time / 100; + if (safe_margin > net_lag) + net_lag = safe_margin; + } + } else { /* We are in main time. */ assert(ti->period == TT_TOTAL); @@ -238,16 +247,6 @@ time_stop_conditions(struct time_info *ti, struct board *b, int fuseki_end, int 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: */ - double safe_margin = RESERVED_BYOYOMI_PERCENT * ti->len.t.byoyomi_time/100; - if (safe_margin > 0) { - assert(ti->len.t.byoyomi_stones > 0); - safe_margin /= ti->len.t.byoyomi_stones; - } - if (safe_margin > MAX_NET_LAG && recommended_time >= max_time - net_lag) { - net_lag = safe_margin; - } - if (DEBUGL(1)) fprintf(stderr, "recommended_time %0.2f, max_time %0.2f, byoyomi %0.2f/%d, lag %0.2f\n", recommended_time, max_time, -- 2.11.4.GIT