UCT dynkomi: Round the dynkomi value to integer before using it
[pachi.git] / mq.h
blob36230b32094f1a8adc5d587f1906a2675c8e7396
1 #ifndef ZZGO_MQ_H
2 #define ZZGO_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 256
13 struct move_queue {
14 int moves;
15 coord_t move[MQL];
18 /* Pick a random move from the queue. */
19 static coord_t mq_pick(struct move_queue *q);
21 /* Add a move to the queue. */
22 static void mq_add(struct move_queue *q, coord_t c);
24 /* Cat two queues together. */
25 static void mq_append(struct move_queue *qd, struct move_queue *qs);
27 /* Check if the last move in queue is not a dupe, and remove it
28 * in that case. */
29 static void mq_nodup(struct move_queue *q);
31 /* Print queue contents on stderr. */
32 static void mq_print(struct move_queue *q, struct board *b, char *label);
35 static inline coord_t
36 mq_pick(struct move_queue *q)
38 return q->moves ? q->move[fast_random(q->moves)] : pass;
41 static inline void
42 mq_add(struct move_queue *q, coord_t c)
44 assert(q->moves < MQL);
45 q->move[q->moves++] = c;
48 static inline void
49 mq_append(struct move_queue *qd, struct move_queue *qs)
51 assert(qd->moves + qs->moves < MQL);
52 memcpy(&qd->move[qd->moves], qs->move, qs->moves * sizeof(*qs->move));
53 qd->moves += qs->moves;
56 static inline void
57 mq_nodup(struct move_queue *q)
59 if ((q->moves > 1 && q->move[q->moves - 2] == q->move[q->moves - 1])
60 || (q->moves > 2 && q->move[q->moves - 3] == q->move[q->moves - 1])
61 || (q->moves > 3 && q->move[q->moves - 4] == q->move[q->moves - 1]))
62 q->moves--;
65 static inline void
66 mq_print(struct move_queue *q, struct board *b, char *label)
68 fprintf(stderr, "%s candidate moves: ", label);
69 for (int i = 0; i < q->moves; i++) {
70 fprintf(stderr, "%s ", coord2sstr(q->move[i], b));
72 fprintf(stderr, "\n");
75 #endif