From 4dd3b9e46c9bf332cbd5ac5e9f5ee8a5c52e3503 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Mon, 5 Oct 2009 14:55:47 +0200 Subject: [PATCH] Moggy mq: Move from playout/moggy.c to mq.h --- mq.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ playout/moggy.c | 31 +------------------------------ 2 files changed, 51 insertions(+), 30 deletions(-) create mode 100644 mq.h diff --git a/mq.h b/mq.h new file mode 100644 index 0000000..5112753 --- /dev/null +++ b/mq.h @@ -0,0 +1,50 @@ +#ifndef ZZGO_MQ_H +#define ZZGO_MQ_H + +/* Move queues; in fact, they are more like move lists, used to accumulate + * equally good move candidates, then choosing from them randomly. */ + +#include "move.h" + +#define MQL 64 +struct move_queue { + int moves; + coord_t move[MQL]; +}; + +/* Add a move to the queue. */ +static void mq_add(struct move_queue *q, coord_t c); + +/* Cat two queues together. */ +static void mq_append(struct move_queue *qd, struct move_queue *qs); + +/* Check if the last move in queue is not a dupe, and remove it + * in that case. */ +static void mq_nodup(struct move_queue *q); + + +static inline void +mq_nodup(struct move_queue *q) +{ + if ((q->moves > 1 && q->move[q->moves - 2] == q->move[q->moves - 1]) + || (q->moves > 2 && q->move[q->moves - 3] == q->move[q->moves - 1]) + || (q->moves > 3 && q->move[q->moves - 4] == q->move[q->moves - 1])) + q->moves--; +} + +static inline void +mq_append(struct move_queue *qd, struct move_queue *qs) +{ + assert(qd->moves + qs->moves < MQL); + memcpy(&qd->move[qd->moves], qs->move, qs->moves * sizeof(*qs->move)); + qd->moves += qs->moves; +} + +static inline void +mq_add(struct move_queue *q, coord_t c) +{ + assert(q->moves < MQL); + q->move[q->moves++] = c; +} + +#endif diff --git a/playout/moggy.c b/playout/moggy.c index c03acc0..c0fc813 100644 --- a/playout/moggy.c +++ b/playout/moggy.c @@ -6,6 +6,7 @@ #define DEBUG #include "board.h" #include "debug.h" +#include "mq.h" #include "pattern3.h" #include "playout.h" #include "playout/moggy.h" @@ -29,36 +30,6 @@ struct moggy_policy { struct pattern3s patterns; }; -#define MQL 64 -struct move_queue { - int moves; - coord_t move[MQL]; -}; - -static void -mq_nodup(struct move_queue *q) -{ - if ((q->moves > 1 && q->move[q->moves - 2] == q->move[q->moves - 1]) - || (q->moves > 2 && q->move[q->moves - 3] == q->move[q->moves - 1]) - || (q->moves > 3 && q->move[q->moves - 4] == q->move[q->moves - 1])) - q->moves--; -} - -static void -mq_append(struct move_queue *qd, struct move_queue *qs) -{ - assert(qd->moves + qs->moves < MQL); - memcpy(&qd->move[qd->moves], qs->move, qs->moves * sizeof(*qs->move)); - qd->moves += qs->moves; -} - -static void -mq_add(struct move_queue *q, coord_t c) -{ - assert(q->moves < MQL); - q->move[q->moves++] = c; -} - static char moggy_patterns_src[][11] = { /* hane pattern - enclosing hane */ -- 2.11.4.GIT