Moggy mq: Move from playout/moggy.c to mq.h
[pachi/json.git] / mq.h
blob5112753d07686d6858e7ddfe3e13ab58590889bc
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"
9 #define MQL 64
10 struct move_queue {
11 int moves;
12 coord_t move[MQL];
15 /* Add a move to the queue. */
16 static void mq_add(struct move_queue *q, coord_t c);
18 /* Cat two queues together. */
19 static void mq_append(struct move_queue *qd, struct move_queue *qs);
21 /* Check if the last move in queue is not a dupe, and remove it
22 * in that case. */
23 static void mq_nodup(struct move_queue *q);
26 static inline void
27 mq_nodup(struct move_queue *q)
29 if ((q->moves > 1 && q->move[q->moves - 2] == q->move[q->moves - 1])
30 || (q->moves > 2 && q->move[q->moves - 3] == q->move[q->moves - 1])
31 || (q->moves > 3 && q->move[q->moves - 4] == q->move[q->moves - 1]))
32 q->moves--;
35 static inline void
36 mq_append(struct move_queue *qd, struct move_queue *qs)
38 assert(qd->moves + qs->moves < MQL);
39 memcpy(&qd->move[qd->moves], qs->move, qs->moves * sizeof(*qs->move));
40 qd->moves += qs->moves;
43 static inline void
44 mq_add(struct move_queue *q, coord_t c)
46 assert(q->moves < MQL);
47 q->move[q->moves++] = c;
50 #endif