diff options
Diffstat (limited to 'games')
-rw-r--r-- | games/gomoku/bdinit.c | 6 | ||||
-rw-r--r-- | games/gomoku/bdisp.c | 18 | ||||
-rw-r--r-- | games/gomoku/gomoku.h | 54 | ||||
-rw-r--r-- | games/gomoku/main.c | 35 | ||||
-rw-r--r-- | games/gomoku/makemove.c | 6 | ||||
-rw-r--r-- | games/gomoku/pickmove.c | 80 | ||||
-rw-r--r-- | games/gomoku/stoc.c | 13 |
7 files changed, 141 insertions, 71 deletions
diff --git a/games/gomoku/bdinit.c b/games/gomoku/bdinit.c index b3096c17690..475fa04dbb1 100644 --- a/games/gomoku/bdinit.c +++ b/games/gomoku/bdinit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bdinit.c,v 1.1 1996/12/16 06:56:07 downsj Exp $ */ +/* $OpenBSD: bdinit.c,v 1.2 1996/12/21 21:17:49 tholo Exp $ */ /* * Copyright (c) 1994 * The Regents of the University of California. All rights reserved. @@ -39,9 +39,10 @@ static char sccsid[] = "@(#)bdinit.c 8.2 (Berkeley) 5/3/95"; #endif /* not lint */ -#include <string.h> #include "gomoku.h" +#include <string.h> +void bdinit(bp) struct spotstr *bp; { @@ -168,6 +169,7 @@ bdinit(bp) * As pieces are played, it can make frames not overlap if there are no * common open spaces shared between the two frames. */ +void init_overlap() { register struct spotstr *sp1, *sp2; diff --git a/games/gomoku/bdisp.c b/games/gomoku/bdisp.c index 2642b801f53..d696a5d84e4 100644 --- a/games/gomoku/bdisp.c +++ b/games/gomoku/bdisp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bdisp.c,v 1.2 1996/12/20 00:22:19 downsj Exp $ */ +/* $OpenBSD: bdisp.c,v 1.3 1996/12/21 21:17:49 tholo Exp $ */ /* * Copyright (c) 1994 * The Regents of the University of California. All rights reserved. @@ -40,8 +40,8 @@ static char sccsid[] = "@(#)bdisp.c 8.2 (Berkeley) 5/3/95"; #endif /* not lint */ #include "gomoku.h" -#include <stdio.h> #include <curses.h> +#include <string.h> #define SCRNH 24 /* assume 24 lines for the moment */ #define SCRNW 80 /* assume 80 chars for the moment */ @@ -52,22 +52,20 @@ static char pcolor[] = "*O.?"; /* * Initialize screen display. */ +void cursinit() { - initscr(); noecho(); cbreak(); - leaveok(stdscr, TRUE); } /* * Restore screen display. */ +void cursfini() { - - leaveok(stdscr, FALSE); move(23, 0); clrtoeol(); refresh(); @@ -77,6 +75,7 @@ cursfini() /* * Initialize board display. */ +void bdisp_init() { register int i, j; @@ -108,6 +107,7 @@ bdisp_init() /* * Update who is playing whom. */ +void bdwho(update) int update; { @@ -131,6 +131,7 @@ bdwho(update) /* * Update the board display after a move. */ +void bdisp() { register int i, j, c; @@ -197,6 +198,7 @@ bdump(fp) /* * Display a transcript entry */ +void dislog(str) char *str; { @@ -217,6 +219,7 @@ dislog(str) /* * Display a question. */ +void ask(str) char *str; { @@ -229,12 +232,13 @@ ask(str) refresh(); } +int getline(buf, size) char *buf; int size; { register char *cp, *end; - register int c; + register int c = EOF; extern int interactive; cp = buf; diff --git a/games/gomoku/gomoku.h b/games/gomoku/gomoku.h index 52822a552f4..301592f1d12 100644 --- a/games/gomoku/gomoku.h +++ b/games/gomoku/gomoku.h @@ -1,4 +1,4 @@ -/* $OpenBSD: gomoku.h,v 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. @@ -37,6 +37,7 @@ * @(#)gomoku.h 8.2 (Berkeley) 5/3/95 */ +#include <stdio.h> #include <sys/types.h> /* board dimensions */ @@ -260,8 +261,53 @@ extern int movelog[BSZ * BSZ]; /* history of moves */ 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) diff --git a/games/gomoku/main.c b/games/gomoku/main.c index 6fbb3507418..9b5bd086939 100644 --- a/games/gomoku/main.c +++ b/games/gomoku/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.3 1996/12/20 00:22:21 downsj Exp $ */ +/* $OpenBSD: main.c,v 1.4 1996/12/21 21:17:51 tholo Exp $ */ /* * Copyright (c) 1994 * The Regents of the University of California. All rights reserved. @@ -45,16 +45,14 @@ static char copyright[] = static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95"; #endif /* not lint */ +#include "gomoku.h" #include <curses.h> #include <err.h> #include <signal.h> -#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> -#include "gomoku.h" - #define USER 0 /* get input from standard input */ #define PROGRAM 1 /* get input from program */ #define INPUTF 2 /* get input from a file */ @@ -78,17 +76,13 @@ int movelog[BSZ * BSZ]; /* log of all the moves */ int movenum; /* current move number */ char *plyr[2]; /* who's who */ -extern void quit(); -#ifdef DEBUG -extern void whatsup(); -#endif - +int main(argc, argv) int argc; char **argv; { char buf[128]; - int color, curmove, i, ch; + int color = BLACK, curmove = 0, i, ch; int input[2]; static char *fmt[2] = { "%3d %-6s", @@ -308,7 +302,7 @@ again: replay: ask("replay? "); if (getline(buf, sizeof(buf)) && - buf[0] == 'y' || buf[0] == 'Y') + (buf[0] == 'y' || buf[0] == 'Y')) goto again; if (strcmp(buf, "save") == 0) { FILE *fp; @@ -327,9 +321,11 @@ again: } } } - quit(); + quit(0); + /* NOTREACHED */ } +int readinput(fp) FILE *fp; { @@ -359,16 +355,16 @@ whatsup(signum) struct combostr *cbp; if (!interactive) - quit(); + quit(0); top: ask("cmd? "); if (!getline(fmtbuf, sizeof(fmtbuf))) - quit(); + quit(0); switch (*fmtbuf) { case '\0': goto top; case 'q': /* conservative quit */ - quit(); + quit(0); case 'd': /* set debug level */ debug = fmtbuf[1] - '0'; sprintf(fmtbuf, "Debug set to %d", debug); @@ -489,6 +485,7 @@ syntax: /* * Display debug info. */ +void dlog(str) char *str; { @@ -501,6 +498,7 @@ dlog(str) fprintf(stderr, "%s\n", str); } +void log(str) char *str; { @@ -513,8 +511,10 @@ log(str) printf("%s\n", str); } +/* ARGSUSED */ void -quit() +quit(sig) + int sig; { if (interactive) { bdisp(); /* show final board */ @@ -526,10 +526,11 @@ quit() /* * Die gracefully. */ +void panic(str) char *str; { fprintf(stderr, "%s: %s\n", prog, str); fputs("resign\n", stdout); - quit(); + quit(0); } diff --git a/games/gomoku/makemove.c b/games/gomoku/makemove.c index d48594063cc..2a4a27da00a 100644 --- a/games/gomoku/makemove.c +++ b/games/gomoku/makemove.c @@ -1,4 +1,4 @@ -/* $OpenBSD: makemove.c,v 1.1 1996/12/16 06:56:08 downsj Exp $ */ +/* $OpenBSD: makemove.c,v 1.2 1996/12/21 21:17:51 tholo Exp $ */ /* * Copyright (c) 1994 * The Regents of the University of California. All rights reserved. @@ -56,6 +56,7 @@ int weight[5] = { 0, 1, 7, 22, 100 }; * WIN The the winning move was just played. * TIE The game is a tie. */ +int makemove(us, mv) int us, mv; { @@ -213,13 +214,14 @@ makemove(us, mv) /* * fix up the overlap array due to updating spot osp. */ +void update_overlap(osp) struct spotstr *osp; { register struct spotstr *sp, *sp1, *sp2; register int i, f, r, r1, d, d1, n; int a, b, bmask, bmask1; - struct spotstr *esp; + struct spotstr *esp = NULL; char *str; for (r = 4; --r >= 0; ) { /* for each direction */ diff --git a/games/gomoku/pickmove.c b/games/gomoku/pickmove.c index 770dc50e29f..c0f5d53da16 100644 --- a/games/gomoku/pickmove.c +++ b/games/gomoku/pickmove.c @@ -1,4 +1,4 @@ -/* $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. @@ -39,12 +39,12 @@ 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) @@ -62,13 +62,13 @@ 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 */ +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) @@ -115,14 +115,14 @@ pickmove(us) } 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], @@ -162,6 +162,7 @@ pickmove(us) /* * Return true if spot 'sp' is better than spot 'sp1' for color 'us'. */ +int better(sp, sp1, us) struct spotstr *sp; struct spotstr *sp1; @@ -210,7 +211,7 @@ better(sp, sp1, us) #ifdef SVR4 return (rand() & 1); #else - return (random() & 1); + return ((int)random() & 1); #endif } @@ -222,6 +223,7 @@ int curlevel; /* implicit parameter to makecombo() */ * 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; { @@ -327,7 +329,7 @@ scanframes(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); @@ -406,13 +408,14 @@ scanframes(color) * 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; @@ -453,7 +456,7 @@ makecombo2(ocbp, osp, off, s) * 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; } @@ -500,7 +503,7 @@ makecombo2(ocbp, osp, off, s) ((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], @@ -515,7 +518,7 @@ makecombo2(ocbp, osp, off, s) makeempty(ncbp); /* add the new combo to the end of the list */ - appendcombo(ncbp, curcolor); + appendcombo(ncbp); } else { updatecombo(ncbp, curcolor); free(ncbp); @@ -537,6 +540,7 @@ makecombo2(ocbp, osp, off, s) * Scan the sorted list of frames and try to add a frame to * combinations of 'level' number of frames. */ +void addframes(level) int level; { @@ -637,6 +641,7 @@ addframes(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; @@ -647,10 +652,10 @@ makecombo(ocbp, osp, off, s) 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; @@ -748,7 +753,7 @@ makecombo(ocbp, osp, off, 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], @@ -785,11 +790,12 @@ 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 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; @@ -817,7 +823,7 @@ makeempty(ocbp) */ 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]; @@ -940,15 +946,15 @@ makeempty(ocbp) * 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 */ @@ -958,7 +964,7 @@ updatecombo(cbp, color) 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) { @@ -1030,9 +1036,9 @@ updatecombo(cbp, color) /* * Add combo to the end of the list. */ -appendcombo(cbp, color) +void +appendcombo(cbp) struct combostr *cbp; - int color; { struct combostr *pcbp, *ncbp; @@ -1060,6 +1066,7 @@ appendcombo(cbp, color) * 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; @@ -1067,8 +1074,8 @@ checkframes(cbp, fcbp, osp, s, vertices) 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; @@ -1076,8 +1083,8 @@ checkframes(cbp, fcbp, osp, s, vertices) 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]; @@ -1086,12 +1093,12 @@ checkframes(cbp, fcbp, osp, s, vertices) * 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); @@ -1134,7 +1141,7 @@ checkframes(cbp, fcbp, osp, s, vertices) vertices->o_link = 1; vertices->o_off = (n - tcbp->c_vertex) / dd[tcbp->c_dir]; - vertices->o_frameindex = index; + vertices->o_frameindex = idx; verts++; } } @@ -1197,6 +1204,7 @@ checkframes(cbp, fcbp, osp, s, vertices) * 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; @@ -1310,6 +1318,7 @@ inserted: /* * Print the combo into string 'str'. */ +void printcombo(cbp, str) struct combostr *cbp; char *str; @@ -1318,7 +1327,7 @@ printcombo(cbp, 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); @@ -1327,6 +1336,7 @@ printcombo(cbp, str) } #ifdef DEBUG +void markcombo(ocbp) struct combostr *ocbp; { @@ -1441,6 +1451,7 @@ markcombo(ocbp) } } +void clearcombo(cbp, open) struct combostr *cbp; int open; @@ -1461,6 +1472,7 @@ clearcombo(cbp, open) sp->s_flg &= mask; } +int list_eq(scbpp, cbpp, n) struct combostr **scbpp; struct combostr **cbpp; diff --git a/games/gomoku/stoc.c b/games/gomoku/stoc.c index 7e89b136490..69b1edcd0fe 100644 --- a/games/gomoku/stoc.c +++ b/games/gomoku/stoc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: stoc.c,v 1.1 1996/12/16 06:56:09 downsj Exp $ */ +/* $OpenBSD: stoc.c,v 1.2 1996/12/21 21:17:53 tholo Exp $ */ /* * Copyright (c) 1994 * The Regents of the University of California. All rights reserved. @@ -40,6 +40,7 @@ static char sccsid[] = "@(#)stoc.c 8.1 (Berkeley) 7/24/94"; #endif /* not lint */ #include "gomoku.h" +#include <stdlib.h> #include <ctype.h> char *letters = "<ABCDEFGHJKLMNOPQRST>"; @@ -49,10 +50,10 @@ struct mvstr { char *m_text; }; static struct mvstr mv[] = { - RESIGN, "resign", - RESIGN, "quit", - SAVE, "save", - -1, 0 + {RESIGN, "resign" }, + {RESIGN, "quit" }, + {SAVE, "save" }, + {-1, 0} }; /* @@ -75,6 +76,7 @@ stoc(s) /* * Turn the character form of a move into the spot number form. */ +int ctos(mp) char *mp; { @@ -94,6 +96,7 @@ ctos(mp) /* * Turn a letter into a number. */ +int lton(c) int c; { |