Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/games/gomoku gomoku: group movelog and nmoves into a game st...
details: https://anonhg.NetBSD.org/src/rev/4c3e87132c4f
branches: trunk
changeset: 366464:4c3e87132c4f
user: rillig <rillig%NetBSD.org@localhost>
date: Sat May 28 08:19:18 2022 +0000
description:
gomoku: group movelog and nmoves into a game struct
No functional change.
diffstat:
games/gomoku/bdinit.c | 6 +++---
games/gomoku/bdisp.c | 7 ++++---
games/gomoku/gomoku.h | 10 +++++++---
games/gomoku/main.c | 38 +++++++++++++++++++-------------------
games/gomoku/makemove.c | 6 +++---
games/gomoku/pickmove.c | 8 ++++----
6 files changed, 40 insertions(+), 35 deletions(-)
diffs (244 lines):
diff -r 47bf5307cc20 -r 4c3e87132c4f games/gomoku/bdinit.c
--- a/games/gomoku/bdinit.c Sat May 28 08:09:22 2022 +0000
+++ b/games/gomoku/bdinit.c Sat May 28 08:19:18 2022 +0000
@@ -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 @@
struct spotstr *sp;
struct combostr *cbp;
- nmoves = 0;
+ game.nmoves = 0;
/* mark the borders as such */
sp = bp;
diff -r 47bf5307cc20 -r 4c3e87132c4f games/gomoku/bdisp.c
--- a/games/gomoku/bdisp.c Sat May 28 08:09:22 2022 +0000
+++ b/games/gomoku/bdisp.c Sat May 28 08:19:18 2022 +0000
@@ -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 @@
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);
diff -r 47bf5307cc20 -r 4c3e87132c4f games/gomoku/gomoku.h
--- a/games/gomoku/gomoku.h Sat May 28 08:09:22 2022 +0000
+++ b/games/gomoku/gomoku.h Sat May 28 08:19:18 2022 +0000
@@ -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 @@
#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 *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;
diff -r 47bf5307cc20 -r 4c3e87132c4f games/gomoku/main.c
--- a/games/gomoku/main.c Sat May 28 08:09:22 2022 +0000
+++ b/games/gomoku/main.c Sat May 28 08:19:18 2022 +0000
@@ -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 @@
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 @@
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 @@
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 @@
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 @@
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);
}
diff -r 47bf5307cc20 -r 4c3e87132c4f games/gomoku/makemove.c
--- a/games/gomoku/makemove.c Sat May 28 08:09:22 2022 +0000
+++ b/games/gomoku/makemove.c Sat May 28 08:19:18 2022 +0000
@@ -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 @@
/* make move */
sp->s_occ = us;
- movelog[nmoves++] = mv;
+ game.moves[game.nmoves++] = mv;
/* compute new frame values */
sp->s_wval = 0;
diff -r 47bf5307cc20 -r 4c3e87132c4f games/gomoku/pickmove.c
--- a/games/gomoku/pickmove.c Sat May 28 08:09:22 2022 +0000
+++ b/games/gomoku/pickmove.c Sat May 28 08:19:18 2022 +0000
@@ -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 @@
{
/* 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 @@
*/
/* 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) {
Home |
Main Index |
Thread Index |
Old Index