Source-Changes-HG archive

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

[src/trunk]: src/games/gomoku gomoku: add type player_color



details:   https://anonhg.NetBSD.org/src/rev/56db38a36c50
branches:  trunk
changeset: 366518:56db38a36c50
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun May 29 15:31:12 2022 +0000

description:
gomoku: add type player_color

No functional change.

diffstat:

 games/gomoku/gomoku.h   |   9 ++++++---
 games/gomoku/makemove.c |   8 ++++----
 games/gomoku/pickmove.c |  20 ++++++++++----------
 3 files changed, 20 insertions(+), 17 deletions(-)

diffs (145 lines):

diff -r 1c289df71d90 -r 56db38a36c50 games/gomoku/gomoku.h
--- a/games/gomoku/gomoku.h     Sun May 29 15:23:20 2022 +0000
+++ b/games/gomoku/gomoku.h     Sun May 29 15:31:12 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gomoku.h,v 1.52 2022/05/29 14:50:37 rillig Exp $       */
+/*     $NetBSD: gomoku.h,v 1.53 2022/05/29 15:31:12 rillig Exp $       */
 
 /*
  * Copyright (c) 1994
@@ -63,6 +63,9 @@
 #define EMPTY  2
 #define BORDER 3
 
+/* Either BLACK or WHITE. */
+typedef unsigned char player_color;
+
 /* A spot on the board, or one of the special values below. */
 typedef unsigned short spot_index;
 #define PT(x, y)       ((x) + (BSZ + 1) * (y))
@@ -267,10 +270,10 @@
 void   whatsup(int);
 const char *stoc(spot_index);
 spot_index ctos(const char *);
-int    makemove(int, spot_index);
+int    makemove(player_color, spot_index);
 void   clearcombo(struct combostr *, int);
 void   markcombo(struct combostr *);
-int    pickmove(int);
+spot_index pickmove(player_color);
 #if defined(DEBUG)
 void   printcombo(struct combostr *, char *, size_t);
 #endif
diff -r 1c289df71d90 -r 56db38a36c50 games/gomoku/makemove.c
--- a/games/gomoku/makemove.c   Sun May 29 15:23:20 2022 +0000
+++ b/games/gomoku/makemove.c   Sun May 29 15:31:12 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: makemove.c,v 1.40 2022/05/29 14:37:44 rillig Exp $     */
+/*     $NetBSD: makemove.c,v 1.41 2022/05/29 15:31: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.40 2022/05/29 14:37:44 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.41 2022/05/29 15:31:12 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -97,7 +97,7 @@
  *     TIE     The game is a tie.
  */
 int
-makemove(int us, spot_index mv)
+makemove(player_color us, spot_index mv)
 {
 
        /* check for end of game */
@@ -161,7 +161,7 @@
                }
 
                /* compute new value & combo number for this frame & color */
-               int them = us != BLACK ? BLACK : WHITE;
+               player_color them = us != BLACK ? BLACK : WHITE;
                fsp->s_fval[them][r].s = 0x600;
                union comboval *cp = &fsp->s_fval[us][r];
                /* both ends open? */
diff -r 1c289df71d90 -r 56db38a36c50 games/gomoku/pickmove.c
--- a/games/gomoku/pickmove.c   Sun May 29 15:23:20 2022 +0000
+++ b/games/gomoku/pickmove.c   Sun May 29 15:31:12 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pickmove.c,v 1.60 2022/05/29 15:16:11 rillig Exp $     */
+/*     $NetBSD: pickmove.c,v 1.61 2022/05/29 15:31: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.60 2022/05/29 15:16:11 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.61 2022/05/29 15:31:12 rillig Exp $");
 
 #include <stdlib.h>
 #include <string.h>
@@ -61,14 +61,14 @@
 static struct combostr *hashcombos[FAREA];/* hash list for finding duplicates */
 static struct combostr *sortcombos;    /* combos at higher levels */
 static int combolen;                   /* number of combos in sortcombos */
-static int nextcolor;                  /* color of next move */
+static player_color nextcolor;         /* color of next move */
 static int elistcnt;                   /* count of struct elist allocated */
 static int combocnt;                   /* count of struct combostr allocated */
 static unsigned int forcemap[MAPSZ];   /* map for blocking <1,x> combos */
 static unsigned int tmpmap[MAPSZ];     /* map for blocking <1,x> combos */
 static int nforce;                     /* count of opponent <1,x> combos */
 
-static bool better(spot_index, spot_index, int);
+static bool better(spot_index, spot_index, player_color);
 static void scanframes(int);
 static void makecombo2(struct combostr *, struct spotstr *, int, int);
 static void addframes(unsigned int);
@@ -83,8 +83,8 @@
 static void printcombo(struct combostr *, char *, size_t);
 #endif
 
-int
-pickmove(int us)
+spot_index
+pickmove(player_color us)
 {
 
        /* first move is easy */
@@ -161,7 +161,7 @@
                 * all be blocked with one move.
                 */
                spot_index m = us == BLACK ? s2 : s1;
-               int them = us != BLACK ? BLACK : WHITE;
+               player_color them = us != BLACK ? BLACK : WHITE;
                if (board[m].s_combo[them].cv_force == 1 &&
                    !BIT_TEST(forcemap, m))
                        debuglog("*** Can't be blocked");
@@ -192,10 +192,10 @@
 }
 
 /*
- * Return true if spot 'sp' is better than spot 'sp1' for color 'us'.
+ * Return true if spot 's' is better than spot 's1' for color 'us'.
  */
 static bool
-better(spot_index s, spot_index s1, int us)
+better(spot_index s, spot_index s1, player_color us)
 {
        const struct spotstr *sp = &board[s], *sp1 = &board[s1];
 
@@ -206,7 +206,7 @@
        if (/* .... */ sp->s_nforce[us] != sp1->s_nforce[us])
                return sp->s_nforce[us] > sp1->s_nforce[us];
 
-       int them = us != BLACK ? BLACK : WHITE;
+       player_color them = us != BLACK ? BLACK : WHITE;
        if (BIT_TEST(forcemap, s) != BIT_TEST(forcemap, s1))
                return BIT_TEST(forcemap, s);
 



Home | Main Index | Thread Index | Old Index