Source-Changes-HG archive

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

[src/trunk]: src/games/gomoku gomoku: provide readable names for c.a and c.b



details:   https://anonhg.NetBSD.org/src/rev/c89d92b8277b
branches:  trunk
changeset: 366281:c89d92b8277b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat May 21 16:39:14 2022 +0000

description:
gomoku: provide readable names for c.a and c.b

No binary change.

diffstat:

 games/gomoku/bdinit.c   |   6 +-
 games/gomoku/gomoku.h   |  32 +++++++++-------
 games/gomoku/makemove.c |  28 +++++++-------
 games/gomoku/pickmove.c |  92 ++++++++++++++++++++++++------------------------
 4 files changed, 80 insertions(+), 78 deletions(-)

diffs (truncated from 468 to 300 lines):

diff -r fcc534bc1ec3 -r c89d92b8277b games/gomoku/bdinit.c
--- a/games/gomoku/bdinit.c     Sat May 21 15:21:40 2022 +0000
+++ b/games/gomoku/bdinit.c     Sat May 21 16:39:14 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bdinit.c,v 1.20 2022/05/21 15:11:24 rillig Exp $       */
+/*     $NetBSD: bdinit.c,v 1.21 2022/05/21 16:39:14 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.20 2022/05/21 15:11:24 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.21 2022/05/21 16:39:14 rillig Exp $");
 
 #include <string.h>
 #include "gomoku.h"
@@ -186,7 +186,7 @@
             * s = 5 if closed, 6 if open.
             * At this point black & white are the same.
             */
