Source-Changes-HG archive

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

[src/trunk]: src/games/gomoku gomoku: inline macros BSZ1, BSZ2, BSZ3, BSZ4



details:   https://anonhg.NetBSD.org/src/rev/f15fe9fe98e0
branches:  trunk
changeset: 366146:f15fe9fe98e0
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun May 15 22:56:20 2022 +0000

description:
gomoku: inline macros BSZ1, BSZ2, BSZ3, BSZ4

These macro names didn't convey any meaning, so replace them with their
replacement text, to have fewer identifiers to worry about.

No binary change.

diffstat:

 games/gomoku/bdinit.c |  14 +++++++-------
 games/gomoku/bdisp.c  |  40 ++++++++++++++++++++--------------------
 games/gomoku/gomoku.h |  16 ++++++----------
 games/gomoku/main.c   |  10 +++++-----
 games/gomoku/stoc.c   |   7 ++++---
 5 files changed, 42 insertions(+), 45 deletions(-)

diffs (290 lines):

diff -r fa73a93557be -r f15fe9fe98e0 games/gomoku/bdinit.c
--- a/games/gomoku/bdinit.c     Sun May 15 22:41:51 2022 +0000
+++ b/games/gomoku/bdinit.c     Sun May 15 22:56:20 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bdinit.c,v 1.10 2022/05/15 22:00:11 rillig Exp $       */
+/*     $NetBSD: bdinit.c,v 1.11 2022/05/15 22:56:20 rillig Exp $       */
 
 /*
  * Copyright (c) 1994
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "from: @(#)bdinit.c     8.2 (Berkeley) 5/3/95";
 #else
-__RCSID("$NetBSD: bdinit.c,v 1.10 2022/05/15 22:00:11 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.11 2022/05/15 22:56:20 rillig Exp $");
 #endif
 #endif /* not lint */
 
@@ -57,7 +57,7 @@
 
        /* mark the borders as such */
        sp = bp;
