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
);
31 mq_pick(struct move_queue
*q
)
33 return q
->moves
? q
->move
[fast_random(q
->moves
)] : pass
;
37 mq_nodup(struct move_queue
*q
)
39 if ((q
->moves
> 1 && q
->move
[q
->moves
- 2] == q
->move
[q
->moves
- 1])
40 || (q
->moves
> 2 && q
->move
[q
->moves
- 3] == q
->move
[q
->moves
- 1])
41 || (q
->moves
> 3 && q
->move
[q
->moves
- 4] == q
->move
[q
->moves
- 1]))
46 mq_append(struct move_queue
*qd
, struct move_queue
*qs
)
48 assert(qd
->moves
+ qs
->moves
< MQL
);
49 memcpy(&qd
->move
[qd
->moves
], qs
->move
, qs
->moves
* sizeof(*qs
->move
));
50 qd
->moves
+= qs
->moves
;
54 mq_add(struct move_queue
*q
, coord_t c
)
56 assert(q
->moves
< MQL
);
57 q
->move
[q
->moves
++] = c
;