diff options
| author | rillig <rillig@NetBSD.org> | 2022-05-29 17:01:42 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2022-05-29 17:01:42 +0000 |
| commit | 16dd548a7e497df17115db0854aa4d0959fad621 (patch) | |
| tree | 80cbd52dbcc957aa09287c0a2c68dabdf21bbee5 /games | |
| parent | 65bce800ec45a790db36a101e7b39d1464b8f329 (diff) | |
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.
Diffstat (limited to 'games')
| -rw-r--r-- | games/gomoku/Makefile | 3 | ||||
| -rw-r--r-- | games/gomoku/bdisp.c | 9 | ||||
| -rw-r--r-- | games/gomoku/gomoku.h | 4 | ||||
| -rw-r--r-- | games/gomoku/main.c | 20 | ||||
| -rw-r--r-- | games/gomoku/makemove.c | 7 | ||||
| -rw-r--r-- | games/gomoku/pickmove.c | 43 |
6 files changed, 42 insertions, 44 deletions
diff --git a/games/gomoku/Makefile b/games/gomoku/Makefile index b649b49dfd4..e064757e45a 100644 --- a/games/gomoku/Makefile +++ b/games/gomoku/Makefile @@ -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 diff --git a/games/gomoku/bdisp.c b/games/gomoku/bdisp.c index a9a8bae14a1..0cc78b9753e 100644 --- a/games/gomoku/bdisp.c +++ b/games/gomoku/bdisp.c @@ -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_change)(const char *)) 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; diff --git a/games/gomoku/gomoku.h b/games/gomoku/gomoku.h index c96ffc5edf1..2b71202b337 100644 --- a/games/gomoku/gomoku.h +++ b/games/gomoku/gomoku.h @@ -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 *); diff --git a/games/gomoku/main.c b/games/gomoku/main.c index a2412af977e..61d48ed2fa0 100644 --- a/games/gomoku/main.c +++ b/games/gomoku/main.c @@ -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]; /* frame [a][b] intersection */ 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; diff --git a/games/gomoku/makemove.c b/games/gomoku/makemove.c index 15e51afbfd6..d59728ecadc 100644 --- a/games/gomoku/makemove.c +++ b/games/gomoku/makemove.c @@ -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 */ diff --git a/games/gomoku/pickmove.c b/games/gomoku/pickmove.c index b6611e03ce5..543b29ef3ed 100644 --- a/games/gomoku/pickmove.c +++ b/games/gomoku/pickmove.c @@ -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 opponent <1,x> combos */ 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 spotstr *osp, int off, int cv) */ 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 spotstr *osp, int off, int cv) } /* 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 color __unused) */ 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 combostr *fcbp, struct spotstr *osp, 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]; |
