Source-Changes-HG archive

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

[src/trunk]: src/games/gomoku gomoku: use proper types when indexing 'board' ...



details:   https://anonhg.NetBSD.org/src/rev/797940e8a3c3
branches:  trunk
changeset: 366507:797940e8a3c3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun May 29 11:36:12 2022 +0000

description:
gomoku: use proper types when indexing 'board' and 'frames'

No functional change.

diffstat:

 games/gomoku/bdinit.c   |   6 +++---
 games/gomoku/makemove.c |   6 +++---
 games/gomoku/pickmove.c |  19 ++++++++++---------
 3 files changed, 16 insertions(+), 15 deletions(-)

diffs (136 lines):

diff -r 89ef2c5b25c1 -r 797940e8a3c3 games/gomoku/bdinit.c
--- a/games/gomoku/bdinit.c     Sun May 29 11:18:33 2022 +0000
+++ b/games/gomoku/bdinit.c     Sun May 29 11:36:12 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bdinit.c,v 1.30 2022/05/29 10:37:21 rillig Exp $       */
+/*     $NetBSD: bdinit.c,v 1.31 2022/05/29 11:36:12 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.30 2022/05/29 10:37:21 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.31 2022/05/29 11:36:12 rillig Exp $");
 
 #include <string.h>
 #include "gomoku.h"
@@ -118,7 +118,7 @@
 
                struct combostr *cbp = &frames[fi];
                cbp->c_combo.s = sp->s_fval[BLACK][r].s;
-               cbp->c_vertex = (u_short)(sp - board);
+               cbp->c_vertex = (spot_index)(sp - board);
                cbp->c_nframes = 1;
                cbp->c_dir = r;
        }
diff -r 89ef2c5b25c1 -r 797940e8a3c3 games/gomoku/makemove.c
--- a/games/gomoku/makemove.c   Sun May 29 11:18:33 2022 +0000
+++ b/games/gomoku/makemove.c   Sun May 29 11:36:12 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: makemove.c,v 1.36 2022/05/29 10:37:21 rillig Exp $     */
+/*     $NetBSD: makemove.c,v 1.37 2022/05/29 11:36:12 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.36 2022/05/29 10:37:21 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.37 2022/05/29 11:36:12 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -155,7 +155,7 @@
 
                /* check for game over */
                if (n == 5) {
-                   game.winning_spot = (int)(fsp - board);
+                   game.winning_spot = (spot_index)(fsp - board);
                    game.winning_dir = r;
                    return WIN;
                }
diff -r 89ef2c5b25c1 -r 797940e8a3c3 games/gomoku/pickmove.c
--- a/games/gomoku/pickmove.c   Sun May 29 11:18:33 2022 +0000
+++ b/games/gomoku/pickmove.c   Sun May 29 11:36:12 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pickmove.c,v 1.53 2022/05/29 10:37:21 rillig Exp $     */
+/*     $NetBSD: pickmove.c,v 1.54 2022/05/29 11:36:12 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.53 2022/05/29 10:37:21 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.54 2022/05/29 11:36:12 rillig Exp $");
 
 #include <stdlib.h>
 #include <string.h>
@@ -308,7 +308,8 @@
                        if (cp->s == 0x101) {
                                sp->s_nforce[color]++;
                                if (color != nextcolor) {
-                                       n = (int)(sp - board);
+                                       /* XXX: suspicious use of 'n' */
+                                       n = (spot_index)(sp - board);
                                        BIT_SET(tmpmap, n);
                                }
                        }
@@ -493,7 +494,7 @@
                ncbp->c_linkv[1].s = fcb.s;
                ncbp->c_voff[0] = off;
                ncbp->c_voff[1] = f;
-               ncbp->c_vertex = (u_short)(osp - board);
+               ncbp->c_vertex = (spot_index)(osp - board);
                ncbp->c_nframes = 2;
                ncbp->c_dir = 0;
                ncbp->c_frameindex = 0;
@@ -681,7 +682,7 @@
 #ifdef DEBUG
                if (sp->s_occ != EMPTY) {
                    debuglog("loop: %c %s", "BW"[curcolor],
-                       stoc((int)(sp - board)));
+                       stoc((spot_index)(sp - board)));
                    whatsup(0);
                }
 #endif
@@ -732,7 +733,7 @@
            ncbp->c_link[1] = ocbp;
            ncbp->c_linkv[1].s = ocb.s;
            ncbp->c_voff[1] = off;
-           ncbp->c_vertex = (u_short)(osp - board);
+           ncbp->c_vertex = (spot_index)(osp - board);
            ncbp->c_nframes = cbp->c_nframes + 1;
            ncbp->c_flags = ocb.cv_win != 0 ? C_OPEN_1 : 0;
            ncbp->c_frameindex = ep->e_frameindex;
@@ -931,7 +932,7 @@
                        nep->e_fval.s = ep->e_fval.s;
                        if (debug > 2) {
                                debuglog("e %s o%d i%d c%d m%x %x",
-                                   stoc((int)(sp - board)),
+                                   stoc((spot_index)(sp - board)),
                                    nep->e_off,
                                    nep->e_frameindex,
                                    nep->e_framecnt,
@@ -1087,7 +1088,7 @@
        fcnt = cb.cv_force - 2;
        verts = 0;
        myindex = cbp->c_nframes;
-       n = (int)(fcbp - frames) * FAREA;
+       n = (frame_index)(fcbp - frames) * FAREA;
        str = &overlap[n];
        spot_index *ip = &intersect[n];
        /*
@@ -1248,7 +1249,7 @@
 inserted:
 
        /* now check to see if this list of frames has already been seen */
-       cbp = hashcombos[inx = (int)(*scbpp - frames)];
+       cbp = hashcombos[inx = (frame_index)(*scbpp - frames)];
        if (cbp == NULL) {
                /*
                 * Easy case, this list hasn't been seen.



Home | Main Index | Thread Index | Old Index