ucb1amaf_update: Fix nres type
[pachi/json.git] / mq.h
blob84357a0cc20de5c900b85f163f1cc9bbe8a5ea66
1 #ifndef ZZGO_MQ_H
2 #define ZZGO_MQ_H
4 /* Move queues; in fact, they are more like move lists, used to accumulate
5 * equally good move candidates, then choosing from them randomly. */
7 #include "move.h"
8 #include "random.h"
10 #define MQL 64
11 struct move_queue {
12 int moves;
13 coord_t move[MQL];
16 /* Pick a random move from the queue. */
17 static coord_t mq_pick(struct move_queue *q);
19 /* Add a move to the queue. */
20 static void mq_add(struct move_queue *q, coord_t c);
22 /* Cat two queues together. */
23 static void mq_append(struct move_queue *qd, struct move_queue *qs);
25 /* Check if the last move in queue is not a dupe, and remove it
26 * in that case. */
27 static void mq_nodup(struct move_queue *q);
29 /* Print queue contents on stderr. */
30 static void mq_print(struct move_queue *q, struct board *b, char *label);
33 static inline coord_t
34 mq_pick(struct move_queue *q)
36 return q->moves ? q->move[fast_random(q->moves)] : pass;
39 static inline void
40 mq_add(struct move_queue *q, coord_t c)
42 assert(q->moves < MQL);
43 q->move[q->moves++] = c;
46 static inline void
47 mq_append(struct move_queue *qd, struct move_queue *qs)
49 assert(qd->moves + qs->moves < MQL);
50 memcpy(&qd->move[qd->moves], qs->move, qs->moves * sizeof(*qs->move));
51 qd->moves += qs->moves;
54 static inline void
55 mq_nodup(struct move_queue *q)
57 if ((q->moves > 1 && q->move[q->moves - 2] == q->move[q->moves - 1])
58 || (q->moves > 2 && q->move[q->moves - 3] == q->move[q->moves - 1])
59 || (q->moves > 3 && q->move[q->moves - 4] == q->move[q->moves - 1]))
60 q->moves--;
63 static inline void
64 mq_print(struct move_queue *q, struct board *b, char *label)
66 fprintf(stderr, "%s candidate moves: ", label);
67 for (int i = 0; i < q->moves; i++) {
68 fprintf(stderr, "%s ", coord2sstr(q->move[i], b));
70 fprintf(stderr, "\n");
73 #endif