-/* $NetBSD: pickmove.c,v 1.18 2009/06/04 07:01:16 dholland Exp $ */
+/* $NetBSD: pickmove.c,v 1.22 2013/10/19 17:23:08 christos Exp $ */
/*
* Copyright (c) 1994
#if 0
static char sccsid[] = "@(#)pickmove.c 8.2 (Berkeley) 5/3/95";
#else
-__RCSID("$NetBSD: pickmove.c,v 1.18 2009/06/04 07:01:16 dholland Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.22 2013/10/19 17:23:08 christos Exp $");
#endif
#endif /* not lint */
#define BIT_CLR(a, b) ((a)[(b)/BITS_PER_INT] &= ~(1 << ((b) % BITS_PER_INT)))
#define BIT_TEST(a, b) ((a)[(b)/BITS_PER_INT] & (1 << ((b) % BITS_PER_INT)))
-struct combostr *hashcombos[FAREA]; /* hash list for finding duplicates */
-struct combostr *sortcombos; /* combos at higher levels */
-int combolen; /* number of combos in sortcombos */
-int nextcolor; /* color of next move */
-int elistcnt; /* count of struct elist allocated */
-int combocnt; /* count of struct combostr allocated */
-int forcemap[MAPSZ]; /* map for blocking <1,x> combos */
-int tmpmap[MAPSZ]; /* map for blocking <1,x> combos */
-int nforce; /* count of opponent <1,x> combos */
+static struct combostr *hashcombos[FAREA];/* hash list for finding duplicates */
+static struct combostr *sortcombos; /* combos at higher levels */
+static int combolen; /* number of combos in sortcombos */
+static int nextcolor; /* color of next move */
+static int elistcnt; /* count of struct elist allocated */
+static int combocnt; /* count of struct combostr allocated */
+static int forcemap[MAPSZ]; /* map for blocking <1,x> combos */
+static int tmpmap[MAPSZ]; /* map for blocking <1,x> combos */
+static int nforce; /* count of opponent <1,x> combos */
+
+static int better(const struct spotstr *, const struct spotstr *, int);
+static void scanframes(int);
+static void makecombo2(struct combostr *, struct spotstr *, int, int);
+static void addframes(int);
+static void makecombo(struct combostr *, struct spotstr *, int, int);
+static void appendcombo(struct combostr *, int);
+static void updatecombo(struct combostr *, int);
+static void makeempty(struct combostr *);
+static int checkframes(struct combostr *, struct combostr *, struct spotstr *,
+ int, struct overlap_info *);
+static int sortcombo(struct combostr **, struct combostr **, struct combostr *);
+static void printcombo(struct combostr *, char *, size_t);
int
pickmove(int us)
{
struct spotstr *sp, *sp1, *sp2;
union comboval *Ocp, *Tcp;
+ unsigned pos;
int m;
/* first move is easy */
return (PT(K,10));
/* initialize all the board values */
- for (sp = &board[PT(T,20)]; --sp >= &board[PT(A,1)]; ) {
+ for (pos = PT(T,20); pos-- > PT(A,1); ) {
+ sp = &board[pos];
sp->s_combo[BLACK].s = MAXCOMBO + 1;
sp->s_combo[WHITE].s = MAXCOMBO + 1;
sp->s_level[BLACK] = 255;
scanframes(WHITE);
/* find the spot with the highest value */
- for (sp = sp1 = sp2 = &board[PT(T,19)]; --sp >= &board[PT(A,1)]; ) {
+ pos = PT(T,19);
+ sp1 = sp2 = &board[pos];
+ for ( ; pos-- > PT(A,1); ) {
+ sp = &board[pos];
if (sp->s_occ != EMPTY)
continue;
if (debug && (sp->s_combo[BLACK].c.a == 1 ||
/*
* Return true if spot 'sp' is better than spot 'sp1' for color 'us'.
*/
-int
+static int
better(const struct spotstr *sp, const struct spotstr *sp1, int us)
{
int them, s, s1;
if (sp->s_wval != sp1->s_wval)
return (0);
-#ifdef SVR4
- return (rand() & 1);
-#else
return (random() & 1);
-#endif
}
-int curcolor; /* implicit parameter to makecombo() */
-int curlevel; /* implicit parameter to makecombo() */
+static int curcolor; /* implicit parameter to makecombo() */
+static int curlevel; /* implicit parameter to makecombo() */
/*
* Scan the sorted list of non-empty frames and
* update the minimum combo values for each empty spot.
* Also, try to combine frames to find more complex (chained) moves.
*/
-void
+static void
scanframes(int color)
{
struct combostr *cbp, *ecbp;
struct elist *ep, *nep;
int i, r, d, n;
union comboval cb;
+ unsigned pos;
curcolor = color;
}
/* scan for combos at empty spots */
- for (sp = &board[PT(T,20)]; --sp >= &board[PT(A,1)]; ) {
+ for (pos = PT(T,20); pos-- > PT(A,1); ) {
+ sp = &board[pos];
for (ep = sp->s_empty; ep; ep = nep) {
cbp = ep->e_combo;
if (cbp->c_combo.s <= sp->s_combo[color].s) {
* Compute all level 2 combos of frames intersecting spot 'osp'
* within the frame 'ocbp' and combo value 's'.
*/
-void
+static void
makecombo2(struct combostr *ocbp, struct spotstr *osp, int off, int s)
{
struct spotstr *fsp;
* Scan the sorted list of frames and try to add a frame to
* combinations of 'level' number of frames.
*/
-void
+static void
addframes(int level)
{
struct combostr *cbp, *ecbp;
int i, r, d;
struct combostr **cbpp, *pcbp;
union comboval fcb, cb;
+ unsigned pos;
curlevel = level;
/* scan for combos at empty spots */
i = curcolor;
- for (sp = &board[PT(T,20)]; --sp >= &board[PT(A,1)]; ) {
+ for (pos = PT(T,20); pos-- > PT(A,1); ) {
+ sp = &board[pos];
for (ep = sp->s_empty; ep; ep = nep) {
cbp = ep->e_combo;
if (cbp->c_combo.s <= sp->s_combo[i].s) {
* Compute all level N combos of frames intersecting spot 'osp'
* within the frame 'ocbp' and combo value 's'.
*/
-void
+static void
makecombo(struct combostr *ocbp, struct spotstr *osp, int off, int s)
{
struct combostr *cbp, *ncbp;
struct overlap_info vertices[1];
char tmp[128];
+ /*
+ * XXX: when I made functions static gcc started warning about
+ * some members of vertices[0] maybe being used uninitialized.
+ * For now I'm just going to clear it rather than wade through
+ * the logic to find out whether gcc or the code is wrong. I
+ * wouldn't be surprised if it were the code though. - dholland
+ */
+ memset(vertices, 0, sizeof(vertices));
+
ocb.s = s;
baseB = ocb.c.a + ocb.c.b - 1;
fcnt = ocb.c.a - 2;
}
#define MAXDEPTH 100
-struct elist einfo[MAXDEPTH];
-struct combostr *ecombo[MAXDEPTH]; /* separate from elist to save space */
+static struct elist einfo[MAXDEPTH];
+static struct combostr *ecombo[MAXDEPTH]; /* separate from elist to save space */
/*
* Add the combostr 'ocbp' to the empty spots list for each empty spot
* in 'ocbp' that will complete the combo.
*/
-void
+static void
makeempty(struct combostr *ocbp)
{
struct combostr *cbp, *tcbp, **cbpp;
* We handle things differently depending on whether the next move
* would be trying to "complete" the combo or trying to block it.
*/
-void
+static void
updatecombo(struct combostr *cbp, int color)
{
struct spotstr *sp;
/*
* Add combo to the end of the list.
*/
-void
+static void
appendcombo(struct combostr *cbp, int color __unused)
{
struct combostr *pcbp, *ncbp;
* Return -1 if 'fcbp' should not be combined with 'cbp'.
* 's' is the combo value for frame 'fcpb'.
*/
-int
+static int
checkframes(struct combostr *cbp, struct combostr *fcbp, struct spotstr *osp,
int s, struct overlap_info *vertices)
{
struct combostr *tcbp, *lcbp;
- int i, n, mask, flags, verts, loop, myindex, fcnt;
+ int i, n, mask, flags, verts, myindex, fcnt;
union comboval cb;
u_char *str;
short *ip;
cb.s = s;
fcnt = cb.c.a - 2;
verts = 0;
- loop = 0;
myindex = cbp->c_nframes;
n = (fcbp - frames) * FAREA;
str = &overlap[n];
* Return true if this list of frames is already in the hash list.
* Otherwise, add the new combo to the hash list.
*/
-int
+static int
sortcombo(struct combostr **scbpp, struct combostr **cbpp,
struct combostr *fcbp)
{
/*
* Print the combo into string buffer 'buf'.
*/
-void
+static void
printcombo(struct combostr *cbp, char *buf, size_t max)
{
struct combostr *tcbp;