From 37cdacb7e3f6b9d7e5825820995534c4ff4bfc73 Mon Sep 17 00:00:00 2001 From: Jean-loup Gailly Date: Mon, 15 Mar 2010 23:11:59 +0100 Subject: [PATCH] Support the "kgs-rules" gtp command. --- board.h | 6 ++++++ gtp.c | 18 ++++++++++++++++++ uct/uct.c | 6 ++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/board.h b/board.h index 8003069..141ee75 100644 --- a/board.h +++ b/board.h @@ -112,6 +112,12 @@ struct board { int captures[S_MAX]; float komi; int handicap; + enum { + RULES_AGA, + RULES_CHINESE, + RULES_NEW_ZEALAND, + RULES_JAPANESE, + } rules; /* Iterator offsets for foreach_neighbor*() */ int nei8[8], dnei[4]; diff --git a/gtp.c b/gtp.c index 643177c..b820373 100644 --- a/gtp.c +++ b/gtp.c @@ -127,6 +127,7 @@ gtp_parse(struct board *board, struct engine *engine, struct time_info *ti, char "clear_board\n" "kgs-game_over\n" "komi\n" + "kgs-rules\n" "play\n" "genmove\n" "kgs-genmove_cleanup\n" @@ -192,6 +193,23 @@ gtp_parse(struct board *board, struct engine *engine, struct time_info *ti, char board_print(board, stderr); gtp_reply(id, NULL); + } else if (!strcasecmp(cmd, "kgs-rules")) { + char *arg; + next_tok(arg); + if (!strcasecmp(arg, "japanese")) { + board->rules = RULES_JAPANESE; + } else if (!strcasecmp(arg, "chinese")) { + board->rules = RULES_CHINESE; + } else if (!strcasecmp(arg, "aga")) { + board->rules = RULES_AGA; + } else if (!strcasecmp(arg, "new_zealand")) { + board->rules = RULES_NEW_ZEALAND; + } else { + gtp_error(id, "unknown rules", NULL); + return P_OK; + } + gtp_reply(id, NULL); + } else if (!strcasecmp(cmd, "play")) { struct move m; diff --git a/uct/uct.c b/uct/uct.c index bc7c4ba..7d36d20 100644 --- a/uct/uct.c +++ b/uct/uct.c @@ -792,13 +792,15 @@ uct_genmove(struct engine *e, struct board *b, struct time_info *ti, enum stone u->t->use_extra_komi = !!(u->dynkomi_mask & color); setup_dynkomi(u, b, color); + if (b->rules == RULES_JAPANESE) + u->territory_scoring = true; + /* Make pessimistic assumption about komi for Japanese rules to * avoid losing by 0.5 when winning by 0.5 with Chinese rules. * The rules usually give the same winner if the integer part of komi * is odd so we adjust the komi only if it is even (for a board of * odd size). We are not trying to get an exact evaluation for rare - * cases of seki. For details see http://home.snafu.de/jasiek/parity.html - * TODO: Support the kgs-rules command once available. */ + * cases of seki. For details see http://home.snafu.de/jasiek/parity.html */ if (u->territory_scoring && (((int)floor(b->komi) + board_size(b)) & 1)) { b->komi += (color == S_BLACK ? 1.0 : -1.0); if (UDEBUGL(0)) -- 2.11.4.GIT