Module Name: src
Committed By: rillig
Date: Sun May 29 17:01:42 UTC 2022
Modified Files:
src/games/gomoku: Makefile bdisp.c gomoku.h main.c makemove.c
pickmove.c
Log Message:
gomoku: refine the type of some functions and variables
Assisted by WARNS=6. At that level, there are several warnings about
type conversion between small integer types that would only clutter the
code, therefore stay at WARNS=5. Same for lint's -aa option.
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/games/gomoku/Makefile
cvs rdiff -u -r1.54 -r1.55 src/games/gomoku/bdisp.c src/games/gomoku/gomoku.h
cvs rdiff -u -r1.70 -r1.71 src/games/gomoku/main.c
cvs rdiff -u -r1.41 -r1.42 src/games/gomoku/makemove.c
cvs rdiff -u -r1.61 -r1.62 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/Makefile
diff -u src/games/gomoku/Makefile:1.10 src/games/gomoku/Makefile:1.11
--- src/games/gomoku/Makefile:1.10 Sat May 21 14:55:26 2022
+++ src/games/gomoku/Makefile Sun May 29 17:01:42 2022
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.10 2022/05/21 14:55:26 rillig Exp $
+# $NetBSD: Makefile,v 1.11 2022/05/29 17:01:42 rillig Exp $
# @(#)Makefile 8.1 (Berkeley) 7/24/94
PROG= gomoku
@@ -9,6 +9,7 @@ LDADD= -lcurses -lterminfo
HIDEGAME=hidegame
CPPFLAGS+= ${DEBUG:D-DDEBUG}
+#WARNS= 6 # would produce warnings about small integer types
LINTFLAGS+= -w # treat warnings as errors
LINTFLAGS+= -T # strict bool mode
LINTFLAGS+= -e # strict enum checks
Index: src/games/gomoku/bdisp.c
diff -u src/games/gomoku/bdisp.c:1.54 src/games/gomoku/bdisp.c:1.55
--- src/games/gomoku/bdisp.c:1.54 Sun May 29 16:30:44 2022
+++ src/games/gomoku/bdisp.c Sun May 29 17:01:42 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: bdisp.c,v 1.54 2022/05/29 16:30:44 rillig Exp $ */
+/* $NetBSD: bdisp.c,v 1.55 2022/05/29 17:01:42 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.54 2022/05/29 16:30:44 rillig Exp $");
+__RCSID("$NetBSD: bdisp.c,v 1.55 2022/05/29 17:01:42 rillig Exp $");
#include <curses.h>
#include <string.h>
@@ -167,12 +167,12 @@ should_highlight(spot_index s)
void
bdisp(void)
{
- int c;
struct spotstr *sp;
for (int row = BSZ + 1; --row > 0; ) {
for (int col = 1; col <= BSZ; col++) {
sp = &board[PT(col, row)];
+ char c;
if (debug > 1 && sp->s_occ == EMPTY) {
if ((sp->s_flags & IFLAGALL) != 0)
c = '+';
@@ -285,7 +285,6 @@ get_line(char *buf, int size, void (*on_
char *cp, *end;
int c;
- c = 0;
cp = buf;
end = buf + size - 1; /* save room for the '\0' */
while ((c = getchar()) != EOF && c != '\n' && c != '\r') {
@@ -352,7 +351,7 @@ get_coord_mouse(int *x, int *y)
* Based on Eric S. Raymond's modifications to the battleship (bs) user
* interface.
*/
-int
+spot_index
get_coord(void)
{
int x = game.user_x, y = game.user_y;
Index: src/games/gomoku/gomoku.h
diff -u src/games/gomoku/gomoku.h:1.54 src/games/gomoku/gomoku.h:1.55
--- src/games/gomoku/gomoku.h:1.54 Sun May 29 16:30:44 2022
+++ src/games/gomoku/gomoku.h Sun May 29 17:01:42 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: gomoku.h,v 1.54 2022/05/29 16:30:44 rillig Exp $ */
+/* $NetBSD: gomoku.h,v 1.55 2022/05/29 17:01:42 rillig Exp $ */
/*
* Copyright (c) 1994
@@ -256,7 +256,7 @@ extern bool interactive;
extern const char *plyr[];
void init_board(void);
-int get_coord(void);
+spot_index get_coord(void);
int get_key(const char *);
bool get_line(char *, int, void (*)(const char *));
void ask(const char *);
Index: src/games/gomoku/main.c
diff -u src/games/gomoku/main.c:1.70 src/games/gomoku/main.c:1.71
--- src/games/gomoku/main.c:1.70 Sun May 29 14:37:44 2022
+++ src/games/gomoku/main.c Sun May 29 17:01:42 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.70 2022/05/29 14:37:44 rillig Exp $ */
+/* $NetBSD: main.c,v 1.71 2022/05/29 17:01:42 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.70 2022/05/29 14:37:44 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.71 2022/05/29 17:01:42 rillig Exp $");
#include <sys/stat.h>
#include <curses.h>
@@ -82,7 +82,7 @@ spot_index intersect[FAREA * FAREA]; /*
struct game game;
const char *plyr[2] = { "???", "???" }; /* who's who */
-static int readinput(FILE *);
+static spot_index readinput(FILE *);
static void misclog(const char *, ...) __printflike(1, 2);
static void quit(void) __dead;
#if !defined(DEBUG)
@@ -281,10 +281,8 @@ struct outcome {
static struct outcome
main_game_loop(enum input_source *input)
{
- int color, curmove, outcome;
-
- curmove = 0; /* for GCC */
- color = BLACK;
+ spot_index curmove = 0;
+ player_color color = BLACK;
again:
switch (input[color]) {
@@ -316,6 +314,7 @@ again:
stoc(curmove));
}
+ int outcome;
if ((outcome = makemove(color, curmove)) != MOVEOK)
return (struct outcome){ outcome, color };
@@ -398,7 +397,7 @@ again:
quit();
}
-static int
+static spot_index
readinput(FILE *fp)
{
int c;
@@ -420,8 +419,9 @@ readinput(FILE *fp)
void
whatsup(int signum __unused)
{
- int n, s1, s2, d1, d2, color;
- spot_index s;
+ int n, d1, d2;
+ player_color color;
+ spot_index s, s1, s2;
struct spotstr *sp;
FILE *fp;
char *str;
Index: src/games/gomoku/makemove.c
diff -u src/games/gomoku/makemove.c:1.41 src/games/gomoku/makemove.c:1.42
--- src/games/gomoku/makemove.c:1.41 Sun May 29 15:31:12 2022
+++ src/games/gomoku/makemove.c Sun May 29 17:01:42 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: makemove.c,v 1.41 2022/05/29 15:31:12 rillig Exp $ */
+/* $NetBSD: makemove.c,v 1.42 2022/05/29 17:01:42 rillig Exp $ */
/*
* Copyright (c) 1994
@@ -34,12 +34,11 @@
#include <sys/cdefs.h>
/* @(#)makemove.c 8.2 (Berkeley) 5/3/95 */
-__RCSID("$NetBSD: makemove.c,v 1.41 2022/05/29 15:31:12 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.42 2022/05/29 17:01:42 rillig Exp $");
#include "gomoku.h"
- /* direction deltas */
-const int dd[4] = {
+const int dd[4] = { /* direction deltas */
1, /* right */
-(BSZ + 1) + 1, /* down + right */
-(BSZ + 1), /* down */
Index: src/games/gomoku/pickmove.c
diff -u src/games/gomoku/pickmove.c:1.61 src/games/gomoku/pickmove.c:1.62
--- src/games/gomoku/pickmove.c:1.61 Sun May 29 15:31:12 2022
+++ src/games/gomoku/pickmove.c Sun May 29 17:01:42 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: pickmove.c,v 1.61 2022/05/29 15:31:12 rillig Exp $ */
+/* $NetBSD: pickmove.c,v 1.62 2022/05/29 17:01:42 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.61 2022/05/29 15:31:12 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.62 2022/05/29 17:01:42 rillig Exp $");
#include <stdlib.h>
#include <string.h>
@@ -70,14 +70,14 @@ static int nforce; /* count of opponen
static bool better(spot_index, spot_index, player_color);
static void scanframes(int);
-static void makecombo2(struct combostr *, struct spotstr *, int, int);
+static void makecombo2(struct combostr *, struct spotstr *, u_char, u_short);
static void addframes(unsigned int);
-static void makecombo(struct combostr *, struct spotstr *, int, int);
+static void makecombo(struct combostr *, struct spotstr *, u_char, u_short);
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 *);
+ u_short, struct overlap_info *);
static bool sortcombo(struct combostr **, struct combostr **, struct combostr *);
#if !defined(DEBUG)
static void printcombo(struct combostr *, char *, size_t);
@@ -256,7 +256,7 @@ scanframes(int color)
struct spotstr *sp;
union comboval *cp;
struct elist *nep;
- int off, r, n;
+ int r, n;
union comboval cb;
curcolor = color;
@@ -280,6 +280,7 @@ scanframes(int color)
sp = &board[cbp->c_vertex];
cp = &sp->s_fval[color][r = cbp->c_dir];
int delta = dd[r];
+ u_char off;
if (cp->cv_win != 0) {
/*
* Since this is the first spot of an open-ended
@@ -318,7 +319,7 @@ scanframes(int color)
if (color != nextcolor) {
/* XXX: suspicious use of 'n' */
n = (spot_index)(sp - board);
- BIT_SET(tmpmap, n);
+ BIT_SET(tmpmap, (spot_index)n);
}
}
/*
@@ -423,11 +424,10 @@ scanframes(int color)
* within the frame 'ocbp' and combo value 'cv'.
*/
static void
-makecombo2(struct combostr *ocbp, struct spotstr *osp, int off, int cv)
+makecombo2(struct combostr *ocbp, struct spotstr *osp, u_char off, u_short cv)
{
struct combostr *ncbp;
- int c;
- int baseB, fcnt, emask, n;
+ int baseB, fcnt, emask;
union comboval ocb, fcb;
struct combostr **scbpp, *fcbp;
char tmp[128];
@@ -451,7 +451,7 @@ makecombo2(struct combostr *ocbp, struct
*/
int bmask = (BFLAG | FFLAG | MFLAG) << r;
struct spotstr *fsp = osp;
- for (int f = 0; f < 5; f++, fsp -= d) { /* for each frame */
+ for (u_char f = 0; f < 5; f++, fsp -= d) { /* for each frame */
if (fsp->s_occ == BORDER)
break;
if ((fsp->s_flags & bmask) != 0)
@@ -473,10 +473,10 @@ makecombo2(struct combostr *ocbp, struct
}
/* compute combo value */
- c = fcb.cv_force + ocb.cv_force - 3;
+ int c = fcb.cv_force + ocb.cv_force - 3;
if (c > 4)
continue;
- n = fcb.cv_force + fcb.cv_win - 1;
+ int n = fcb.cv_force + fcb.cv_win - 1;
if (baseB < n)
n = baseB;
@@ -621,7 +621,7 @@ addframes(unsigned int level)
*/
int d = dd[r];
struct spotstr *sp = fsp + d;
- for (int off = 1; off < 5; off++, sp += d) {
+ for (u_char off = 1; off < 5; off++, sp += d) {
if (sp->s_occ != EMPTY)
continue;
makecombo(cbp, sp, off, fcb.s);
@@ -654,7 +654,7 @@ addframes(unsigned int level)
* within the frame 'ocbp' and combo value 'cv'.
*/
static void
-makecombo(struct combostr *ocbp, struct spotstr *osp, int off, int cv)
+makecombo(struct combostr *ocbp, struct spotstr *osp, u_char off, u_short cv)
{
struct combostr *cbp;
struct spotstr *sp;
@@ -966,13 +966,12 @@ static void
updatecombo(struct combostr *cbp, int color)
{
struct combostr *tcbp;
- int nframes, flags;
union comboval cb;
- flags = 0;
+ int flags = 0;
/* save the top level value for the whole combo */
cb.cv_force = cbp->c_combo.cv_force;
- nframes = cbp->c_nframes;
+ u_char nframes = cbp->c_nframes;
if (color != nextcolor)
memset(tmpmap, 0, sizeof(tmpmap));
@@ -1082,10 +1081,10 @@ appendcombo(struct combostr *cbp, int co
*/
static int
checkframes(struct combostr *cbp, struct combostr *fcbp, struct spotstr *osp,
- int cv, struct overlap_info *vertices)
+ u_short cv, struct overlap_info *vertices)
{
struct combostr *tcbp, *lcbp;
- int ovbit, n, mask, flags, verts, myindex, fcnt;
+ int ovbit, n, mask, flags, fcnt;
union comboval cb;
u_char *str;
@@ -1094,8 +1093,8 @@ checkframes(struct combostr *cbp, struct
cb.s = cv;
fcnt = cb.cv_force - 2;
- verts = 0;
- myindex = cbp->c_nframes;
+ int verts = 0;
+ u_char myindex = cbp->c_nframes;
n = (frame_index)(fcbp - frames) * FAREA;
str = &overlap[n];
spot_index *ip = &intersect[n];