From 34267ac2c78229dba2f4eb3b8661e4a3c8c2f028 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 9 Sep 2010 18:56:05 +0200 Subject: [PATCH] MQ: Add support for tagging moves Not used anywhere yet, but Moggy will use it. --- distributed/distributed.c | 2 +- mq.h | 9 +++++++-- ownermap.c | 2 +- playout/moggy.c | 14 +++++++------- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/distributed/distributed.c b/distributed/distributed.c index 16d0baa..51a73c1 100644 --- a/distributed/distributed.c +++ b/distributed/distributed.c @@ -425,7 +425,7 @@ distributed_dead_group_list(struct engine *e, struct board *b, struct move_queue char *dead = gtp_replies[best_reply]; dead = strchr(dead, ' '); // skip "id " while (dead && *++dead != '\n') { - mq_add(mq, str2scoord(dead, board_size(b))); + mq_add(mq, str2scoord(dead, board_size(b)), 0); dead = strchr(dead, '\n'); } protocol_unlock(); diff --git a/mq.h b/mq.h index a6b673a..8f483df 100644 --- a/mq.h +++ b/mq.h @@ -13,13 +13,16 @@ struct move_queue { unsigned int moves; coord_t move[MQL]; + /* Each move can have an optional tag or set of tags. + * The usage of these is user-dependent. */ + unsigned char tag[MQL]; }; /* Pick a random move from the queue. */ static coord_t mq_pick(struct move_queue *q); /* Add a move to the queue. */ -static void mq_add(struct move_queue *q, coord_t c); +static void mq_add(struct move_queue *q, coord_t c, unsigned char tag); /* Cat two queues together. */ static void mq_append(struct move_queue *qd, struct move_queue *qs); @@ -39,9 +42,10 @@ mq_pick(struct move_queue *q) } static inline void -mq_add(struct move_queue *q, coord_t c) +mq_add(struct move_queue *q, coord_t c, unsigned char tag) { assert(q->moves < MQL); + q->tag[q->moves] = tag; q->move[q->moves++] = c; } @@ -49,6 +53,7 @@ static inline void mq_append(struct move_queue *qd, struct move_queue *qs) { assert(qd->moves + qs->moves < MQL); + memcpy(&qd->tag[qd->moves], qs->tag, qs->moves * sizeof(*qs->tag)); memcpy(&qd->move[qd->moves], qs->move, qs->moves * sizeof(*qs->move)); qd->moves += qs->moves; } diff --git a/ownermap.c b/ownermap.c index 8166581..c4218a0 100644 --- a/ownermap.c +++ b/ownermap.c @@ -96,6 +96,6 @@ groups_of_status(struct board *b, struct group_judgement *judge, enum gj_state s assert(judge->gs[g] != GS_NONE); if (judge->gs[g] == s) - mq_add(mq, g); + mq_add(mq, g, 0); } foreach_point_end; } diff --git a/playout/moggy.c b/playout/moggy.c index 385d06b..6fde0b5 100644 --- a/playout/moggy.c +++ b/playout/moggy.c @@ -252,7 +252,7 @@ apply_pattern_here(struct playout_policy *p, struct board *b, coord_t c, enum st { struct move m2 = { .coord = c, .color = color }; if (board_is_valid_move(b, &m2) && test_pattern3_here(p, b, &m2)) - mq_add(q, c); + mq_add(q, c, 0); } /* Check if we match any pattern around given move (with the other color to play). */ @@ -366,7 +366,7 @@ scan:; if (!q) { return true; } - mq_add(q, board_group_info(b, group_at(b, c)).lib[0]); + mq_add(q, board_group_info(b, group_at(b, c)).lib[0], 0); mq_nodup(q); }); } foreach_in_group_end; @@ -449,7 +449,7 @@ group_atari_check(struct playout_policy *p, struct board *b, group_t group, enum q->moves = qmoves_prev; } - mq_add(q, lib); + mq_add(q, lib, 0); mq_nodup(q); } @@ -467,7 +467,7 @@ joseki_check(struct playout_policy *p, struct board *b, enum stone to_play, stru for (; !is_pass(*cc); cc++) { if (coord_quadrant(*cc, b) != i) continue; - mq_add(q, *cc); + mq_add(q, *cc, 0); } } @@ -610,7 +610,7 @@ check_group_atari(struct board *b, group_t group, enum stone owner, continue; /* Tasty! Crispy! Good! */ - mq_add(q, lib); + mq_add(q, lib, 0); mq_nodup(q); } } @@ -642,7 +642,7 @@ group_2lib_check(struct playout_policy *p, struct board *b, group_t group, enum group_t g2 = group_at(b, c); if (board_group_info(b, g2).libs == 1) { /* We can capture a neighbor. */ - mq_add(q, board_group_info(b, g2).lib[0]); + mq_add(q, board_group_info(b, g2).lib[0], 0); continue; } if (board_group_info(b, g2).libs != 2) @@ -793,7 +793,7 @@ playout_moggy_fullchoose(struct playout_policy *p, struct board *b, enum stone t && pp->korate > fast_random(100)) { if (board_is_valid_play(b, to_play, b->last_ko.coord) && !is_bad_selfatari(b, to_play, b->last_ko.coord)) - mq_add(&q, b->last_ko.coord); + mq_add(&q, b->last_ko.coord, 0); } /* Local checks */ -- 2.11.4.GIT