-           int s = 5 + sp1->s_fval[BLACK][cbp->c_dir].c.b;
+           int s = 5 + sp1->s_fval[BLACK][cbp->c_dir].cv_win;
            /* for each spot in frame A */
            for (int i = 0; i < s; i++, sp1 += d1, vertex += d1) {
                /* the sixth spot in frame A only overlaps if it is open */
diff -r fcc534bc1ec3 -r c89d92b8277b games/gomoku/gomoku.h
--- a/games/gomoku/gomoku.h     Sat May 21 15:21:40 2022 +0000
+++ b/games/gomoku/gomoku.h     Sat May 21 16:39:14 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gomoku.h,v 1.36 2022/05/21 15:21:40 rillig Exp $       */
+/*     $NetBSD: gomoku.h,v 1.37 2022/05/21 16:39:14 rillig Exp $       */
 
 /*
  * Copyright (c) 1994
@@ -75,8 +75,8 @@
 
 /*
  * A 'combo' is a group of intersecting frames and consists of two numbers:
- * 'A' is the number of moves to make the combo non-blockable.
- * 'B' is the minimum number of moves needed to win once it can't be blocked.
+ * 'F' is the number of moves to make the combo non-blockable.
+ * 'W' is the minimum number of moves needed to win once it can't be blocked.
  *
  * A 'force' is a combo that is one move away from being non-blockable.
  *
@@ -88,13 +88,13 @@
  * it is already a force. Also, the frames have to be independent so a
  * single move doesn't affect more than one frame making up the combo.
  *
- * Rules for comparing which of two combos (<A1,B1> <A2,B2>) is better:
+ * Rules for comparing which of two combos (<F1,W1> <F2,W2>) is better:
  * Both the same color:
- *     <A',B'> = (A1 < A2 || A1 == A2 && B1 <= B2) ? <A1,B1> : <A2,B2>
+ *     <F',W'> = (F1 < F2 || F1 == F2 && W1 <= W2) ? <F1,W1> : <F2,W2>
  *     We want to complete the force first, then the combo with the
  *     fewest moves to win.
- * Different colors, <A1,B1> is the combo for the player with the next move:
- *     <A',B'> = A2 <= 1 && (A1 > 1 || A2 + B2 < A1 + B1) ? <A2,B2> : <A1,B1>
+ * Different colors, <F1,W1> is the combo for the player with the next move:
+ *     <F',W'> = F2 <= 1 && (F1 > 1 || F2 + W2 < F1 + W1) ? <F2,W2> : <F1,W1>
  *     We want to block only if we have to (i.e., if they are one move away
  *     from completing a force, and we don't have a force that we can
  *     complete which takes fewer or the same number of moves to win).
@@ -102,7 +102,7 @@
 
 /*
  * Single frame combo values:
- *     <A,B>   board values
+ *     <F,W>   board values
  *     5,0     . . . . . O
  *     4,1     . . . . . .
  *     4,0     . . . . X O
@@ -115,24 +115,26 @@
  *     0,1     . X X X X .
  *     0,0     X X X X X O
  *
- * The rule for combining two combos (<A1,B1> <A2,B2>) with V valid
+ * The rule for combining two combos (<F1,W1> <F2,W2>) with V valid
  * intersection points is:
- *     A' = A1 + A2 - 2 - V
- *     B' = MIN(A1 + B1 - 1, A2 + B2 - 1)
+ *     F' = F1 + F2 - 2 - V
+ *     W' = MIN(F1 + W1 - 1, F2 + W2 - 1)
  */
 union comboval {
        struct {
 #if BYTE_ORDER == BIG_ENDIAN
-               u_char  a;      /* # moves to complete force */
-               u_char  b;      /* # moves to win */
+               u_char  a;
+               u_char  b;
 #endif
 #if BYTE_ORDER == LITTLE_ENDIAN
-               u_char  b;      /* # moves to win */
-               u_char  a;      /* # moves to complete force */
+               u_char  b;
+               u_char  a;
 #endif
        } c;
        u_short s;
 };
+#define cv_force       c.a     /* # moves to complete force */
+#define cv_win         c.b     /* # moves to win */
 
 /*
  * This structure is used to record information about single frames (F) and
diff -r fcc534bc1ec3 -r c89d92b8277b games/gomoku/makemove.c
--- a/games/gomoku/makemove.c   Sat May 21 15:21:40 2022 +0000
+++ b/games/gomoku/makemove.c   Sat May 21 16:39:14 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: makemove.c,v 1.19 2022/05/21 15:11:24 rillig Exp $     */
+/*     $NetBSD: makemove.c,v 1.20 2022/05/21 16:39:14 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.19 2022/05/21 15:11:24 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.20 2022/05/21 16:39:14 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -109,12 +109,12 @@
                /* compute old weight value for this frame */
                cp = &fsp->s_fval[BLACK][r];
                if (cp->s <= 0x500)
-                   val = weight[5 - cp->c.a - cp->c.b];
+                   val = weight[5 - cp->cv_force - cp->cv_win];
                else
                    val = 0;
                cp = &fsp->s_fval[WHITE][r];
                if (cp->s <= 0x500)
-                   val += weight[5 - cp->c.a - cp->c.b];
+                   val += weight[5 - cp->cv_force - cp->cv_win];
 
                /* compute new combo value for this frame */
                sp = fsp;
@@ -148,11 +148,11 @@
                cp = &fsp->s_fval[us][r];
                /* both ends open? */
                if (space && sp->s_occ == EMPTY) {
-                   cp->c.a = 4 - n;
-                   cp->c.b = 1;
+                   cp->cv_force = 4 - n;
+                   cp->cv_win = 1;
                } else {
-                   cp->c.a = 5 - n;
-                   cp->c.b = 0;
+                   cp->cv_force = 5 - n;
+                   cp->cv_win = 0;
                }
                val = weight[n];
                sp = fsp;
@@ -190,14 +190,14 @@
            /* both ends open? */
            if (fsp->s_occ == EMPTY) {
                cp = &fsp->s_fval[BLACK][r];
-               if (cp->c.b != 0) {
-                   cp->c.a += 1;
-                   cp->c.b = 0;
+               if (cp->cv_win != 0) {
+                   cp->cv_force++;
+                   cp->cv_win = 0;
                }
                cp = &fsp->s_fval[WHITE][r];
-               if (cp->c.b != 0) {
-                   cp->c.a += 1;
-                   cp->c.b = 0;
+               if (cp->cv_win != 0) {
+                   cp->cv_force++;
+                   cp->cv_win = 0;
                }
            }
 
diff -r fcc534bc1ec3 -r c89d92b8277b games/gomoku/pickmove.c
--- a/games/gomoku/pickmove.c   Sat May 21 15:21:40 2022 +0000
+++ b/games/gomoku/pickmove.c   Sat May 21 16:39:14 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pickmove.c,v 1.41 2022/05/21 15:11:24 rillig Exp $     */
+/*     $NetBSD: pickmove.c,v 1.42 2022/05/21 16:39:14 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.41 2022/05/21 15:11:24 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.42 2022/05/21 16:39:14 rillig Exp $");
 
 #include <stdlib.h>
 #include <string.h>
@@ -121,8 +121,8 @@
                sp = &board[pos];
                if (sp->s_occ != EMPTY)
                        continue;
-               if (debug != 0 && (sp->s_combo[BLACK].c.a == 1 ||
-                   sp->s_combo[WHITE].c.a == 1)) {
+               if (debug != 0 && (sp->s_combo[BLACK].cv_force == 1 ||
+                   sp->s_combo[WHITE].cv_force == 1)) {
                        debuglog("- %s %x/%d %d %x/%d %d %d",
                            stoc((int)(sp - board)),
                            sp->s_combo[BLACK].s, sp->s_level[BLACK],
@@ -158,7 +158,7 @@
                 */
                sp = (us == BLACK) ? sp2 : sp1;
                m = (int)(sp - board);
-               if (sp->s_combo[us != BLACK ? BLACK : WHITE].c.a == 1 &&
+               if (sp->s_combo[us != BLACK ? BLACK : WHITE].cv_force == 1 &&
                    !BIT_TEST(forcemap, m))
                        debuglog("*** Can't be blocked");
        }
@@ -177,8 +177,8 @@
         * away from completing a force, and we don't have a force that
         * we can complete which takes fewer moves to win).
         */
-       if (Tcp->c.a <= 1 && (Ocp->c.a > 1 ||
-           Tcp->c.a + Tcp->c.b < Ocp->c.a + Ocp->c.b))
+       if (Tcp->cv_force <= 1 && (Ocp->cv_force > 1 ||
+           Tcp->cv_force + Tcp->cv_win < Ocp->cv_force + Ocp->cv_win))
                return (int)(sp2 - board);
        return (int)(sp1 - board);
 }
@@ -247,7 +247,7 @@
        cb.s = sp->s_fval[color][d = cbp->c_dir].s;
        if (cb.s < 0x101) {
                d = dd[d];
-               for (i = 5 + cb.c.b; --i >= 0; sp += d) {
+               for (i = 5 + cb.cv_win; --i >= 0; sp += d) {
                        if (sp->s_occ != EMPTY)
                                continue;
                        sp->s_combo[color].s = cb.s;
@@ -267,13 +267,13 @@
                sp = &board[cbp->c_vertex];
                cp = &sp->s_fval[color][r = cbp->c_dir];
                d = dd[r];
-               if (cp->c.b != 0) {
+               if (cp->cv_win != 0) {
                        /*
                         * Since this is the first spot of an open-ended
                         * frame, we treat it as a closed frame.
                         */
-                       cb.c.a = cp->c.a + 1;
-                       cb.c.b = 0;
+                       cb.cv_force = cp->cv_force + 1;
+                       cb.cv_win = 0;
                        if (cb.s < sp->s_combo[color].s) {
                                sp->s_combo[color].s = cb.s;
                                sp->s_level[color] = 1;
@@ -423,9 +423,9 @@
 
        /* try to combine a new frame with those found so far */
        ocb.s = s;
-       baseB = ocb.c.a + ocb.c.b - 1;
-       fcnt = ocb.c.a - 2;
-       emask = fcnt != 0 ? ((ocb.c.b != 0 ? 0x1E : 0x1F) & ~(1 << off)) : 0;
+       baseB = ocb.cv_force + ocb.cv_win - 1;
+       fcnt = ocb.cv_force - 2;
+       emask = fcnt != 0 ? ((ocb.cv_win != 0 ? 0x1E : 0x1F) & ~(1 << off)) : 0;
        for (int r = 4; --r >= 0; ) {           /* for each direction */
            /* don't include frames that overlap in the same direction */
            if (r == ocbp->c_dir)
@@ -447,7 +447,7 @@
 
                /* don't include frames of the wrong color */
                fcb.s = fsp->s_fval[curcolor][r].s;
-               if (fcb.c.a >= 6)
+               if (fcb.cv_force >= 6)
                    continue;
 
                /*
@@ -455,16 +455,16 @@
                 * If this is the end point of the frame,
                 * use the closed ended value for the frame.
                 */
-               if ((f == 0 && fcb.c.b != 0) || fcb.s == 0x101) {
-                   fcb.c.a++;
-                   fcb.c.b = 0;
+               if ((f == 0 && fcb.cv_win != 0) || fcb.s == 0x101) {
+                   fcb.cv_force++;
+                   fcb.cv_win = 0;
                }
 
                /* compute combo value */
-               c = fcb.c.a + ocb.c.a - 3;
+               c = fcb.cv_force + ocb.cv_force - 3;
                if (c > 4)
                    continue;
-               n = fcb.c.a + fcb.c.b - 1;
+               n = fcb.cv_force + fcb.cv_win - 1;
                if (baseB < n)
                    n = baseB;
 
@@ -482,8 +482,8 @@
                    scbpp[0] = fcbp;
                    scbpp[1] = ocbp;



Home | Main Index | Thread Index | Old Index