-       for (i = BSZ2; --i >= 0; sp++) {
+       for (i = 1 + BSZ + 1; --i >= 0; sp++) {
                sp->s_occ = BORDER;                     /* top border */
                sp->s_flags = BFLAGALL;
        }
@@ -65,8 +65,8 @@
        /* fill entire board with EMPTY spots */
        memset(frames, 0, sizeof(frames));
        cbp = frames;
-       for (j = 0; ++j < BSZ1; sp++) {                 /* for each row */
-               for (i = 0; ++i < BSZ1; sp++) {         /* for each column */
+       for (j = 0; ++j < BSZ + 1; sp++) {              /* for each row */
+               for (i = 0; ++i < BSZ + 1; sp++) {      /* for each column */
                        sp->s_occ = EMPTY;
                        sp->s_flags = 0;
                        sp->s_wval = 0;
@@ -145,8 +145,8 @@
        }
 
        /* mark the borders as such */
-       for (i = BSZ1; --i >= 0; sp++) {
-               sp->s_occ = BORDER;             /* bottom border */
+       for (i = BSZ + 1; --i >= 0; sp++) {
+               sp->s_occ = BORDER;                     /* bottom border */
                sp->s_flags = BFLAGALL;
        }
 
diff -r fa73a93557be -r f15fe9fe98e0 games/gomoku/bdisp.c
--- a/games/gomoku/bdisp.c      Sun May 15 22:41:51 2022 +0000
+++ b/games/gomoku/bdisp.c      Sun May 15 22:56:20 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bdisp.c,v 1.21 2022/05/15 22:08:05 rillig Exp $        */
+/*     $NetBSD: bdisp.c,v 1.22 2022/05/15 22:56:20 rillig Exp $        */
 
 /*
  * Copyright (c) 1994
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)bdisp.c    8.2 (Berkeley) 5/3/95";
 #else
-__RCSID("$NetBSD: bdisp.c,v 1.21 2022/05/15 22:08:05 rillig Exp $");
+__RCSID("$NetBSD: bdisp.c,v 1.22 2022/05/15 22:56:20 rillig Exp $");
 #endif
 #endif /* not lint */
 
@@ -85,7 +85,7 @@
 cursfini(void)
 {
 
-       move(BSZ4, 0);
+       move(BSZ + 4, 0);
        clrtoeol();
        refresh();
        echo();
@@ -101,19 +101,19 @@
        int i, j;
 
        /* top border */
-       for (i = 1; i < BSZ1; i++) {
+       for (i = 1; i < BSZ + 1; i++) {
                move(0, 2 * i + 1);
                addch(letters[i]);
        }
        /* left and right edges */
-       for (j = BSZ1; --j > 0; ) {
+       for (j = BSZ + 1; --j > 0; ) {
                move(20 - j, 0);
                printw("%2d ", j);
-               move(20 - j, 2 * BSZ1 + 1);
+               move(20 - j, 2 * (BSZ + 1) + 1);
                printw("%d ", j);
        }
        /* bottom border */
-       for (i = 1; i < BSZ1; i++) {
+       for (i = 1; i < BSZ + 1; i++) {
                move(20, 2 * i + 1);
                addch(letters[i]);
        }
@@ -165,10 +165,10 @@
        int i, j, c;
        struct spotstr *sp;
 
-       for (j = BSZ1; --j > 0; ) {
-               for (i = 1; i < BSZ1; i++) {
-                       move(BSZ1 - j, 2 * i + 1);
-                       sp = &board[i + j * BSZ1];
+       for (j = BSZ + 1; --j > 0; ) {
+               for (i = 1; i < BSZ + 1; i++) {
+                       move(BSZ + 1 - j, 2 * i + 1);
+                       sp = &board[i + j * (BSZ + 1)];
                        if (debug > 1 && sp->s_occ == EMPTY) {
                                if (sp->s_flags & IFLAGALL)
                                        c = '+';
@@ -197,11 +197,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 (j = BSZ1; --j > 0; ) {
+       for (j = BSZ + 1; --j > 0; ) {
                /* left edge */
                fprintf(fp, "%2d ", j);
-               for (i = 1; i < BSZ1; i++) {
-                       sp = &board[i + j * BSZ1];
+               for (i = 1; i < BSZ + 1; i++) {
+                       sp = &board[i + j * (BSZ + 1)];
                        if (debug > 1 && sp->s_occ == EMPTY) {
                                if (sp->s_flags & IFLAGALL)
                                        c = '+';
@@ -250,10 +250,10 @@
 {
        int len = strlen(str);
 
-       move(BSZ4, 0);
+       move(BSZ + 4, 0);
        addstr(str);
        clrtoeol();
-       move(BSZ4, len);
+       move(BSZ + 4, len);
        refresh();
 }
 
@@ -336,7 +336,7 @@
        nx = curx;
        ny = cury;
        for (;;) {
-               mvprintw(BSZ3, (BSZ - 6) / 2, "(%c %d) ",
+               mvprintw(BSZ + 3, (BSZ - 6) / 2, "(%c %d) ",
                    'A' + ((curx > 7) ? (curx + 1) : curx), cury + 1);
                BGOTO(cury, curx);
 
@@ -434,8 +434,8 @@
                        MEVENT  myevent;
 
                        getmouse(&myevent);
-                       if (myevent.y >= 1 && myevent.y <= BSZ1 &&
-                           myevent.x >= 3 && myevent.x <= (2 * BSZ + 1)) {
+                       if (myevent.y >= 1 && myevent.y <= BSZ + 1 &&
+                           myevent.x >= 3 && myevent.x <= 2 * BSZ + 1) {
                                curx = (myevent.x - 3) / 2;
                                cury = BSZ - myevent.y;
                                return PT(curx,cury);
@@ -453,7 +453,7 @@
                        return SAVE;
                case ' ':
                case '\r':
-                       (void)mvaddstr(BSZ3, (BSZ - 6) / 2, "      ");
+                       (void)mvaddstr(BSZ + 3, (BSZ - 6) / 2, "      ");
                        return PT(curx + 1, cury + 1);
                }
 
diff -r fa73a93557be -r f15fe9fe98e0 games/gomoku/gomoku.h
--- a/games/gomoku/gomoku.h     Sun May 15 22:41:51 2022 +0000
+++ b/games/gomoku/gomoku.h     Sun May 15 22:56:20 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gomoku.h,v 1.24 2022/05/15 22:41:51 rillig Exp $       */
+/*     $NetBSD: gomoku.h,v 1.25 2022/05/15 22:56:20 rillig Exp $       */
 
 /*
  * Copyright (c) 1994
@@ -40,13 +40,9 @@
 
 /* board dimensions */
 #define BSZ    19
-#define BSZ1   (BSZ + 1)
-#define BSZ2   (BSZ + 2)
-#define BSZ3   (BSZ + 3)
-#define BSZ4   (BSZ + 4)
-#define BAREA  (BSZ2 * BSZ1 + 1)
+#define BAREA  ((1 + BSZ + 1) * (BSZ + 1) + 1)
 
-#define TRANSCRIPT_COL (2 * BSZ4)
+#define TRANSCRIPT_COL (2 * (BSZ + 4))
 
 /* interactive curses stuff */
 #define BGOTO(y, x)    move(BSZ - (y), 2 * (x) + 3)
@@ -56,8 +52,8 @@
 #define FSZ2   (BSZ-4)
 #define FAREA  (FSZ1*FSZ2 + FSZ2*FSZ2 + FSZ1*FSZ2 + FSZ2*FSZ2)
 
-#define MUP    (BSZ1)
-#define MDOWN  (-BSZ1)
+#define MUP    (BSZ + 1)
+#define MDOWN  (-(BSZ + 1))
 #define MLEFT  (-1)
 #define MRIGHT (1)
 
@@ -75,7 +71,7 @@
 #define TIE    4
 #define SAVE   5
 
-#define PT(x, y)       ((x) + BSZ1 * (y))
+#define PT(x, y)       ((x) + (BSZ + 1) * (y))
 
 /*
  * A 'frame' is a group of five or six contiguous board locations.
diff -r fa73a93557be -r f15fe9fe98e0 games/gomoku/main.c
--- a/games/gomoku/main.c       Sun May 15 22:41:51 2022 +0000
+++ b/games/gomoku/main.c       Sun May 15 22:56:20 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.30 2022/05/15 22:08:05 rillig Exp $ */
+/*     $NetBSD: main.c,v 1.31 2022/05/15 22:56:20 rillig Exp $ */
 
 /*
  * Copyright (c) 1994
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.4 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: main.c,v 1.30 2022/05/15 22:08:05 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.31 2022/05/15 22:56:20 rillig Exp $");
 #endif
 #endif /* not lint */
 
@@ -157,7 +157,7 @@
 #endif
 
                if (inputfp == NULL && test == 0) {
-                       move(BSZ3, 0);
+                       move(BSZ + 3, 0);
                        printw("Black moves first. ");
                        ask("(B)lack or (W)hite? ");
                        for (;;) {
@@ -176,7 +176,7 @@
                                beep();
                                ask("Please choose (B)lack or (W)hite: ");
                        }
-                       move(BSZ3, 0);
+                       move(BSZ + 3, 0);
                        clrtoeol();
                }
        } else {
@@ -300,7 +300,7 @@
                        bdisp();
        }
        if (interactive) {
-               move(BSZ3, 0);
+               move(BSZ + 3, 0);
                switch (i) {
                case WIN:
                        if (input[color] == PROGRAM)
diff -r fa73a93557be -r f15fe9fe98e0 games/gomoku/stoc.c
--- a/games/gomoku/stoc.c       Sun May 15 22:41:51 2022 +0000
+++ b/games/gomoku/stoc.c       Sun May 15 22:56:20 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: stoc.c,v 1.15 2022/05/15 22:08:05 rillig Exp $ */
+/*     $NetBSD: stoc.c,v 1.16 2022/05/15 22:56:20 rillig Exp $ */
 
 /*
  * Copyright (c) 1994
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)stoc.c     8.1 (Berkeley) 7/24/94";
 #else
-__RCSID("$NetBSD: stoc.c,v 1.15 2022/05/15 22:08:05 rillig Exp $");
+__RCSID("$NetBSD: stoc.c,v 1.16 2022/05/15 22:56:20 rillig Exp $");
 #endif
 #endif /* not lint */
 
@@ -74,7 +74,8 @@
        for (i = 0; mv[i].m_code >= 0; i++)
                if (s == mv[i].m_code)
                        return mv[i].m_text;
-       snprintf(buf, sizeof(buf), "%c%d", letters[s % BSZ1], s / BSZ1);
+       snprintf(buf, sizeof(buf), "%c%d",
+           letters[s % (BSZ + 1)], s / (BSZ + 1));
        return buf;
 }
 



Home | Main Index | Thread Index | Old Index