Module Name:    src
Committed By:   rillig
Date:           Sun May 29 15:31:12 UTC 2022

Modified Files:
        src/games/gomoku: gomoku.h makemove.c pickmove.c

Log Message:
gomoku: add type player_color

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.40 -r1.41 src/games/gomoku/makemove.c
cvs rdiff -u -r1.60 -r1.61 src/games/gomoku/pickmove.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/gomoku/gomoku.h
diff -u src/games/gomoku/gomoku.h:1.52 src/games/gomoku/gomoku.h:1.53
--- src/games/gomoku/gomoku.h:1.52	Sun May 29 14:50:37 2022
+++ src/games/gomoku/gomoku.h	Sun May 29 15:31:12 2022
@@ -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	debuglog(const char *, ...) __print
 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

Index: src/games/gomoku/makemove.c
diff -u src/games/gomoku/makemove.c:1.40 src/games/gomoku/makemove.c:1.41
--- src/games/gomoku/makemove.c:1.40	Sun May 29 14:37:44 2022
+++ src/games/gomoku/makemove.c	Sun May 29 15:31:12 2022
@@ -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 @@ old_weight_value(const struct spotstr *s
  *	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 @@ makemove(int us, spot_index mv)
 		}
 
 		/* 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? */

Index: src/games/gomoku/pickmove.c
diff -u src/games/gomoku/pickmove.c:1.60 src/games/gomoku/pickmove.c:1.61
--- src/games/gomoku/pickmove.c:1.60	Sun May 29 15:16:11 2022
+++ src/games/gomoku/pickmove.c	Sun May 29 15:31:12 2022
@@ -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 @@ struct overlap_info {
 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 bool sortcombo(struct combostr **
 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 @@ pickmove(int us)
 		 * 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 @@ pickmove(int us)
 }
 
 /*
- * 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 @@ better(spot_index s, spot_index s1, int 
 	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);
 

Reply via email to