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. */
16 /* Each move can have an optional tag or set of tags.
17 * The usage of these is user-dependent. */
18 unsigned char tag
[MQL
];
21 /* Pick a random move from the queue. */
22 static coord_t
mq_pick(struct move_queue
*q
);
24 /* Add a move to the queue. */
25 static void mq_add(struct move_queue
*q
, coord_t c
, unsigned char tag
);
27 /* Cat two queues together. */
28 static void mq_append(struct move_queue
*qd
, struct move_queue
*qs
);
30 /* Check if the last move in queue is not a dupe, and remove it
32 static void mq_nodup(struct move_queue
*q
);
34 /* Print queue contents on stderr. */
35 static void mq_print(struct move_queue
*q
, struct board
*b
, char *label
);
39 mq_pick(struct move_queue
*q
)
41 return q
->moves
? q
->move
[fast_random(q
->moves
)] : pass
;
45 mq_add(struct move_queue
*q
, coord_t c
, unsigned char tag
)
47 assert(q
->moves
< MQL
);
48 q
->tag
[q
->moves
] = tag
;
49 q
->move
[q
->moves
++] = c
;
53 mq_append(struct move_queue
*qd
, struct move_queue
*qs
)
55 assert(qd
->moves
+ qs
->moves
< MQL
);
56 memcpy(&qd
->tag
[qd
->moves
], qs
->tag
, qs
->moves
* sizeof(*qs
->tag
));
57 memcpy(&qd
->move
[qd
->moves
], qs
->move
, qs
->moves
* sizeof(*qs
->move
));
58 qd
->moves
+= qs
->moves
;
62 mq_nodup(struct move_queue
*q
)
64 for (unsigned int i
= 1; i
< 4; i
++) {
67 if (q
->move
[q
->moves
- 1 - i
] == q
->move
[q
->moves
- 1]) {
68 q
->tag
[q
->moves
- 1 - i
] |= q
->tag
[q
->moves
- 1];
76 mq_print(struct move_queue
*q
, struct board
*b
, char *label
)
78 fprintf(stderr
, "%s candidate moves: ", label
);
79 for (unsigned int i
= 0; i
< q
->moves
; i
++) {
80 fprintf(stderr
, "%s ", coord2sstr(q
->move
[i
], b
));
82 fprintf(stderr
, "\n");