Source-Changes-HG archive

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

[src/trunk]: src/games/gomoku gomoku: don't use 'i' as special-purpose variab...



details:   https://anonhg.NetBSD.org/src/rev/86dd84fd3d73
branches:  trunk
changeset: 366514:86dd84fd3d73
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun May 29 14:37:44 2022 +0000

description:
gomoku: don't use 'i' as special-purpose variable name

No binary change.

diffstat:

 games/gomoku/bdinit.c   |  20 ++++++++--------
 games/gomoku/bdisp.c    |  46 ++++++++++++++++++++--------------------
 games/gomoku/gomoku.h   |   6 ++--
 games/gomoku/main.c     |  27 ++++++++++++-----------
 games/gomoku/makemove.c |  20 ++++++++--------
 games/gomoku/pickmove.c |  56 ++++++++++++++++++++++++------------------------
 6 files changed, 88 insertions(+), 87 deletions(-)

diffs (truncated from 539 to 300 lines):

diff -r 7e0595d6f517 -r 86dd84fd3d73 games/gomoku/bdinit.c
--- a/games/gomoku/bdinit.c     Sun May 29 14:01:57 2022 +0000
+++ b/games/gomoku/bdinit.c     Sun May 29 14:37:44 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bdinit.c,v 1.33 2022/05/29 14:01:57 rillig Exp $       */
+/*     $NetBSD: bdinit.c,v 1.34 2022/05/29 14:37:44 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.33 2022/05/29 14:01:57 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.34 2022/05/29 14:37:44 rillig Exp $");
 
 #include <string.h>
 #include "gomoku.h"
@@ -42,11 +42,11 @@
 static void init_overlap(void);
 
 static void
-init_spot_flags_and_fval(struct spotstr *sp, int i, int j)
+init_spot_flags_and_fval(struct spotstr *sp, int col, int row)
 {
 
        sp->s_flags = 0;
-       if (j < 5) {
+       if (row < 5) {
                /* directions 1, 2, 3 are blocked */
                sp->s_flags |= (BFLAG << 1) | (BFLAG << 2) |
                    (BFLAG << 3);
@@ -56,7 +56,7 @@
                sp->s_fval[WHITE][1].s = 0x600;
                sp->s_fval[WHITE][2].s = 0x600;
                sp->s_fval[WHITE][3].s = 0x600;
-       } else if (j == 5) {
+       } else if (row == 5) {
                /* five spaces, blocked on one side */
                sp->s_fval[BLACK][1].s = 0x500;
                sp->s_fval[BLACK][2].s = 0x500;
@@ -73,14 +73,14 @@
                sp->s_fval[WHITE][2].s = 0x401;
                sp->s_fval[WHITE][3].s = 0x401;
        }
