Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games/gomoku gomoku: refine the type of some functions and v...



details:   https://anonhg.NetBSD.org/src/rev/3e147b38f5c0
branches:  trunk
changeset: 366525:3e147b38f5c0
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun May 29 17:01:42 2022 +0000

description:
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:

 games/gomoku/Makefile   |   3 ++-
 games/gomoku/bdisp.c    |   9 ++++-----
 games/gomoku/gomoku.h   |   4 ++--
 games/gomoku/main.c     |  20 ++++++++++----------
 games/gomoku/makemove.c |   7 +++----
 games/gomoku/pickmove.c |  43 +++++++++++++++++++++----------------------
 6 files changed, 42 insertions(+), 44 deletions(-)

diffs (truncated from 333 to 300 lines):

diff -r e86bf6231dc2 -r 3e147b38f5c0 games/gomoku/Makefile
--- a/games/gomoku/Makefile     Sun May 29 16:45:00 2022 +0000
+++ b/games/gomoku/Makefile     Sun May 29 17:01:42 2022 +0000
@@ -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 @@
 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 -r e86bf6231dc2 -r 3e147b38f5c0 games/gomoku/bdisp.c
--- a/games/gomoku/bdisp.c      Sun May 29 16:45:00 2022 +0000
+++ b/games/gomoku/bdisp.c      Sun May 29 17:01:42 2022 +0000
@@ -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 @@
 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 @@
        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 @@
  * 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 -r e86bf6231dc2 -r 3e147b38f5c0 games/gomoku/gomoku.h
--- a/games/gomoku/gomoku.h     Sun May 29 16:45:00 2022 +0000
+++ b/games/gomoku/gomoku.h     Sun May 29 17:01:42 2022 +0000
@@ -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 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 -r e86bf6231dc2 -r 3e147b38f5c0 games/gomoku/main.c
--- a/games/gomoku/main.c       Sun May 29 16:45:00 2022 +0000
+++ b/games/gomoku/main.c       Sun May 29 17:01:42 2022 +0000
@@ -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 @@
 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 @@
 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 @@
                    stoc(curmove));
        }
 
+       int outcome;
        if ((outcome = makemove(color, curmove)) != MOVEOK)
                return (struct outcome){ outcome, color };
 
@@ -398,7 +397,7 @@
        quit();
 }
 
-static int
+static spot_index
 readinput(FILE *fp)
 {
        int c;
@@ -420,8 +419,9 @@
 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 -r e86bf6231dc2 -r 3e147b38f5c0 games/gomoku/makemove.c
--- a/games/gomoku/makemove.c   Sun May 29 16:45:00 2022 +0000
+++ b/games/gomoku/makemove.c   Sun May 29 17:01:42 2022 +0000
@@ -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 -r e86bf6231dc2 -r 3e147b38f5c0 games/gomoku/pickmove.c
--- a/games/gomoku/pickmove.c   Sun May 29 16:45:00 2022 +0000
+++ b/games/gomoku/pickmove.c   Sun May 29 17:01:42 2022 +0000
@@ -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 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 @@
        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 @@
                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 @@
                                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 @@
  * 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 @@
             */
            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 @@
                }
 
                /* 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 @@
                 */
                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 @@
  * 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 @@
 updatecombo(struct combostr *cbp, int color)
 {
        struct combostr *tcbp;
-       int nframes, flags;
        union comboval cb;
 



Home | Main Index | Thread Index | Old Index