From 05b7089fabf08deb3fd30ed075152b518c1a7d59 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 7 Mar 2013 03:38:00 +0100 Subject: [PATCH] Split off BOARD_SPATPROB; board.spatprob is not interesting for us so far --- board.c | 17 ++++++++++++++--- board.h | 7 ++++++- patternprob.c | 4 ++-- uct/search.c | 10 ++++++++++ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/board.c b/board.c index d0aae91..e87d3ac 100644 --- a/board.c +++ b/board.c @@ -77,9 +77,12 @@ board_alloc(struct board *board) #endif #ifdef BOARD_SPATHASH int ssize = board_size2(board) * sizeof(*board->spathash); - int spsize = board_size2(board) * sizeof(*board->spatprob); #else int ssize = 0; +#endif +#ifdef BOARD_SPATPROB + int spsize = board_size2(board) * sizeof(*board->spatprob); +#else int spsize = 0; #endif #ifdef BOARD_PAT3 @@ -112,6 +115,8 @@ board_alloc(struct board *board) #endif #ifdef BOARD_SPATHASH board->spathash = x; x += ssize; +#endif +#ifdef BOARD_SPATPROB board->spatprob = x; x += spsize; #endif #ifdef BOARD_PAT3 @@ -258,7 +263,7 @@ board_init_data(struct board *board) /* Initialize spatial hashes. */ foreach_point(board) { for (int d = 1; d <= BOARD_SPATHASH_MAXD; d++) { - for (int j = ptind[d]; j < ptind[d + 1]; j++) { + for (unsigned int j = ptind[d]; j < ptind[d + 1]; j++) { ptcoords_at(x, y, c, board, j); board->spathash[coord_xy(board, x, y)][d - 1][0] ^= pthashes[0][j][board_at(board, c)]; @@ -266,6 +271,10 @@ board_init_data(struct board *board) pthashes[0][j][stone_other(board_at(board, c))]; } } + } foreach_point_end; +#endif +#ifdef BOARD_SPATPROB + foreach_point(board) { board->spatprob[c][0] = NAN; board->spatprob[c][1] = NAN; } foreach_point_end; @@ -482,7 +491,7 @@ board_hash_update(struct board *board, coord_t coord, enum stone color) /* Gridcular metric is reflective, so we update all hashes * of appropriate ditance in OUR circle. */ for (int d = 1; d <= BOARD_SPATHASH_MAXD; d++) { - for (int j = ptind[d]; j < ptind[d + 1]; j++) { + for (unsigned int j = ptind[d]; j < ptind[d + 1]; j++) { ptcoords_at(x, y, coord, board, j); /* We either changed from S_NONE to color * or vice versa; doesn't matter. */ @@ -490,8 +499,10 @@ board_hash_update(struct board *board, coord_t coord, enum stone color) pthashes[0][j][color] ^ pthashes[0][j][S_NONE]; board->spathash[coord_xy(board, x, y)][d - 1][1] ^= pthashes[0][j][stone_other(color)] ^ pthashes[0][j][S_NONE]; +#ifdef BOARD_SPATPROB board->spatprob[coord_xy(board, x, y)][0] = NAN; board->spatprob[coord_xy(board, x, y)][1] = NAN; +#endif } } #endif diff --git a/board.h b/board.h index a8dbc0e..5c5822b 100644 --- a/board.h +++ b/board.h @@ -27,8 +27,9 @@ struct fbook; //#define BOARD_SIZE 9 // constant board size, allows better optimization -// #define BOARD_SPATHASH // incremental patternsp.h hashes +//#define BOARD_SPATHASH // incremental patternsp.h hashes #define BOARD_SPATHASH_MAXD 5 // maximal diameter +//#define BOARD_SPATPROB // pattern probability cache #define BOARD_PAT3 // incremental 3x3 pattern codes @@ -193,10 +194,14 @@ struct board { * ([][1], reversed stone colors since we match all patterns as * black-to-play). */ uint32_t (*spathash)[BOARD_SPATHASH_MAXD][2]; +#endif +#ifdef BOARD_SPATPROB /* Probability of given pattern being played by either player * (non-normalized). This is just a cache, by default filled * with NAN. It is not cleared on liberty-related feature * changes. */ + /* XXX: This is useless for local followup selection as each + * move will clear cache of probabilities in the local area. */ floating_t (*spatprob)[2]; #endif #ifdef BOARD_PAT3 diff --git a/patternprob.c b/patternprob.c index fa92b3f..4d00cee 100644 --- a/patternprob.c +++ b/patternprob.c @@ -108,14 +108,14 @@ pattern_rate_some_moves(struct pattern_setup *pat, continue; if (!pats) { -#ifdef BOARD_SPATHASH +#ifdef BOARD_SPATPROB probs[f] = b->spatprob[coords[f]][color - 1]; #endif if (isnan(probs[f])) { struct pattern tmppat; pattern_match(&pat->pc, pat->ps, &tmppat, b, &mo); probs[f] = pattern_prob(pat->pd, &tmppat); -#ifdef BOARD_SPATHASH +#ifdef BOARD_SPATPROB b->spatprob[coords[f]][color - 1] = probs[f]; #endif } diff --git a/uct/search.c b/uct/search.c index 87434b5..a2a5756 100644 --- a/uct/search.c +++ b/uct/search.c @@ -215,6 +215,16 @@ uct_search_start(struct uct *u, struct board *b, enum stone color, time_stop_conditions(ti, b, u->fuseki_end, u->yose_start, u->max_maintime_ratio, &s->stop); } +#ifdef BOARD_SPATPROB + /* Do an initial pattern match, information that can be shared by + * all the subsequent tree branches and playouts. */ + if (u->want_pat) { + floating_t probs[b->flen]; + pattern_rate_moves(&u->pat, b, S_BLACK, NULL, probs); + pattern_rate_moves(&u->pat, b, S_WHITE, NULL, probs); + } +#endif + /* Fire up the tree search thread manager, which will in turn * spawn the searching threads. */ assert(u->threads > 0); -- 2.11.4.GIT