Module Name: src Committed By: rillig Date: Sat May 28 08:19:19 UTC 2022
Modified Files: src/games/gomoku: bdinit.c bdisp.c gomoku.h main.c makemove.c pickmove.c Log Message: gomoku: group movelog and nmoves into a game struct No functional change. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/games/gomoku/bdinit.c cvs rdiff -u -r1.47 -r1.48 src/games/gomoku/bdisp.c cvs rdiff -u -r1.42 -r1.43 src/games/gomoku/gomoku.h cvs rdiff -u -r1.60 -r1.61 src/games/gomoku/main.c cvs rdiff -u -r1.31 -r1.32 src/games/gomoku/makemove.c cvs rdiff -u -r1.46 -r1.47 src/games/gomoku/pickmove.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/games/gomoku/bdinit.c diff -u src/games/gomoku/bdinit.c:1.22 src/games/gomoku/bdinit.c:1.23 --- src/games/gomoku/bdinit.c:1.22 Fri May 27 19:59:56 2022 +++ src/games/gomoku/bdinit.c Sat May 28 08:19:18 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: bdinit.c,v 1.22 2022/05/27 19:59:56 rillig Exp $ */ +/* $NetBSD: bdinit.c,v 1.23 2022/05/28 08:19:18 rillig Exp $ */ /* * Copyright (c) 1994 @@ -34,7 +34,7 @@ #include <sys/cdefs.h> /* from: @(#)bdinit.c 8.2 (Berkeley) 5/3/95 */ -__RCSID("$NetBSD: bdinit.c,v 1.22 2022/05/27 19:59:56 rillig Exp $"); +__RCSID("$NetBSD: bdinit.c,v 1.23 2022/05/28 08:19:18 rillig Exp $"); #include <string.h> #include "gomoku.h" @@ -47,7 +47,7 @@ bdinit(struct spotstr *bp) struct spotstr *sp; struct combostr *cbp; - nmoves = 0; + game.nmoves = 0; /* mark the borders as such */ sp = bp; Index: src/games/gomoku/bdisp.c diff -u src/games/gomoku/bdisp.c:1.47 src/games/gomoku/bdisp.c:1.48 --- src/games/gomoku/bdisp.c:1.47 Fri May 27 19:59:56 2022 +++ src/games/gomoku/bdisp.c Sat May 28 08:19:18 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: bdisp.c,v 1.47 2022/05/27 19:59:56 rillig Exp $ */ +/* $NetBSD: bdisp.c,v 1.48 2022/05/28 08:19:18 rillig Exp $ */ /* * Copyright (c) 1994 @@ -34,7 +34,7 @@ #include <sys/cdefs.h> /* @(#)bdisp.c 8.2 (Berkeley) 5/3/95 */ -__RCSID("$NetBSD: bdisp.c,v 1.47 2022/05/27 19:59:56 rillig Exp $"); +__RCSID("$NetBSD: bdisp.c,v 1.48 2022/05/28 08:19:18 rillig Exp $"); #include <curses.h> #include <string.h> @@ -171,7 +171,8 @@ bdisp(void) c = pcolor[sp->s_occ]; move(scr_y(j), scr_x(i)); - if (nmoves > 0 && movelog[nmoves - 1] == PT(i, j)) { + if (game.nmoves > 0 && + game.moves[game.nmoves - 1] == PT(i, j)) { attron(A_BOLD); addch(c); attroff(A_BOLD); Index: src/games/gomoku/gomoku.h diff -u src/games/gomoku/gomoku.h:1.42 src/games/gomoku/gomoku.h:1.43 --- src/games/gomoku/gomoku.h:1.42 Sat May 28 06:25:35 2022 +++ src/games/gomoku/gomoku.h Sat May 28 08:19:18 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: gomoku.h,v 1.42 2022/05/28 06:25:35 rillig Exp $ */ +/* $NetBSD: gomoku.h,v 1.43 2022/05/28 08:19:18 rillig Exp $ */ /* * Copyright (c) 1994 @@ -215,6 +215,11 @@ struct spotstr { #define BFLAG 0x010000 /* frame intersects border or dead */ #define BFLAGALL 0x0F0000 /* all frames dead */ +struct game { + int moves[BSZ * BSZ]; /* log of all played moves */ + unsigned int nmoves; /* number of played moves */ +}; + extern const char letters[]; extern const char pdir[]; @@ -224,8 +229,7 @@ extern struct combostr frames[FAREA]; / extern struct combostr *sortframes[2]; /* sorted, non-empty frames */ extern u_char overlap[FAREA * FAREA]; extern short intersect[FAREA * FAREA]; /* frame [a][b] intersection */ -extern int movelog[BSZ * BSZ]; -extern unsigned int nmoves; +extern struct game game; extern int debug; extern bool interactive; Index: src/games/gomoku/main.c diff -u src/games/gomoku/main.c:1.60 src/games/gomoku/main.c:1.61 --- src/games/gomoku/main.c:1.60 Sat May 28 06:25:35 2022 +++ src/games/gomoku/main.c Sat May 28 08:19:18 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.60 2022/05/28 06:25:35 rillig Exp $ */ +/* $NetBSD: main.c,v 1.61 2022/05/28 08:19:18 rillig Exp $ */ /* * Copyright (c) 1994 @@ -36,7 +36,7 @@ __COPYRIGHT("@(#) Copyright (c) 1994\ The Regents of the University of California. All rights reserved."); /* @(#)main.c 8.4 (Berkeley) 5/4/95 */ -__RCSID("$NetBSD: main.c,v 1.60 2022/05/28 06:25:35 rillig Exp $"); +__RCSID("$NetBSD: main.c,v 1.61 2022/05/28 08:19:18 rillig Exp $"); #include <sys/stat.h> #include <curses.h> @@ -79,8 +79,7 @@ struct combostr *sortframes[2]; /* sorte u_char overlap[FAREA * FAREA]; /* non-zero if frame [a][b] overlap; * see init_overlap */ short intersect[FAREA * FAREA]; /* frame [a][b] intersection */ -int movelog[BSZ * BSZ]; /* log of all played moves */ -unsigned int nmoves; /* number of played moves */ +struct game game; const char *plyr[2] = { "???", "???" }; /* who's who */ static int readinput(FILE *); @@ -116,8 +115,8 @@ save_game(void) misclog("cannot create save file"); return; } - for (unsigned int i = 0; i < nmoves; i++) - fprintf(fp, "%s\n", stoc(movelog[i])); + for (unsigned int i = 0; i < game.nmoves; i++) + fprintf(fp, "%s\n", stoc(game.moves[i])); fclose(fp); } @@ -313,7 +312,8 @@ again: if (interactive && curmove != ILLEGAL) { misclog("%3u%*s%-6s", - nmoves + 1, color == BLACK ? 2 : 9, "", stoc(curmove)); + game.nmoves + 1, color == BLACK ? 2 : 9, "", + stoc(curmove)); } if ((outcome = makemove(color, curmove)) != MOVEOK) @@ -448,9 +448,9 @@ top: case 'c': break; case 'b': /* back up a move */ - if (nmoves > 0) { - nmoves--; - board[movelog[nmoves]].s_occ = EMPTY; + if (game.nmoves > 0) { + game.nmoves--; + board[game.moves[game.nmoves]].s_occ = EMPTY; bdisp(); } goto top; @@ -460,23 +460,23 @@ top: stoc(pickmove(i))); goto top; case 'f': /* go forward a move */ - board[movelog[nmoves]].s_occ = - nmoves % 2 == 0 ? BLACK : WHITE; - nmoves++; + board[game.moves[game.nmoves]].s_occ = + game.nmoves % 2 == 0 ? BLACK : WHITE; + game.nmoves++; bdisp(); goto top; case 'l': /* print move history */ if (input[1] == '\0') { - for (unsigned int m = 0; m < nmoves; m++) - debuglog("%s", stoc(movelog[m])); + for (unsigned int m = 0; m < game.nmoves; m++) + debuglog("%s", stoc(game.moves[m])); goto top; } if ((fp = fopen(input + 1, "w")) == NULL) goto top; - for (unsigned int m = 0; m < nmoves; m++) { - fprintf(fp, "%s", stoc(movelog[m])); - if (++m < nmoves) - fprintf(fp, " %s\n", stoc(movelog[m])); + for (unsigned int m = 0; m < game.nmoves; m++) { + fprintf(fp, "%s", stoc(game.moves[m])); + if (++m < game.nmoves) + fprintf(fp, " %s\n", stoc(game.moves[m])); else fputc('\n', fp); } Index: src/games/gomoku/makemove.c diff -u src/games/gomoku/makemove.c:1.31 src/games/gomoku/makemove.c:1.32 --- src/games/gomoku/makemove.c:1.31 Sat May 28 08:09:22 2022 +++ src/games/gomoku/makemove.c Sat May 28 08:19:18 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: makemove.c,v 1.31 2022/05/28 08:09:22 rillig Exp $ */ +/* $NetBSD: makemove.c,v 1.32 2022/05/28 08:19:18 rillig Exp $ */ /* * Copyright (c) 1994 @@ -34,7 +34,7 @@ #include <sys/cdefs.h> /* @(#)makemove.c 8.2 (Berkeley) 5/3/95 */ -__RCSID("$NetBSD: makemove.c,v 1.31 2022/05/28 08:09:22 rillig Exp $"); +__RCSID("$NetBSD: makemove.c,v 1.32 2022/05/28 08:19:18 rillig Exp $"); #include "gomoku.h" @@ -111,7 +111,7 @@ makemove(int us, int mv) /* make move */ sp->s_occ = us; - movelog[nmoves++] = mv; + game.moves[game.nmoves++] = mv; /* compute new frame values */ sp->s_wval = 0; Index: src/games/gomoku/pickmove.c diff -u src/games/gomoku/pickmove.c:1.46 src/games/gomoku/pickmove.c:1.47 --- src/games/gomoku/pickmove.c:1.46 Fri May 27 23:10:54 2022 +++ src/games/gomoku/pickmove.c Sat May 28 08:19:18 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: pickmove.c,v 1.46 2022/05/27 23:10:54 rillig Exp $ */ +/* $NetBSD: pickmove.c,v 1.47 2022/05/28 08:19:18 rillig Exp $ */ /* * Copyright (c) 1994 @@ -34,7 +34,7 @@ #include <sys/cdefs.h> /* @(#)pickmove.c 8.2 (Berkeley) 5/3/95 */ -__RCSID("$NetBSD: pickmove.c,v 1.46 2022/05/27 23:10:54 rillig Exp $"); +__RCSID("$NetBSD: pickmove.c,v 1.47 2022/05/28 08:19:18 rillig Exp $"); #include <stdlib.h> #include <string.h> @@ -89,7 +89,7 @@ pickmove(int us) { /* first move is easy */ - if (nmoves == 0) + if (game.nmoves == 0) return PT((BSZ + 1) / 2, (BSZ + 1) / 2); /* initialize all the board values */ @@ -336,7 +336,7 @@ scanframes(int color) */ /* LINTED 117: bitwise '>>' on signed value possibly nonportable */ for (unsigned int level = 2; - level <= 1 + nmoves / 2 && combolen > n; level++) { + level <= 1 + game.nmoves / 2 && combolen > n; level++) { if (level >= 9) break; /* Do not think too long. */ if (debug != 0) {