From db27bb0c21e3c189352ccfb78a65fe66d6855cee Mon Sep 17 00:00:00 2001 From: Jean-loup Gailly Date: Sat, 8 May 2010 11:24:31 +0200 Subject: [PATCH] Distributed engine: Define board_bits2 and path2sstr --- board.c | 4 ++++ board.h | 11 +++++++++++ distributed/distributed.c | 26 ++++++++++++++++++++++++++ distributed/distributed.h | 9 +++++++++ uct/slave.c | 5 +++-- 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/board.c b/board.c index e1b83a7..d0fc7a6 100644 --- a/board.c +++ b/board.c @@ -148,6 +148,10 @@ board_resize(struct board *board, int size) #endif board->size = size + 2 /* S_OFFBOARD margin */; board->size2 = board_size(board) * board_size(board); + + board->bits2 = 1; + while ((1 << board->bits2) < board->size2) board->bits2++; + if (board->b) free(board->b); diff --git a/board.h b/board.h index 2b75d96..9a5f035 100644 --- a/board.h +++ b/board.h @@ -104,6 +104,7 @@ struct btraits { struct board { int size; /* Including S_OFFBOARD margin - see below. */ int size2; /* size^2 */ + int bits2; /* ceiling(log2(size2)) */ int captures[S_MAX]; float komi; int handicap; @@ -249,6 +250,16 @@ struct board { #define board_size2(b_) ((b_)->size2) #endif +#if BOARD_SIZE == 19 +# define board_bits2(b_) 9 +#elif BOARD_SIZE == 13 +# define board_bits2(b_) 8 +#elif BOARD_SIZE == 9 +# define board_bits2(b_) 7 +#else +# define board_bits2(b_) ((b_)->bits2) +#endif + #define board_at(b_, c) ((b_)->b[c]) #define board_atxy(b_, x, y) ((b_)->b[(x) + board_size(b_) * (y)]) diff --git a/distributed/distributed.c b/distributed/distributed.c index 1ee632f..215bcc7 100644 --- a/distributed/distributed.c +++ b/distributed/distributed.c @@ -100,6 +100,32 @@ static const struct time_info default_ti = { /* Maximum time (seconds) to wait for answers to genmoves. */ #define MAX_GENMOVES_WAIT 0.1 /* 100 ms */ + +/* Display a path as leaf> board_bits2(board)) +#define leaf_coord(path, board) ((path) & hash_mask(board_bits2(board))) +#define append_child(path, c, board) (((path) << board_bits2(board)) | (c)) + + /* Stats exchanged between master and slave. They are always * incremental values to be added to what was last sent. */ struct incr_stats { @@ -35,6 +43,7 @@ struct move_stats2 { struct move_stats amaf; }; +char *path2sstr(path_t path, struct board *b); struct engine *engine_distributed_init(char *arg, struct board *b); #endif diff --git a/uct/slave.c b/uct/slave.c index b1df4c2..8515058 100644 --- a/uct/slave.c +++ b/uct/slave.c @@ -76,8 +76,9 @@ receive_stats(struct uct *u, int size) return false; if (UDEBUGL(7)) - fprintf(stderr, "read %5d/%d %6d %.3f %"PRIpath"\n", n, nodes, - is.incr.playouts, is.incr.value, is.coord_path); + fprintf(stderr, "read %5d/%d %6d %.3f %"PRIpath" %s\n", n, nodes, + is.incr.playouts, is.incr.value, is.coord_path, + path2sstr(is.coord_path, u->t->board)); /* TODO: update the stats in the tree. */ } -- 2.11.4.GIT