From ce690fccf402cec8c88916b4503076786e84f71f Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Mon, 30 Jul 2012 14:11:13 +0200 Subject: [PATCH] board_set_rules(): Offloaded name->ruleset conversion from gtp.c:kgs-rules --- board.c | 17 +++++++++++++++++ board.h | 4 ++++ gtp.c | 10 +--------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/board.c b/board.c index 9d97e35..2e2ca06 100644 --- a/board.c +++ b/board.c @@ -1582,3 +1582,20 @@ board_official_score(struct board *board, struct move_queue *q) return board->komi + board->handicap + scores[S_WHITE] - scores[S_BLACK]; } + +bool +board_set_rules(struct board *board, char *name) +{ + if (!strcasecmp(name, "japanese")) { + board->rules = RULES_JAPANESE; + } else if (!strcasecmp(name, "chinese")) { + board->rules = RULES_CHINESE; + } else if (!strcasecmp(name, "aga")) { + board->rules = RULES_AGA; + } else if (!strcasecmp(name, "new_zealand")) { + board->rules = RULES_NEW_ZEALAND; + } else { + return false; + } + return true; +} diff --git a/board.h b/board.h index b0b8709..e87002a 100644 --- a/board.h +++ b/board.h @@ -372,6 +372,10 @@ floating_t board_fast_score(struct board *board); struct move_queue; floating_t board_official_score(struct board *board, struct move_queue *mq); +/* Set board rules according to given string. Returns false in case + * of unknown ruleset name. */ +bool board_set_rules(struct board *board, char *name); + /** Iterators */ #define foreach_point(board_) \ diff --git a/gtp.c b/gtp.c index 644b4b1..26093dc 100644 --- a/gtp.c +++ b/gtp.c @@ -247,15 +247,7 @@ gtp_parse(struct board *board, struct engine *engine, struct time_info *ti, char } 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 { + if (!board_set_rules(board, arg)) { gtp_error(id, "unknown rules", NULL); return P_OK; } -- 2.11.4.GIT