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). */
12 #define MQL 512 /* XXX: On larger board this might not be enough. */
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
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
);
36 mq_pick(struct move_queue
*q
)
38 return q
->moves
? q
->move
[fast_random(q
->moves
)] : pass
;
42 mq_add(struct move_queue
*q
, coord_t c
)
44 assert(q
->moves
< MQL
);
45 q
->move
[q
->moves
++] = c
;
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
;
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]))
66 mq_print(struct move_queue
*q
, struct board
*b
, char *label
)
68 fprintf(stderr
, "%s candidate moves: ", label
);
69 for (unsigned int i
= 0; i
< q
->moves
; i
++) {
70 fprintf(stderr
, "%s ", coord2sstr(q
->move
[i
], b
));
72 fprintf(stderr
, "\n");