4 /* Move queues; in fact, they are more like move lists, used to accumulate
5 * equally good move candidates, then choosing from them randomly. */
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
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
);
34 mq_pick(struct move_queue
*q
)
36 return q
->moves
? q
->move
[fast_random(q
->moves
)] : pass
;
40 mq_add(struct move_queue
*q
, coord_t c
)
42 assert(q
->moves
< MQL
);
43 q
->move
[q
->moves
++] = c
;
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
;
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]))
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");