-/* $OpenBSD: gomoku.h,v 1.1.1.1 1996/12/16 06:56:08 downsj Exp $ */
+/* $OpenBSD: gomoku.h,v 1.2 1996/12/21 21:17:50 tholo Exp $ */
/*
* Copyright (c) 1994
* The Regents of the University of California. All rights reserved.
* @(#)gomoku.h 8.2 (Berkeley) 5/3/95
*/
+#include <stdio.h>
#include <sys/types.h>
/* board dimensions */
extern int movenum;
extern int debug;
-extern char *copy();
-extern char *stoc();
-extern char *tail();
+extern void addframes __P((int));
+extern void appendcombo __P((struct combostr *));
+extern void ask __P((char *));
+extern void bdinit __P((struct spotstr *));
+extern void bdisp __P((void));
+extern void bdisp_init __P((void));
+#ifdef DEBUG
+extern void bdump __P((FILE *));
+#endif
+extern void bdwho __P((int));
+extern int better __P((struct spotstr *, struct spotstr *, int));
+extern int checkframes __P((struct combostr *, struct combostr *,
+ struct spotstr *, int, struct ovlp_info *));
+#ifdef DEBUG
+extern void clearcombo __P((struct combostr *, int));
+#endif
+extern int ctos __P((char *));
+extern void cursfini __P((void));
+extern void cursinit __P((void));
+extern void dislog __P((char *));
+extern void dlog __P((char *));
+extern int getline __P((char *, int));
+extern void init_overlap __P((void));
+#ifdef DEBUG
+extern int list_eq __P((struct combostr **, struct combostr **, int));
+#endif
+extern void log __P((char *));
+extern int lton __P((int));
+extern void makecombo __P((struct combostr *, struct spotstr *, int, int));
+extern void makecombo2 __P((struct combostr *, struct spotstr *, int, int));
+extern void makeempty __P((struct combostr *));
+extern int makemove __P((int, int));
+#ifdef DEBUG
+extern void markcombo __P((struct combostr *));
+#endif
+extern void panic __P((char *));
+extern int pickmove __P((int));
+extern void printcombo __P((struct combostr *, char *));
+extern void quit __P((int));
+extern int readinput __P((FILE *));
+extern void scanframes __P((int));
+extern int sortcombo __P((struct combostr **, struct combostr **, struct combostr *));
+extern char *stoc __P((int));
+extern void updatecombo __P((struct combostr *, int));
+extern void update_overlap __P((struct spotstr *));
+#ifdef DEBUG
+extern void whatsup __P((int));
+#endif
#define ASSERT(x)
-/* $OpenBSD: pickmove.c,v 1.2 1996/12/20 00:22:23 downsj Exp $ */
+/* $OpenBSD: pickmove.c,v 1.3 1996/12/21 21:17:52 tholo Exp $ */
/*
* Copyright (c) 1994
* The Regents of the University of California. All rights reserved.
static char sccsid[] = "@(#)pickmove.c 8.2 (Berkeley) 5/3/95";
#endif /* not lint */
-#include <stdio.h>
+#include "gomoku.h"
+#include <stdlib.h>
+#include <string.h>
#include <curses.h>
#include <machine/limits.h>
-#include "gomoku.h"
-
#define BITS_PER_INT (sizeof(int) * CHAR_BIT)
#define MAPSZ (BAREA / BITS_PER_INT)
int tmpmap[MAPSZ]; /* map for blocking <1,x> combos */
int nforce; /* count of opponent <1,x> combos */
+int
pickmove(us)
int us;
{
register struct spotstr *sp, *sp1, *sp2;
register union comboval *Ocp, *Tcp;
- char *str;
- int i, j, m;
+ int m;
/* first move is easy */
if (movenum == 1)
}
if (debug) {
- sprintf(fmtbuf, "B %s %x/%d %d %x/%d %d %d %d",
+ sprintf(fmtbuf, "B %s %x/%d %d %x/%d %d %d",
stoc(sp1 - board),
sp1->s_combo[BLACK].s, sp1->s_level[BLACK],
sp1->s_nforce[BLACK],
sp1->s_combo[WHITE].s, sp1->s_level[WHITE],
sp1->s_nforce[WHITE], sp1->s_wval);
dlog(fmtbuf);
- sprintf(fmtbuf, "W %s %x/%d %d %x/%d %d %d %d",
+ sprintf(fmtbuf, "W %s %x/%d %d %x/%d %d %d",
stoc(sp2 - board),
sp2->s_combo[WHITE].s, sp2->s_level[WHITE],
sp2->s_nforce[WHITE],
/*
* Return true if spot 'sp' is better than spot 'sp1' for color 'us'.
*/
+int
better(sp, sp1, us)
struct spotstr *sp;
struct spotstr *sp1;
#ifdef SVR4
return (rand() & 1);
#else
- return (random() & 1);
+ return ((int)random() & 1);
#endif
}
* update the minimum combo values for each empty spot.
* Also, try to combine frames to find more complex (chained) moves.
*/
+void
scanframes(color)
int color;
{
* Limit the search depth early in the game.
*/
d = 2;
- while (d <= ((movenum + 1) >> 1) && combolen > n) {
+ while (d <= ((unsigned)(movenum + 1) >> 1) && combolen > n) {
if (debug) {
sprintf(fmtbuf, "%cL%d %d %d %d", "BW"[color],
d, combolen - n, combocnt, elistcnt);
* Compute all level 2 combos of frames intersecting spot 'osp'
* within the frame 'ocbp' and combo value 's'.
*/
+void
makecombo2(ocbp, osp, off, s)
struct combostr *ocbp;
struct spotstr *osp;
int off;
int s;
{
- register struct spotstr *sp, *fsp;
+ register struct spotstr *fsp;
register struct combostr *ncbp;
register int f, r, d, c;
int baseB, fcnt, emask, bmask, n;
* If this is the end point of the frame,
* use the closed ended value for the frame.
*/
- if (f == 0 && fcb.c.b || fcb.s == 0x101) {
+ if (f == 0 && (fcb.c.b || fcb.s == 0x101)) {
fcb.c.a++;
fcb.c.b = 0;
}
((fcb.c.b ? 0x1E : 0x1F) & ~(1 << f)) : 0;
combocnt++;
- if (c == 1 && debug > 1 || debug > 3) {
+ if (c == 1 && debug > 1) {
sprintf(fmtbuf, "%c c %d %d m %x %x o %d %d",
"bw"[curcolor],
ncbp->c_framecnt[0], ncbp->c_framecnt[1],
makeempty(ncbp);
/* add the new combo to the end of the list */
- appendcombo(ncbp, curcolor);
+ appendcombo(ncbp);
} else {
updatecombo(ncbp, curcolor);
free(ncbp);
* Scan the sorted list of frames and try to add a frame to
* combinations of 'level' number of frames.
*/
+void
addframes(level)
int level;
{
* Compute all level N combos of frames intersecting spot 'osp'
* within the frame 'ocbp' and combo value 's'.
*/
+void
makecombo(ocbp, osp, off, s)
struct combostr *ocbp;
struct spotstr *osp;
register struct spotstr *sp;
register struct elist *ep;
register int n, c;
- struct elist *nep, **epp;
+ struct elist *nep;
struct combostr **scbpp;
- int baseB, fcnt, emask, verts, d;
- union comboval ocb, cb;
+ int baseB, fcnt, emask, verts;
+ union comboval ocb;
struct ovlp_info vertices[1];
ocb.s = s;
ncbp->c_voff[0] = ep->e_off;
}
- if (c == 1 && debug > 1 || debug > 3) {
+ if (c == 1 && debug > 1) {
sprintf(fmtbuf, "%c v%d i%d d%d c %d %d m %x %x o %d %d",
"bw"[curcolor], verts, ncbp->c_frameindex, ncbp->c_dir,
ncbp->c_framecnt[0], ncbp->c_framecnt[1],
* Add the combostr 'ocbp' to the empty spots list for each empty spot
* in 'ocbp' that will complete the combo.
*/
+void
makeempty(ocbp)
struct combostr *ocbp;
{
- struct combostr *cbp, *tcbp, **cbpp;
- struct elist *ep, *nep, **epp;
+ struct combostr *cbp, **cbpp;
+ struct elist *ep, *nep;
struct spotstr *sp;
int s, d, m, emask, i;
int nframes;
*/
ep = &einfo[nframes];
cbpp = &ecombo[nframes];
- for (cbp = ocbp; tcbp = cbp->c_link[1]; cbp = cbp->c_link[0]) {
+ for (cbp = ocbp; cbp->c_link[1] != NULL; cbp = cbp->c_link[0]) {
ep--;
ep->e_combo = cbp;
*--cbpp = cbp->c_link[1];
* We handle things differently depending on whether the next move
* would be trying to "complete" the combo or trying to block it.
*/
+void
updatecombo(cbp, color)
struct combostr *cbp;
int color;
{
- register struct framestr *fp;
register struct spotstr *sp;
register struct combostr *tcbp;
register int i, d;
- int nframes, flg, s;
+ int nframes, s, flg = 0;
union comboval cb;
/* save the top level value for the whole combo */
if (color != nextcolor)
memset(tmpmap, 0, sizeof(tmpmap));
- for (; tcbp = cbp->c_link[1]; cbp = cbp->c_link[0]) {
+ for (; (tcbp = cbp->c_link[1]) != NULL; cbp = cbp->c_link[0]) {
flg = cbp->c_flg;
cb.c.b = cbp->c_combo.c.b;
if (color == nextcolor) {
/*
* Add combo to the end of the list.
*/
-appendcombo(cbp, color)
+void
+appendcombo(cbp)
struct combostr *cbp;
- int color;
{
struct combostr *pcbp, *ncbp;
* Return -1 if 'fcbp' should not be combined with 'cbp'.
* 's' is the combo value for frame 'fcpb'.
*/
+int
checkframes(cbp, fcbp, osp, s, vertices)
struct combostr *cbp;
struct combostr *fcbp;
int s;
struct ovlp_info *vertices;
{
- struct combostr *tcbp, *lcbp;
- int i, n, mask, flg, verts, loop, index, fcnt;
+ struct combostr *tcbp, *lcbp = NULL;
+ int i, n, mask, flg, verts, idx, fcnt;
union comboval cb;
u_char *str;
short *ip;
cb.s = s;
fcnt = cb.c.a - 2;
verts = 0;
- loop = 0;
- index = cbp->c_nframes;
+ flg = 0;
+ idx = cbp->c_nframes;
n = (fcbp - frames) * FAREA;
str = &overlap[n];
ip = &intersect[n];
* an open or closed frame.
*/
i = cb.c.b ? 2 : 0;
- for (; tcbp = cbp->c_link[1]; lcbp = cbp, cbp = cbp->c_link[0]) {
+ for (; (tcbp = cbp->c_link[1]) != NULL; lcbp = cbp, cbp = cbp->c_link[0]) {
if (tcbp == fcbp)
return (-1); /* fcbp is already included */
/* check for intersection of 'tcbp' with 'fcbp' */
- index--;
+ idx--;
mask = str[tcbp - frames];
flg = cbp->c_flg;
n = i + ((flg & C_OPEN_1) != 0);
vertices->o_link = 1;
vertices->o_off = (n - tcbp->c_vertex) /
dd[tcbp->c_dir];
- vertices->o_frameindex = index;
+ vertices->o_frameindex = idx;
verts++;
}
}
* Return true if this list of frames is already in the hash list.
* Otherwise, add the new combo to the hash list.
*/
+int
sortcombo(scbpp, cbpp, fcbp)
struct combostr **scbpp;
struct combostr **cbpp;
/*
* Print the combo into string 'str'.
*/
+void
printcombo(cbp, str)
struct combostr *cbp;
char *str;
sprintf(str, "%x/%d", cbp->c_combo.s, cbp->c_nframes);
str += strlen(str);
- for (; tcbp = cbp->c_link[1]; cbp = cbp->c_link[0]) {
+ for (; (tcbp = cbp->c_link[1]) != NULL; cbp = cbp->c_link[0]) {
sprintf(str, " %s%c%x", stoc(tcbp->c_vertex), pdir[tcbp->c_dir],
cbp->c_flg);
str += strlen(str);
}
#ifdef DEBUG
+void
markcombo(ocbp)
struct combostr *ocbp;
{
}
}
+void
clearcombo(cbp, open)
struct combostr *cbp;
int open;
sp->s_flg &= mask;
}
+int
list_eq(scbpp, cbpp, n)
struct combostr **scbpp;
struct combostr **cbpp;