From 71de9e76de8b74d2d1cb24dff3378eb09861fb20 Mon Sep 17 00:00:00 2001 From: Jean-loup Gailly Date: Sun, 5 Dec 2010 01:46:06 +0100 Subject: [PATCH] fbook: Fix for distributed mode --- fbook.c | 29 +++++++++++++++++++++++++++++ fbook.h | 1 + gtp.c | 34 +++++++--------------------------- uct/slave.c | 21 +++++++++++++-------- 4 files changed, 50 insertions(+), 35 deletions(-) diff --git a/fbook.c b/fbook.c index da08db8..59136f4 100644 --- a/fbook.c +++ b/fbook.c @@ -27,6 +27,35 @@ coord_transform(struct board *b, coord_t coord, int i) return coord; } +/* Check if we can make a move along the fbook right away. + * Otherwise return pass. */ +coord_t +fbook_check(struct board *board) +{ + if (!board->fbook) return pass; + + hash_t hi = board->hash; + coord_t cf = pass; + while (!is_pass(board->fbook->moves[hi & fbook_hash_mask])) { + if (board->fbook->hashes[hi & fbook_hash_mask] == board->hash) { + cf = board->fbook->moves[hi & fbook_hash_mask]; + break; + } + hi++; + } + if (!is_pass(cf)) { + if (DEBUGL(1)) + fprintf(stderr, "fbook match %"PRIhash":%"PRIhash"\n", board->hash, board->hash & fbook_hash_mask); + } else { + /* No match, also prevent further fbook usage + * until the next clear_board. */ + if (DEBUGL(4)) + fprintf(stderr, "fbook out %"PRIhash":%"PRIhash"\n", board->hash, board->hash & fbook_hash_mask); + fbook_done(board->fbook); + board->fbook = NULL; + } + return cf; +} struct fbook * fbook_init(char *filename, struct board *b) diff --git a/fbook.h b/fbook.h index 734251a..e7c580d 100644 --- a/fbook.h +++ b/fbook.h @@ -19,6 +19,7 @@ struct fbook { hash_t hashes[1<fbook) { - /* We have an fbook, check if we cannot make - * a move along it right away. */ - hash_t hi = board->hash; - coord_t cf = pass; - while (!is_pass(board->fbook->moves[hi & fbook_hash_mask])) { - if (board->fbook->hashes[hi & fbook_hash_mask] == board->hash) { - cf = board->fbook->moves[hi & fbook_hash_mask]; - break; - } - hi++; - } - if (!is_pass(cf)) { - if (DEBUGL(1)) - fprintf(stderr, "fbook match %"PRIhash":%"PRIhash"\n", board->hash, board->hash & fbook_hash_mask); - c = coord_copy(cf); - } else { - /* No match, also prevent further fbook usage - * until the next clear_board. */ - if (DEBUGL(4)) - fprintf(stderr, "fbook out %"PRIhash":%"PRIhash"\n", board->hash, board->hash & fbook_hash_mask); - fbook_done(board->fbook); - board->fbook = NULL; - } + coord_t cf = pass; + if (board->fbook) + cf = fbook_check(board); + if (!is_pass(cf)) { + c = coord_copy(cf); + } else { + c = engine->genmove(engine, board, &ti[color], color, !strcasecmp(cmd, "kgs-genmove_cleanup")); } - - if (!c) c = engine->genmove(engine, board, &ti[color], color, !strcasecmp(cmd, "kgs-genmove_cleanup")); - struct move m = { *c, color }; if (board_play(board, &m) < 0) { fprintf(stderr, "Attempted to generate an illegal move: [%s, %s]\n", coord2sstr(m.coord, board), stone2str(m.color)); diff --git a/uct/slave.c b/uct/slave.c index 5e5b5b9..c2dd6e9 100644 --- a/uct/slave.c +++ b/uct/slave.c @@ -37,6 +37,7 @@ #include "debug.h" #include "board.h" +#include "fbook.h" #include "gtp.h" #include "move.h" #include "timeinfo.h" @@ -525,14 +526,18 @@ uct_genmoves(struct engine *e, struct board *b, struct time_info *ti, enum stone uct_search_progress(u, b, color, u->t, ti, &s, played_games); u->played_own = played_games - s.base_playouts; - bool keep_looking = !uct_search_check_stop(u, b, color, u->t, ti, &s, played_games); - coord_t best_coord; - uct_search_result(u, b, color, pass_all_alive, played_games, s.base_playouts, &best_coord); - - if (u->shared_levels) { - *stats_buf = report_incr_stats(u, stats_size); - } else { - *stats_size = 0; + *stats_size = 0; + bool keep_looking = false; + coord_t best_coord = pass; + if (b->fbook) + best_coord = fbook_check(b); + if (best_coord == pass) { + keep_looking = !uct_search_check_stop(u, b, color, u->t, ti, &s, played_games); + uct_search_result(u, b, color, pass_all_alive, played_games, s.base_playouts, &best_coord); + + if (u->shared_levels) { + *stats_buf = report_incr_stats(u, stats_size); + } } char *reply = report_stats(u, b, best_coord, keep_looking, *stats_size); return reply; -- 2.11.4.GIT