-       if (i > (BSZ - 4)) {
+       if (col > (BSZ - 4)) {
                /* directions 0, 1 are blocked */
                sp->s_flags |= BFLAG | (BFLAG << 1);
                sp->s_fval[BLACK][0].s = 0x600;
                sp->s_fval[BLACK][1].s = 0x600;
                sp->s_fval[WHITE][0].s = 0x600;
                sp->s_fval[WHITE][1].s = 0x600;
-       } else if (i == (BSZ - 4)) {
+       } else if (col == (BSZ - 4)) {
                sp->s_fval[BLACK][0].s = 0x500;
                sp->s_fval[WHITE][0].s = 0x500;
                /* if direction 1 is not blocked */
@@ -91,12 +91,12 @@
        } else {
                sp->s_fval[BLACK][0].s = 0x401;
                sp->s_fval[WHITE][0].s = 0x401;
-               if (i < 5) {
+               if (col < 5) {
                        /* direction 3 is blocked */
                        sp->s_flags |= (BFLAG << 3);
                        sp->s_fval[BLACK][3].s = 0x600;
                        sp->s_fval[WHITE][3].s = 0x600;
-               } else if (i == 5 &&
+               } else if (col == 5 &&
                    (sp->s_flags & (BFLAG << 3)) == 0) {
                        sp->s_fval[BLACK][3].s = 0x500;
                        sp->s_fval[WHITE][3].s = 0x500;
@@ -129,7 +129,7 @@
 {
 
        game.nmoves = 0;
-       game.winning_spot = 0;
+       game.win_spot = 0;
 
        struct spotstr *sp = board;
        for (int i = 0; i < 1 + BSZ + 1; i++, sp++) {
diff -r 7e0595d6f517 -r 86dd84fd3d73 games/gomoku/bdisp.c
--- a/games/gomoku/bdisp.c      Sun May 29 14:01:57 2022 +0000
+++ b/games/gomoku/bdisp.c      Sun May 29 14:37:44 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bdisp.c,v 1.51 2022/05/29 00:12:11 rillig Exp $        */
+/*     $NetBSD: bdisp.c,v 1.52 2022/05/29 14:37:44 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.51 2022/05/29 00:12:11 rillig Exp $");
+__RCSID("$NetBSD: bdisp.c,v 1.52 2022/05/29 14:37:44 rillig Exp $");
 
 #include <curses.h>
 #include <string.h>
@@ -98,15 +98,15 @@
 {
 
        /* top and bottom borders */
-       for (int i = 1; i < BSZ + 1; i++) {
-               mvaddch(scr_y(BSZ + 1), scr_x(i), letters[i]);
-               mvaddch(scr_y(0), scr_x(i), letters[i]);
+       for (int col = 1; col <= BSZ; col++) {
+               mvaddch(scr_y(BSZ + 1), scr_x(col), letters[col]);
+               mvaddch(scr_y(0), scr_x(col), letters[col]);
        }
 
        /* left and right edges */
-       for (int j = BSZ + 1; --j > 0; ) {
-               mvprintw(scr_y(j), 0, "%2d", j);
-               mvprintw(scr_y(j), scr_x(BSZ) + 2, "%d", j);
+       for (int row = BSZ; row >= 1; row--) {
+               mvprintw(scr_y(row), 0, "%2d", row);
+               mvprintw(scr_y(row), scr_x(BSZ) + 2, "%d", row);
        }
 
        bdwho();
@@ -154,9 +154,9 @@
 
        if (game.nmoves > 0 && game.moves[game.nmoves - 1] == s)
                return true;
-       if (game.winning_spot != 0)
-               for (int i = 0; i < 5; i++)
-                       if (s == game.winning_spot + i * dd[game.winning_dir])
+       if (game.win_spot != 0)
+               for (int off = 0; off < 5; off++)
+                       if (s == game.win_spot + off * dd[game.win_dir])
                                return true;
        return false;
 }
@@ -170,9 +170,9 @@
        int c;
        struct spotstr *sp;
 
-       for (int j = BSZ + 1; --j > 0; ) {
-               for (int i = 1; i < BSZ + 1; i++) {
-                       sp = &board[i + j * (BSZ + 1)];
+       for (int row = BSZ + 1; --row > 0; ) {
+               for (int col = 1; col <= BSZ; col++) {
+                       sp = &board[PT(col, row)];
                        if (debug > 1 && sp->s_occ == EMPTY) {
                                if ((sp->s_flags & IFLAGALL) != 0)
                                        c = '+';
@@ -183,8 +183,8 @@
                        } else
                                c = pcolor[sp->s_occ];
 
-                       move(scr_y(j), scr_x(i));
-                       if (should_highlight(PT(i, j))) {
+                       move(scr_y(row), scr_x(col));
+                       if (should_highlight(PT(col, row))) {
                                attron(A_BOLD);
                                addch(c);
                                attroff(A_BOLD);
@@ -208,11 +208,11 @@
        /* top border */
        fprintf(fp, "   A B C D E F G H J K L M N O P Q R S T\n");
 
-       for (int j = BSZ + 1; --j > 0; ) {
-               /* left edge */
-               fprintf(fp, "%2d ", j);
-               for (int i = 1; i < BSZ + 1; i++) {
-                       sp = &board[i + j * (BSZ + 1)];
+       for (int row = BSZ + 1; --row > 0; ) {
+               fprintf(fp, "%2d ", row);       /* left edge */
+
+               for (int col = 1; col <= BSZ; col++) {
+                       sp = &board[PT(col, row)];
                        if (debug > 1 && sp->s_occ == EMPTY) {
                                if ((sp->s_flags & IFLAGALL) != 0)
                                        c = '+';
@@ -225,8 +225,8 @@
                        putc(c, fp);
                        putc(' ', fp);
                }
-               /* right edge */
-               fprintf(fp, "%d\n", j);
+
+               fprintf(fp, "%d\n", row);       /* right edge */
        }
 
        /* bottom border */
diff -r 7e0595d6f517 -r 86dd84fd3d73 games/gomoku/gomoku.h
--- a/games/gomoku/gomoku.h     Sun May 29 14:01:57 2022 +0000
+++ b/games/gomoku/gomoku.h     Sun May 29 14:37:44 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gomoku.h,v 1.50 2022/05/29 13:49:10 rillig Exp $       */
+/*     $NetBSD: gomoku.h,v 1.51 2022/05/29 14:37:44 rillig Exp $       */
 
 /*
  * Copyright (c) 1994
@@ -226,8 +226,8 @@
 struct game {
        unsigned int    nmoves;         /* number of played moves */
        spot_index      moves[BSZ * BSZ]; /* log of all played moves */
-       spot_index      winning_spot;
-       direction       winning_dir;
+       spot_index      win_spot;       /* the winning move, or 0 */
+       direction       win_dir;
 };
 
 extern const char      letters[];
diff -r 7e0595d6f517 -r 86dd84fd3d73 games/gomoku/main.c
--- a/games/gomoku/main.c       Sun May 29 14:01:57 2022 +0000
+++ b/games/gomoku/main.c       Sun May 29 14:37:44 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.69 2022/05/29 10:37:21 rillig Exp $ */
+/*     $NetBSD: main.c,v 1.70 2022/05/29 14:37:44 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.69 2022/05/29 10:37:21 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.70 2022/05/29 14:37:44 rillig Exp $");
 
 #include <sys/stat.h>
 #include <curses.h>
@@ -115,8 +115,8 @@
                misclog("cannot create save file");
                return;
        }
-       for (unsigned int i = 0; i < game.nmoves; i++)
-               fprintf(fp, "%s\n", stoc(game.moves[i]));
+       for (unsigned int m = 0; m < game.nmoves; m++)
+               fprintf(fp, "%s\n", stoc(game.moves[m]));
        fclose(fp);
 }
 
@@ -420,7 +420,8 @@
 void
 whatsup(int signum __unused)
 {
-       int i, n, s1, s2, d1, d2;
+       int n, s1, s2, d1, d2, color;
+       spot_index s;
        struct spotstr *sp;
        FILE *fp;
        char *str;
@@ -455,9 +456,9 @@
                }
                goto top;
        case 's':               /* suggest a move */
-               i = input[1] == 'b' ? BLACK : WHITE;
-               debuglog("suggest %c %s", i == BLACK ? 'B' : 'W',
-                       stoc(pickmove(i)));
+               color = input[1] == 'b' ? BLACK : WHITE;
+               debuglog("suggest %c %s", color == BLACK ? 'B' : 'W',
+                       stoc(pickmove(color)));
                goto top;
        case 'f':               /* go forward a move */
                board[game.moves[game.nmoves]].s_occ =
@@ -510,16 +511,16 @@
                    stoc(s2), pdir[d2], overlap[n]);
                goto top;
        case 'p':
-               sp = &board[i = ctos(input + 1)];
-               debuglog("V %s %x/%d %d %x/%d %d %d %x", stoc(i),
+               sp = &board[s = ctos(input + 1)];
+               debuglog("V %s %x/%d %d %x/%d %d %d %x", stoc(s),
                        sp->s_combo[BLACK].s, sp->s_level[BLACK],
                        sp->s_nforce[BLACK],
                        sp->s_combo[WHITE].s, sp->s_level[WHITE],
                        sp->s_nforce[WHITE], sp->s_wval, sp->s_flags);
-               debuglog("FB %s %x %x %x %x", stoc(i),
+               debuglog("FB %s %x %x %x %x", stoc(s),
                        sp->s_fval[BLACK][0].s, sp->s_fval[BLACK][1].s,
                        sp->s_fval[BLACK][2].s, sp->s_fval[BLACK][3].s);
-               debuglog("FW %s %x %x %x %x", stoc(i),
+               debuglog("FW %s %x %x %x %x", stoc(s),
                        sp->s_fval[WHITE][0].s, sp->s_fval[WHITE][1].s,
                        sp->s_fval[WHITE][2].s, sp->s_fval[WHITE][3].s);
                goto top;
@@ -529,7 +530,7 @@
                        n = *str++ - '0';
                else
                        n = 0;
-               sp = &board[i = ctos(str)];
+               sp = &board[ctos(str)];
                for (ep = sp->s_empty; ep != NULL; ep = ep->e_next) {
                        cbp = ep->e_combo;
                        if (n != 0) {
diff -r 7e0595d6f517 -r 86dd84fd3d73 games/gomoku/makemove.c
--- a/games/gomoku/makemove.c   Sun May 29 14:01:57 2022 +0000
+++ b/games/gomoku/makemove.c   Sun May 29 14:37:44 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: makemove.c,v 1.39 2022/05/29 14:01:57 rillig Exp $     */
+/*     $NetBSD: makemove.c,v 1.40 2022/05/29 14:37:44 rillig Exp $     */
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 



Home | Main Index | Thread Index | Old Index