uct_progress_json(): Merge back territstatus, chainstatus to boards.territory (per...
[pachi.git] / mq.h
blob3532f6cd8eea283daf45b425946a2f5d1bda2f4b
1 #ifndef PACHI_MQ_H
2 #define PACHI_MQ_H
4 /* Move queues; in fact, they are more like move lists, usually used
5 * to accumulate equally good move candidates, then choosing from them
6 * randomly. But they are also used to juggle group lists (using the
7 * fact that coord_t == group_t). */
9 #include "move.h"
10 #include "random.h"
12 #define MQL 512 /* XXX: On larger board this might not be enough. */
13 struct move_queue {
14 unsigned int moves;
15 coord_t move[MQL];
16 /* Each move can have an optional tag or set of tags.
17 * The usage of these is user-dependent. */
18 unsigned char tag[MQL];
21 /* Pick a random move from the queue. */
22 static coord_t mq_pick(struct move_queue *q);
24 /* Add a move to the queue. */
25 static void mq_add(struct move_queue *q, coord_t c, unsigned char tag);
27 /* Cat two queues together. */
28 static void mq_append(struct move_queue *qd, struct move_queue *qs);
30 /* Check if the last move in queue is not a dupe, and remove it
31 * in that case. */
32 static void mq_nodup(struct move_queue *q);
34 /* Print queue contents on stderr. */
35 static void mq_print(struct move_queue *q, struct board *b, char *label);
38 static inline coord_t
39 mq_pick(struct move_queue *q)
41 return q->moves ? q->move[fast_random(q->moves)] : pass;
44 static inline void
45 mq_add(struct move_queue *q, coord_t c, unsigned char tag)
47 assert(q->moves < MQL);
48 q->tag[q->moves] = tag;
49 q->move[q->moves++] = c;
52 static inline void
53 mq_append(struct move_queue *qd, struct move_queue *qs)
55 assert(qd->moves + qs->moves < MQL);
56 memcpy(&qd->tag[qd->moves], qs->tag, qs->moves * sizeof(*qs->tag));
57 memcpy(&qd->move[qd->moves], qs->move, qs->moves * sizeof(*qs->move));
58 qd->moves += qs->moves;
61 static inline void
62 mq_nodup(struct move_queue *q)
64 for (unsigned int i = 1; i < 4; i++) {
65 if (q->moves <= i)
66 return;
67 if (q->move[q->moves - 1 - i] == q->move[q->moves - 1]) {
68 q->tag[q->moves - 1 - i] |= q->tag[q->moves - 1];
69 q->moves--;
70 return;
75 static inline void
76 mq_print(struct move_queue *q, struct board *b, char *label)
78 fprintf(stderr, "%s candidate moves: ", label);
79 for (unsigned int i = 0; i < q->moves; i++) {
80 fprintf(stderr, "%s ", coord2sstr(q->move[i], b));
82 fprintf(stderr, "\n");
85 #endif