From fb5cae84198c540decd86ff0db15f33f652f5747 Mon Sep 17 00:00:00 2001 From: Jean-loup Gailly Date: Thu, 25 Mar 2010 22:12:16 +0100 Subject: [PATCH] Distributed engine: move time parsing to uct_genmoves to reduce engine dependencies in gtp.c. --- engine.h | 2 +- gtp.c | 15 +++++---------- uct/uct.c | 11 ++++++++++- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/engine.h b/engine.h index ea92add..d99ccd5 100644 --- a/engine.h +++ b/engine.h @@ -14,7 +14,7 @@ typedef char *(*engine_chat)(struct engine *e, struct board *b, char *cmd); * if all stones on the board can be considered alive, without regard to "dead" * considered stones. */ typedef coord_t *(*engine_genmove)(struct engine *e, struct board *b, struct time_info *ti, enum stone color, bool pass_all_alive); -typedef char *(*engine_genmoves)(struct engine *e, struct board *b, struct time_info *ti, enum stone color, bool pass_all_alive); +typedef char *(*engine_genmoves)(struct engine *e, struct board *b, struct time_info *ti, enum stone color, char *args, bool pass_all_alive); /* One dead group per queued move (coord_t is (ab)used as group_t). */ typedef void (*engine_dead_group_list)(struct engine *e, struct board *b, struct move_queue *mq); /* e->data and e will be free()d by caller afterwards. */ diff --git a/gtp.c b/gtp.c index b820373..a3c59bc 100644 --- a/gtp.c +++ b/gtp.c @@ -270,18 +270,13 @@ gtp_parse(struct board *board, struct engine *engine, struct time_info *ti, char char *arg; next_tok(arg); enum stone color = str2stone(arg); - struct time_info *myti = &ti[color]; - /* Get correct time from master. Keep this code in sync - * with distributed_genmove(). */ - if (myti->dim == TD_WALLTIME && - sscanf(next, "%lf %lf %d %d", &myti->len.t.main_time, - &myti->len.t.byoyomi_time, &myti->len.t.byoyomi_periods, - &myti->len.t.byoyomi_stones) != 4) { - gtp_error(id, "incorrect time info", NULL); + + char *reply = engine->genmoves(engine, board, &ti[color], color, next, + !strcasecmp(cmd, "pachi-genmoves_cleanup")); + if (!reply) { + gtp_error(id, "genmoves error", NULL); return P_OK; } - - char *reply = engine->genmoves(engine, board, myti, color, !strcasecmp(cmd, "pachi-genmoves_cleanup")); if (DEBUGL(2)) fprintf(stderr, "proposing moves %s\n", reply); if (DEBUGL(1)) { diff --git a/uct/uct.c b/uct/uct.c index dd40229..658d71e 100644 --- a/uct/uct.c +++ b/uct/uct.c @@ -914,13 +914,22 @@ uct_getstats(struct uct *u, struct board *b, coord_t *c) } static char * -uct_genmoves(struct engine *e, struct board *b, struct time_info *ti, enum stone color, bool pass_all_alive) +uct_genmoves(struct engine *e, struct board *b, struct time_info *ti, enum stone color, + char *args, bool pass_all_alive) { struct uct *u = e->data; assert(u->slave); coord_t *c = uct_genmove(e, b, ti, color, pass_all_alive); + /* Get correct time from master. Keep this code in sync with time_info(). */ + if (ti->dim == TD_WALLTIME + && sscanf(args, "%lf %lf %d %d", &ti->len.t.main_time, + &ti->len.t.byoyomi_time, &ti->len.t.byoyomi_periods, + &ti->len.t.byoyomi_stones) != 4) { + return NULL; + } + char *reply = uct_getstats(u, b, is_pass(*c) || is_resign(*c) ? c : NULL); coord_done(c); return reply; -- 2.11.4.GIT