CVS commit: src/games/gomoku

2022-06-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jun 19 10:33:17 UTC 2022

Modified Files:
src/games/gomoku: bdinit.c

Log Message:
gomoku: remove redundant parentheses

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/games/gomoku/bdinit.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/bdinit.c
diff -u src/games/gomoku/bdinit.c:1.36 src/games/gomoku/bdinit.c:1.37
--- src/games/gomoku/bdinit.c:1.36	Sun Jun 19 10:23:48 2022
+++ src/games/gomoku/bdinit.c	Sun Jun 19 10:33:17 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdinit.c,v 1.36 2022/06/19 10:23:48 rillig Exp $	*/
+/*	$NetBSD: bdinit.c,v 1.37 2022/06/19 10:33:17 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	from: @(#)bdinit.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdinit.c,v 1.36 2022/06/19 10:23:48 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.37 2022/06/19 10:33:17 rillig Exp $");
 
 #include 
 #include "gomoku.h"
@@ -73,14 +73,14 @@ init_spot_flags_and_fval(struct spotstr 
 		sp->s_fval[WHITE][DIR_D_].s = 0x401;
 		sp->s_fval[WHITE][DIR_DL].s = 0x401;
 	}
-	if (col > (BSZ - 4)) {
+	if (col > BSZ - 4) {
 		set_blocked(sp, DIR__R);
 		set_blocked(sp, DIR_DR);
 		sp->s_fval[BLACK][DIR__R].s = 0x600;
 		sp->s_fval[BLACK][DIR_DR].s = 0x600;
 		sp->s_fval[WHITE][DIR__R].s = 0x600;
 		sp->s_fval[WHITE][DIR_DR].s = 0x600;
-	} else if (col == (BSZ - 4)) {
+	} else if (col == BSZ - 4) {
 		sp->s_fval[BLACK][DIR__R].s = 0x500;
 		sp->s_fval[WHITE][DIR__R].s = 0x500;
 		if (!is_blocked(sp, DIR_DR)) {



CVS commit: src/games/gomoku

2022-06-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jun 19 10:33:17 UTC 2022

Modified Files:
src/games/gomoku: bdinit.c

Log Message:
gomoku: remove redundant parentheses

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/games/gomoku/bdinit.c

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



CVS commit: src/games/gomoku

2022-06-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jun 19 10:23:48 UTC 2022

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

Log Message:
gomoku: reduce usage of magic numbers in the code

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.55 -r1.56 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.42 -r1.43 src/games/gomoku/makemove.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/bdinit.c
diff -u src/games/gomoku/bdinit.c:1.35 src/games/gomoku/bdinit.c:1.36
--- src/games/gomoku/bdinit.c:1.35	Sun May 29 16:30:44 2022
+++ src/games/gomoku/bdinit.c	Sun Jun 19 10:23:48 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdinit.c,v 1.35 2022/05/29 16:30:44 rillig Exp $	*/
+/*	$NetBSD: bdinit.c,v 1.36 2022/06/19 10:23:48 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	from: @(#)bdinit.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdinit.c,v 1.35 2022/05/29 16:30:44 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.36 2022/06/19 10:23:48 rillig Exp $");
 
 #include 
 #include "gomoku.h"
@@ -47,59 +47,56 @@ init_spot_flags_and_fval(struct spotstr 
 
 	sp->s_flags = 0;
 	if (row < 5) {
-		/* directions 1, 2, 3 are blocked */
-		sp->s_flags |= (BFLAG << 1) | (BFLAG << 2) |
-		(BFLAG << 3);
-		sp->s_fval[BLACK][1].s = 0x600;
-		sp->s_fval[BLACK][2].s = 0x600;
-		sp->s_fval[BLACK][3].s = 0x600;
-		sp->s_fval[WHITE][1].s = 0x600;
-		sp->s_fval[WHITE][2].s = 0x600;
-		sp->s_fval[WHITE][3].s = 0x600;
+		set_blocked(sp, DIR_DR);
+		set_blocked(sp, DIR_D_);
+		set_blocked(sp, DIR_DL);
+		sp->s_fval[BLACK][DIR_DR].s = 0x600;
+		sp->s_fval[BLACK][DIR_D_].s = 0x600;
+		sp->s_fval[BLACK][DIR_DL].s = 0x600;
+		sp->s_fval[WHITE][DIR_DR].s = 0x600;
+		sp->s_fval[WHITE][DIR_D_].s = 0x600;
+		sp->s_fval[WHITE][DIR_DL].s = 0x600;
 	} else if (row == 5) {
 		/* five spaces, blocked on one side */
-		sp->s_fval[BLACK][1].s = 0x500;
-		sp->s_fval[BLACK][2].s = 0x500;
-		sp->s_fval[BLACK][3].s = 0x500;
-		sp->s_fval[WHITE][1].s = 0x500;
-		sp->s_fval[WHITE][2].s = 0x500;
-		sp->s_fval[WHITE][3].s = 0x500;
+		sp->s_fval[BLACK][DIR_DR].s = 0x500;
+		sp->s_fval[BLACK][DIR_D_].s = 0x500;
+		sp->s_fval[BLACK][DIR_DL].s = 0x500;
+		sp->s_fval[WHITE][DIR_DR].s = 0x500;
+		sp->s_fval[WHITE][DIR_D_].s = 0x500;
+		sp->s_fval[WHITE][DIR_DL].s = 0x500;
 	} else {
 		/* six spaces, not blocked */
-		sp->s_fval[BLACK][1].s = 0x401;
-		sp->s_fval[BLACK][2].s = 0x401;
-		sp->s_fval[BLACK][3].s = 0x401;
-		sp->s_fval[WHITE][1].s = 0x401;
-		sp->s_fval[WHITE][2].s = 0x401;
-		sp->s_fval[WHITE][3].s = 0x401;
+		sp->s_fval[BLACK][DIR_DR].s = 0x401;
+		sp->s_fval[BLACK][DIR_D_].s = 0x401;
+		sp->s_fval[BLACK][DIR_DL].s = 0x401;
+		sp->s_fval[WHITE][DIR_DR].s = 0x401;
+		sp->s_fval[WHITE][DIR_D_].s = 0x401;
+		sp->s_fval[WHITE][DIR_DL].s = 0x401;
 	}
 	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;
+		set_blocked(sp, DIR__R);
+		set_blocked(sp, DIR_DR);
+		sp->s_fval[BLACK][DIR__R].s = 0x600;
+		sp->s_fval[BLACK][DIR_DR].s = 0x600;
+		sp->s_fval[WHITE][DIR__R].s = 0x600;
+		sp->s_fval[WHITE][DIR_DR].s = 0x600;
 	} 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 */
-		if ((sp->s_flags & (BFLAG << 1)) == 0) {
-			sp->s_fval[BLACK][1].s = 0x500;
-			sp->s_fval[WHITE][1].s = 0x500;
+		sp->s_fval[BLACK][DIR__R].s = 0x500;
+		sp->s_fval[WHITE][DIR__R].s = 0x500;
+		if (!is_blocked(sp, DIR_DR)) {
+			sp->s_fval[BLACK][DIR_DR].s = 0x500;
+			sp->s_fval[WHITE][DIR_DR].s = 0x500;
 		}
 	} else {
-		sp->s_fval[BLACK][0].s = 0x401;
-		sp->s_fval[WHITE][0].s = 0x401;
+		sp->s_fval[BLACK][DIR__R].s = 0x401;
+		sp->s_fval[WHITE][DIR__R].s = 0x401;
 		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 (col == 5 &&
-		(sp->s_flags & (BFLAG << 3)) == 0) {
-			sp->s_fval[BLACK][3].s = 0x500;
-			sp->s_fval[WHITE][3].s = 0x500;
+			set_blocked(sp, DIR_DL);
+			sp->s_fval[BLACK][DIR_DL].s = 0x600;
+			sp->s_fval[WHITE][DIR_DL].s = 0x600;
+		} else if (col == 5 && !is_blocked(sp, DIR_DL)) {
+			sp->s_fval[BLACK][DIR_DL].s = 0x500;
+			sp->s_fval[WHITE][DIR_DL].s = 0x500;
 		}
 	}
 }
@@ -110,7 +107,7 @@ init_spot_frame(struct spotstr *sp, fram
 {
 
 	for (direction r = 4; r-- > 0; ) {
-		if ((sp->s_flags & (BFLAG << r)) != 0)
+		if (is_blocked(sp, r))
 			continue;
 
 		frame_index fi = (*fip)++;
@@ -247,7 +244,7 @@ init_overlap_frame(int fia, int ra, int 
 			const struct spotstr *spb0 = [s - offb * db];
 			if (spb0->s_occ == BORDER)
 break;
-			if 

CVS commit: src/games/gomoku

2022-06-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jun 19 10:23:48 UTC 2022

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

Log Message:
gomoku: reduce usage of magic numbers in the code

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.55 -r1.56 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.42 -r1.43 src/games/gomoku/makemove.c

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



CVS commit: src/games/gomoku

2022-05-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue May 31 19:11:58 UTC 2022

Modified Files:
src/games/gomoku: Makefile

Log Message:
Elide vax breakage


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/games/gomoku/Makefile

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/Makefile
diff -u src/games/gomoku/Makefile:1.11 src/games/gomoku/Makefile:1.12
--- src/games/gomoku/Makefile:1.11	Sun May 29 13:01:42 2022
+++ src/games/gomoku/Makefile	Tue May 31 15:11:58 2022
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.11 2022/05/29 17:01:42 rillig Exp $
+#	$NetBSD: Makefile,v 1.12 2022/05/31 19:11:58 christos Exp $
 #	@(#)Makefile	8.1 (Berkeley) 7/24/94
 
 PROG=	gomoku
@@ -9,6 +9,10 @@ LDADD=	-lcurses -lterminfo
 HIDEGAME=hidegame
 CPPFLAGS+=	${DEBUG:D-DDEBUG}
 
+.if ${MACHINE} == "vax"
+COPTS.pickmove.c += -O0
+.endif
+
 #WARNS=		6	# would produce warnings about small integer types
 LINTFLAGS+=	-w	# treat warnings as errors
 LINTFLAGS+=	-T	# strict bool mode



CVS commit: src/games/gomoku

2022-05-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue May 31 19:11:58 UTC 2022

Modified Files:
src/games/gomoku: Makefile

Log Message:
Elide vax breakage


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/games/gomoku/Makefile

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 22:03:29 UTC 2022

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

Log Message:
gomoku: clean up variable names, add empty lines

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 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/pickmove.c
diff -u src/games/gomoku/pickmove.c:1.67 src/games/gomoku/pickmove.c:1.68
--- src/games/gomoku/pickmove.c:1.67	Sun May 29 21:47:12 2022
+++ src/games/gomoku/pickmove.c	Sun May 29 22:03:29 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pickmove.c,v 1.67 2022/05/29 21:47:12 rillig Exp $	*/
+/*	$NetBSD: pickmove.c,v 1.68 2022/05/29 22:03:29 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)pickmove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: pickmove.c,v 1.67 2022/05/29 21:47:12 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.68 2022/05/29 22:03:29 rillig Exp $");
 
 #include 
 #include 
@@ -102,6 +102,7 @@ pickmove(player_color us)
 		sp->s_nforce[WHITE] = 0;
 		sp->s_flags &= ~(FFLAGALL | MFLAGALL);
 	}
+
 	nforce = 0;
 	memset(forcemap, 0, sizeof(forcemap));
 
@@ -144,21 +145,23 @@ pickmove(player_color us)
 	}
 
 	if (debug > 0) {
-		spot_index s1 = us == BLACK ? os : ts;
-		spot_index s2 = us == BLACK ? ts : os;
-		const struct spotstr *sp1 = [s1], *sp2 = [s2];
+		spot_index bs = us == BLACK ? os : ts;
+		spot_index ws = us == BLACK ? ts : os;
+		const struct spotstr *bsp = [bs];
+		const struct spotstr *wsp = [ws];
+
 		debuglog("B %s %x/%d %d %x/%d %d %d",
-		stoc(s1),
-		sp1->s_combo[BLACK].s, sp1->s_level[BLACK],
-		sp1->s_nforce[BLACK],
-		sp1->s_combo[WHITE].s, sp1->s_level[WHITE],
-		sp1->s_nforce[WHITE], sp1->s_wval);
+		stoc(bs),
+		bsp->s_combo[BLACK].s, bsp->s_level[BLACK],
+		bsp->s_nforce[BLACK],
+		bsp->s_combo[WHITE].s, bsp->s_level[WHITE],
+		bsp->s_nforce[WHITE], bsp->s_wval);
 		debuglog("W %s %x/%d %d %x/%d %d %d",
-		stoc(s2),
-		sp2->s_combo[WHITE].s, sp2->s_level[WHITE],
-		sp2->s_nforce[WHITE],
-		sp2->s_combo[BLACK].s, sp2->s_level[BLACK],
-		sp2->s_nforce[BLACK], sp2->s_wval);
+		stoc(ws),
+		wsp->s_combo[WHITE].s, wsp->s_level[WHITE],
+		wsp->s_nforce[WHITE],
+		wsp->s_combo[BLACK].s, wsp->s_level[BLACK],
+		wsp->s_nforce[BLACK], wsp->s_wval);
 
 		/*
 		 * Check for more than one force that can't all be blocked
@@ -185,33 +188,34 @@ pickmove(player_color us)
 }
 
 /*
- * Return true if spot 's' is better than spot 's1' for color 'us'.
+ * Return true if spot 'as' is better than spot 'bs' for color 'us'.
  */
 static bool
-better(spot_index s, spot_index s1, player_color us)
+better(spot_index as, spot_index bs, player_color us)
 {
-	const struct spotstr *sp = [s], *sp1 = [s1];
+	const struct spotstr *asp = [as];
+	const struct spotstr *bsp = [bs];
 
-	if (/*  */ sp->s_combo[us].s != sp1->s_combo[us].s)
-		return sp->s_combo[us].s < sp1->s_combo[us].s;
-	if (/*  */ sp->s_level[us] != sp1->s_level[us])
-		return sp->s_level[us] < sp1->s_level[us];
-	if (/*  */ sp->s_nforce[us] != sp1->s_nforce[us])
-		return sp->s_nforce[us] > sp1->s_nforce[us];
+	if (/*  */ asp->s_combo[us].s != bsp->s_combo[us].s)
+		return asp->s_combo[us].s < bsp->s_combo[us].s;
+	if (/*  */ asp->s_level[us] != bsp->s_level[us])
+		return asp->s_level[us] < bsp->s_level[us];
+	if (/*  */ asp->s_nforce[us] != bsp->s_nforce[us])
+		return asp->s_nforce[us] > bsp->s_nforce[us];
 
 	player_color them = us != BLACK ? BLACK : WHITE;
-	if (BIT_TEST(forcemap, s) != BIT_TEST(forcemap, s1))
-		return BIT_TEST(forcemap, s);
+	if (BIT_TEST(forcemap, as) != BIT_TEST(forcemap, bs))
+		return BIT_TEST(forcemap, as);
 
-	if (/*  */ sp->s_combo[them].s != sp1->s_combo[them].s)
-		return sp->s_combo[them].s < sp1->s_combo[them].s;
-	if (/*  */ sp->s_level[them] != sp1->s_level[them])
-		return sp->s_level[them] < sp1->s_level[them];
-	if (/*  */ sp->s_nforce[them] != sp1->s_nforce[them])
-		return sp->s_nforce[them] > sp1->s_nforce[them];
+	if (/*  */ asp->s_combo[them].s != bsp->s_combo[them].s)
+		return asp->s_combo[them].s < bsp->s_combo[them].s;
+	if (/*  */ asp->s_level[them] != bsp->s_level[them])
+		return asp->s_level[them] < bsp->s_level[them];
+	if (/*  */ asp->s_nforce[them] != bsp->s_nforce[them])
+		return asp->s_nforce[them] > bsp->s_nforce[them];
 
-	if (/*  */ sp->s_wval != sp1->s_wval)
-		return sp->s_wval > sp1->s_wval;
+	if (/*  */ asp->s_wval != bsp->s_wval)
+		return asp->s_wval > bsp->s_wval;
 
 	return (random() & 1) != 0;
 }
@@ -273,6 +277,7 @@ scanframes(player_color color)
 		sp = [cbp->c_vertex];
 		cp = >s_fval[color][r = cbp->c_dir];
 		int delta = dd[r];
+
 		u_char off;
 		if (cp->cv_win != 0) {
 			/*
@@ -300,6 +305,7 @@ scanframes(player_color color)
 			cb.s = 

CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 22:03:29 UTC 2022

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

Log Message:
gomoku: clean up variable names, add empty lines

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 21:47:12 UTC 2022

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

Log Message:
gomoku: clean up color handling in 'pickmove'

Instead of searching for the best black and white moves, search instead
for our and their best moves. This makes the code simpler and more
uniform, as the strategy is the same for Black and White.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 21:47:12 UTC 2022

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

Log Message:
gomoku: clean up color handling in 'pickmove'

Instead of searching for the best black and white moves, search instead
for our and their best moves. This makes the code simpler and more
uniform, as the strategy is the same for Black and White.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 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/pickmove.c
diff -u src/games/gomoku/pickmove.c:1.66 src/games/gomoku/pickmove.c:1.67
--- src/games/gomoku/pickmove.c:1.66	Sun May 29 21:38:36 2022
+++ src/games/gomoku/pickmove.c	Sun May 29 21:47:12 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pickmove.c,v 1.66 2022/05/29 21:38:36 rillig Exp $	*/
+/*	$NetBSD: pickmove.c,v 1.67 2022/05/29 21:47:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)pickmove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: pickmove.c,v 1.66 2022/05/29 21:38:36 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.67 2022/05/29 21:47:12 rillig Exp $");
 
 #include 
 #include 
@@ -106,6 +106,7 @@ pickmove(player_color us)
 	memset(forcemap, 0, sizeof(forcemap));
 
 	/* compute new values */
+	player_color them = us != BLACK ? BLACK : WHITE;
 	nextcolor = us;
 	/*
 	 * TODO: Scanning for both frames misses that after loading the game
@@ -117,8 +118,8 @@ pickmove(player_color us)
 	scanframes(WHITE);
 
 	/* find the spot with the highest value */
-	spot_index s1 = PT(BSZ, BSZ);
-	spot_index s2 = PT(BSZ, BSZ);
+	spot_index os = PT(BSZ, BSZ);		/* our spot */
+	spot_index ts = PT(BSZ, BSZ);		/* their spot */
 	for (spot_index s = PT(BSZ, BSZ); s-- > PT(1, 1); ) {
 		const struct spotstr *sp = [s];
 		if (sp->s_occ != EMPTY)
@@ -136,13 +137,15 @@ pickmove(player_color us)
 			sp->s_wval);
 		}
 
-		if (better(s, s1, BLACK))	/* pick the best black move */
-			s1 = s;
-		if (better(s, s2, WHITE))	/* pick the best white move */
-			s2 = s;
+		if (better(s, os, us))		/* pick our best move */
+			os = s;
+		if (better(s, ts, them))	/* pick their best move */
+			ts = s;
 	}
 
 	if (debug > 0) {
+		spot_index s1 = us == BLACK ? os : ts;
+		spot_index s2 = us == BLACK ? ts : os;
 		const struct spotstr *sp1 = [s1], *sp2 = [s2];
 		debuglog("B %s %x/%d %d %x/%d %d %d",
 		stoc(s1),
@@ -161,36 +164,24 @@ pickmove(player_color us)
 		 * Check for more than one force that can't all be blocked
 		 * with one move.
 		 */
-		spot_index m = us == BLACK ? s2 : s1;
-		player_color them = us != BLACK ? BLACK : WHITE;
-		if (board[m].s_combo[them].cv_force == 1 &&
-		!BIT_TEST(forcemap, m))
+		if (board[ts].s_combo[them].cv_force == 1 &&
+		!BIT_TEST(forcemap, ts))
 			debuglog("*** Can't be blocked");
 	}
 
-	union comboval *Ocp, *Tcp;
-	if (us == BLACK) {
-		Ocp = [s1].s_combo[BLACK];
-		Tcp = [s2].s_combo[WHITE];
-	} else {
-		Tcp = [s1].s_combo[BLACK];
-		Ocp = [s2].s_combo[WHITE];
-
-		spot_index tmp = s1;
-		s1 = s2;
-		s2 = tmp;
-	}
+	union comboval ocv = board[os].s_combo[us];
+	union comboval tcv = board[ts].s_combo[them];
 
 	/*
 	 * Block their combo 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 moves to win).
 	 */
-	if (Tcp->cv_force <= 1 &&
-	!(Ocp->cv_force <= 1 &&
-	  Tcp->cv_force + Tcp->cv_win >= Ocp->cv_force + Ocp->cv_win))
-		return s2;
-	return s1;
+	if (tcv.cv_force <= 1 &&
+	!(ocv.cv_force <= 1 &&
+	  tcv.cv_force + tcv.cv_win >= ocv.cv_force + ocv.cv_win))
+		return ts;
+	return os;
 }
 
 /*



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 21:38:36 UTC 2022

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

Log Message:
gomoku: clean up 'pickmove' stylistically

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 21:38:36 UTC 2022

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

Log Message:
gomoku: clean up 'pickmove' stylistically

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 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/pickmove.c
diff -u src/games/gomoku/pickmove.c:1.65 src/games/gomoku/pickmove.c:1.66
--- src/games/gomoku/pickmove.c:1.65	Sun May 29 21:02:37 2022
+++ src/games/gomoku/pickmove.c	Sun May 29 21:38:36 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pickmove.c,v 1.65 2022/05/29 21:02:37 rillig Exp $	*/
+/*	$NetBSD: pickmove.c,v 1.66 2022/05/29 21:38:36 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)pickmove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: pickmove.c,v 1.65 2022/05/29 21:02:37 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.66 2022/05/29 21:38:36 rillig Exp $");
 
 #include 
 #include 
@@ -117,15 +117,16 @@ pickmove(player_color us)
 	scanframes(WHITE);
 
 	/* find the spot with the highest value */
-	spot_index s = PT(BSZ, BSZ);
-	spot_index s1 = s;
-	spot_index s2 = s;
-	for ( ; s-- > PT(1, 1); ) {
-		struct spotstr *sp = [s];
+	spot_index s1 = PT(BSZ, BSZ);
+	spot_index s2 = PT(BSZ, BSZ);
+	for (spot_index s = PT(BSZ, BSZ); s-- > PT(1, 1); ) {
+		const struct spotstr *sp = [s];
 		if (sp->s_occ != EMPTY)
 			continue;
-		if (debug != 0 && (sp->s_combo[BLACK].cv_force == 1 ||
-		sp->s_combo[WHITE].cv_force == 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(s),
 			sp->s_combo[BLACK].s, sp->s_level[BLACK],
@@ -134,15 +135,14 @@ pickmove(player_color us)
 			sp->s_nforce[WHITE],
 			sp->s_wval);
 		}
-		/* pick the best black move */
-		if (better(s, s1, BLACK))
+
+		if (better(s, s1, BLACK))	/* pick the best black move */
 			s1 = s;
-		/* pick the best white move */
-		if (better(s, s2, WHITE))
+		if (better(s, s2, WHITE))	/* pick the best white move */
 			s2 = s;
 	}
 
-	if (debug != 0) {
+	if (debug > 0) {
 		const struct spotstr *sp1 = [s1], *sp2 = [s2];
 		debuglog("B %s %x/%d %d %x/%d %d %d",
 		stoc(s1),
@@ -156,9 +156,10 @@ pickmove(player_color us)
 		sp2->s_nforce[WHITE],
 		sp2->s_combo[BLACK].s, sp2->s_level[BLACK],
 		sp2->s_nforce[BLACK], sp2->s_wval);
+
 		/*
-		 * Check for more than one force that can't
-		 * all be blocked with one move.
+		 * Check for more than one force that can't all be blocked
+		 * with one move.
 		 */
 		spot_index m = us == BLACK ? s2 : s1;
 		player_color them = us != BLACK ? BLACK : WHITE;
@@ -179,6 +180,7 @@ pickmove(player_color us)
 		s1 = s2;
 		s2 = tmp;
 	}
+
 	/*
 	 * Block their combo 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
@@ -348,7 +350,7 @@ scanframes(player_color color)
 	 level <= 1 + game.nmoves / 2 && combolen > n; level++) {
 		if (level >= 9)
 			break;	/* Do not think too long. */
-		if (debug != 0) {
+		if (debug > 0) {
 			debuglog("%cL%u %d %d %d", "BW"[color],
 			level, combolen - n, combocnt, elistcnt);
 			refresh();



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 21:02:37 UTC 2022

Modified Files:
src/games/gomoku: main.c pickmove.c

Log Message:
gomoku: migrate remaining functions to type player_color

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/games/gomoku/main.c
cvs rdiff -u -r1.64 -r1.65 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/main.c
diff -u src/games/gomoku/main.c:1.72 src/games/gomoku/main.c:1.73
--- src/games/gomoku/main.c:1.72	Sun May 29 20:21:28 2022
+++ src/games/gomoku/main.c	Sun May 29 21:02:37 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.72 2022/05/29 20:21:28 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.73 2022/05/29 21:02:37 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.72 2022/05/29 20:21:28 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.73 2022/05/29 21:02:37 rillig Exp $");
 
 #include 
 #include 
@@ -162,7 +162,7 @@ parse_args(int argc, char **argv)
 }
 
 static void
-set_input_sources(enum input_source *input, int color)
+set_input_sources(enum input_source *input, player_color color)
 {
 	switch (test) {
 	case NORMAL_PLAY:
@@ -249,7 +249,7 @@ again:
 }
 
 static void
-declare_winner(int outcome, const enum input_source *input, int color)
+declare_winner(int outcome, const enum input_source *input, player_color color)
 {
 
 	move(BSZ + 3, 0);
@@ -275,7 +275,7 @@ declare_winner(int outcome, const enum i
 
 struct outcome {
 	int result;
-	int winner;
+	player_color winner;
 };
 
 static struct outcome

Index: src/games/gomoku/pickmove.c
diff -u src/games/gomoku/pickmove.c:1.64 src/games/gomoku/pickmove.c:1.65
--- src/games/gomoku/pickmove.c:1.64	Sun May 29 18:25:39 2022
+++ src/games/gomoku/pickmove.c	Sun May 29 21:02:37 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pickmove.c,v 1.64 2022/05/29 18:25:39 rillig Exp $	*/
+/*	$NetBSD: pickmove.c,v 1.65 2022/05/29 21:02:37 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)pickmove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: pickmove.c,v 1.64 2022/05/29 18:25:39 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.65 2022/05/29 21:02:37 rillig Exp $");
 
 #include 
 #include 
@@ -69,12 +69,12 @@ static unsigned int tmpmap[MAPSZ];	/* ma
 static int nforce;			/* count of opponent <1,x> combos */
 
 static bool better(spot_index, spot_index, player_color);
-static void scanframes(int);
+static void scanframes(player_color);
 static void makecombo2(struct combostr *, struct spotstr *, u_char, u_short);
 static void addframes(unsigned int);
 static void makecombo(struct combostr *, struct spotstr *, u_char, u_short);
-static void appendcombo(struct combostr *, int);
-static void updatecombo(struct combostr *, int);
+static void appendcombo(struct combostr *);
+static void updatecombo(struct combostr *, player_color);
 static void makeempty(struct combostr *);
 static int checkframes(struct combostr *, struct combostr *, struct spotstr *,
 		u_short, struct overlap_info *);
@@ -223,11 +223,11 @@ better(spot_index s, spot_index s1, play
 	return (random() & 1) != 0;
 }
 
-static int curcolor;	/* implicit parameter to makecombo() */
+static player_color curcolor;	/* implicit parameter to makecombo() */
 static unsigned int curlevel;	/* implicit parameter to makecombo() */
 
 static bool
-four_in_a_row(int color, spot_index s, direction r)
+four_in_a_row(player_color color, spot_index s, direction r)
 {
 
 	struct spotstr *sp = [s];
@@ -250,7 +250,7 @@ four_in_a_row(int color, spot_index s, d
  * Also, try to combine frames to find more complex (chained) moves.
  */
 static void
-scanframes(int color)
+scanframes(player_color color)
 {
 	struct combostr *ecbp;
 	struct spotstr *sp;
@@ -530,7 +530,7 @@ makecombo2(struct combostr *ocbp, struct
 		makeempty(ncbp);
 
 		/* add the new combo to the end of the list */
-		appendcombo(ncbp, curcolor);
+		appendcombo(ncbp);
 		} else {
 		updatecombo(ncbp, curcolor);
 		free(ncbp);
@@ -565,7 +565,7 @@ addframes(unsigned int level)
 	curlevel = level;
 
 	/* scan for combos at empty spots */
-	int c = curcolor;
+	player_color c = curcolor;
 	for (spot_index s = PT(BSZ, BSZ) + 1; s-- > PT(1, 1); ) {
 		struct spotstr *sp = [s];
 		for (struct elist *ep = sp->s_empty; ep != NULL; ep = nep) {
@@ -953,7 +953,7 @@ makeempty(struct combostr *ocbp)
  * would be trying to "complete" the combo or trying to block it.
  */
 static void
-updatecombo(struct combostr *cbp, int color)
+updatecombo(struct combostr *cbp, player_color color)
 {
 	struct combostr *tcbp;
 	union comboval cb;
@@ -1041,7 +1041,7 @@ updatecombo(struct combostr *cbp, int co
  * Add combo to the end of the 

CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 21:02:37 UTC 2022

Modified Files:
src/games/gomoku: main.c pickmove.c

Log Message:
gomoku: migrate remaining functions to type player_color

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/games/gomoku/main.c
cvs rdiff -u -r1.64 -r1.65 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 20:21:29 UTC 2022

Modified Files:
src/games/gomoku: main.c

Log Message:
gomoku: make parsing of the debug command 'o' robust

Previously, the (invalid) debug command 'o,' succeeded to parse and led
to out-of-bounds memory access. Add proper parsing for the arguments of
that debug command. Add a short usage for that debug command, as
guessing the usage from the previous code was time-consuming due to the
large amount of ad-hoc low-level parsing code.

When leaving debug mode, clear the debug prompt.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/games/gomoku/main.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/main.c
diff -u src/games/gomoku/main.c:1.71 src/games/gomoku/main.c:1.72
--- src/games/gomoku/main.c:1.71	Sun May 29 17:01:42 2022
+++ src/games/gomoku/main.c	Sun May 29 20:21:28 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.71 2022/05/29 17:01:42 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.72 2022/05/29 20:21:28 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.71 2022/05/29 17:01:42 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.72 2022/05/29 20:21:28 rillig Exp $");
 
 #include 
 #include 
@@ -412,6 +412,59 @@ readinput(FILE *fp)
 }
 
 #ifdef DEBUG
+
+static bool
+skip_any(const char **pp, const char *s)
+{
+	while (strchr(s, **pp) != NULL)
+		(*pp)++;
+	return true;
+}
+
+static bool
+parse_char_index(const char **pp, const char *s, unsigned int *out)
+{
+	const char *found = strchr(s, **pp);
+	if (found != NULL)
+		*out = (unsigned int)(found - s), (*pp)++;
+	return found != NULL;
+}
+
+static bool
+parse_direction(const char **pp, direction *out)
+{
+	unsigned int u;
+	if (!parse_char_index(pp, "-\\|/", ))
+		return false;
+	*out = (direction)u;
+	return true;
+}
+
+static bool
+parse_row(const char **pp, unsigned int *out)
+{
+	if (!('0' <= **pp && **pp <= '9'))
+		return false;
+	unsigned int u = *(*pp)++ - '0';
+	if ('0' <= **pp && **pp <= '9')
+		u = 10 * u + *(*pp)++ - '0';
+	*out = u;
+	return 1 <= u && u <= BSZ;
+}
+
+static bool
+parse_spot(const char **pp, spot_index *out)
+{
+	unsigned row, col;
+	if (!parse_char_index(pp, "abcdefghjklmnopqrst", ) &&
+	!parse_char_index(pp, "ABCDEFGHJKLMNOPQRST", ))
+		return false;
+	if (!parse_row(pp, ))
+		return false;
+	*out = PT(col + 1, row);
+	return true;
+}
+
 /*
  * Handle strange situations and ^C.
  */
@@ -419,12 +472,13 @@ readinput(FILE *fp)
 void
 whatsup(int signum __unused)
 {
-	int n, d1, d2;
+	unsigned int n;
 	player_color color;
 	spot_index s, s1, s2;
+	direction r1, r2;
 	struct spotstr *sp;
 	FILE *fp;
-	char *str;
+	const char *str;
 	struct elist *ep;
 	struct combostr *cbp;
 	char input[128];
@@ -447,7 +501,8 @@ top:
 		debuglog("Debug set to %d", debug);
 		goto top;
 	case 'c':
-		break;
+		ask("");
+		return;
 	case 'b':		/* back up a move */
 		if (game.nmoves > 0) {
 			game.nmoves--;
@@ -485,30 +540,21 @@ top:
 		fclose(fp);
 		goto top;
 	case 'o':
-		/* avoid use w/o initialization on invalid input */
-		d1 = s1 = 0;
-
-		n = 0;
-		for (str = input + 1; *str != '\0'; str++)
-			if (*str == ',') {
-for (d1 = 0; d1 < 4; d1++)
-	if (str[-1] == pdir[d1])
-		break;
-str[-1] = '\0';
-sp = [s1 = ctos(input + 1)];
-n = sp->s_frame[d1] * FAREA;
-*str++ = '\0';
-break;
-			}
-		sp = [s2 = ctos(str)];
-		while (*str != '\0')
-			str++;
-		for (d2 = 0; d2 < 4; d2++)
-			if (str[-1] == pdir[d2])
-break;
-		n += sp->s_frame[d2];
-		debuglog("overlap %s%c,%s%c = %x", stoc(s1), pdir[d1],
-		stoc(s2), pdir[d2], overlap[n]);
+		str = input + 1;
+		if (skip_any(, " ") &&
+		parse_spot(, ) &&
+		parse_direction(, ) &&
+		skip_any(, ", ") &&
+		parse_spot(, ) &&
+		parse_direction(, ) &&
+		*str == '\0') {
+			n = board[s1].s_frame[r1] * FAREA
+			+ board[s2].s_frame[r2];
+			debuglog("overlap %s%c,%s%c = %02x",
+			stoc(s1), pdir[r1], stoc(s2), pdir[r2],
+			overlap[n]);
+		} else
+			debuglog("usage: o  ");
 		goto top;
 	case 'p':
 		sp = [s = ctos(input + 1)];
@@ -524,7 +570,7 @@ top:
 			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;
-	case 'e':	/* e {b|w} [0-9] spot */
+	case 'e':	/* e [0-9] spot */
 		str = input + 1;
 		if (*str >= '0' && *str <= '9')
 			n = *str++ - '0';



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 20:21:29 UTC 2022

Modified Files:
src/games/gomoku: main.c

Log Message:
gomoku: make parsing of the debug command 'o' robust

Previously, the (invalid) debug command 'o,' succeeded to parse and led
to out-of-bounds memory access. Add proper parsing for the arguments of
that debug command. Add a short usage for that debug command, as
guessing the usage from the previous code was time-consuming due to the
large amount of ad-hoc low-level parsing code.

When leaving debug mode, clear the debug prompt.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/games/gomoku/main.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 18:25:39 UTC 2022

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

Log Message:
gomoku: clean up overlap info in 'checkframes'

In 2009, GCC had complained that the overlap_info might only be
partially filled. All possible code paths are sane though, so that was
probably a bug in GCC.

Remove the comment and the unnecessary initialization, rename the
variable since it doesn't match its behavior anymore. Sync nearby
comments with reality; there is no array anywhere near.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 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/pickmove.c
diff -u src/games/gomoku/pickmove.c:1.63 src/games/gomoku/pickmove.c:1.64
--- src/games/gomoku/pickmove.c:1.63	Sun May 29 18:05:25 2022
+++ src/games/gomoku/pickmove.c	Sun May 29 18:25:39 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pickmove.c,v 1.63 2022/05/29 18:05:25 rillig Exp $	*/
+/*	$NetBSD: pickmove.c,v 1.64 2022/05/29 18:25:39 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)pickmove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: pickmove.c,v 1.63 2022/05/29 18:05:25 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.64 2022/05/29 18:25:39 rillig Exp $");
 
 #include 
 #include 
@@ -53,7 +53,7 @@ __RCSID("$NetBSD: pickmove.c,v 1.63 2022
  * This structure is used to store overlap information between frames.
  */
 struct overlap_info {
-	int		o_intersect;	/* intersection spot */
+	spot_index	o_intersect;	/* intersection spot */
 	u_char		o_off;		/* offset in frame of intersection */
 	u_char		o_frameindex;	/* intersection frame index */
 };
@@ -661,18 +661,9 @@ makecombo(struct combostr *ocbp, struct 
 	struct combostr **scbpp;
 	int baseB, fcnt, emask, verts;
 	union comboval ocb;
-	struct overlap_info vertices[1];
+	struct overlap_info ovi;
 	char tmp[128];
 
-	/*
-	 * XXX: when I made functions static gcc started warning about
-	 * some members of vertices[0] maybe being used uninitialized.
-	 * For now, I'm just going to clear it rather than wade through
-	 * the logic to find out whether gcc or the code is wrong. I
-	 * wouldn't be surprised if it were the code though. - dholland
-	 */
-	memset(vertices, 0, sizeof(vertices));
-
 	ocb.s = cv;
 	baseB = ocb.cv_force + ocb.cv_win - 1;
 	fcnt = ocb.cv_force - 2;
@@ -680,13 +671,13 @@ makecombo(struct combostr *ocbp, struct 
 	for (struct elist *ep = osp->s_empty; ep != NULL; ep = ep->e_next) {
 	/* check for various kinds of overlap */
 	cbp = ep->e_combo;
-	verts = checkframes(cbp, ocbp, osp, cv, vertices);
+	verts = checkframes(cbp, ocbp, osp, cv, );
 	if (verts < 0)
 		continue;
 
 	/* check to see if this frame forms a valid loop */
 	if (verts > 0) {
-		sp = [vertices[0].o_intersect];
+		sp = [ovi.o_intersect];
 #ifdef DEBUG
 		if (sp->s_occ != EMPTY) {
 		debuglog("loop: %c %s", "BW"[curcolor],
@@ -754,15 +745,14 @@ makecombo(struct combostr *ocbp, struct 
 	ncbp->c_emask[0] = ep->e_emask;
 	if (verts != 0) {
 		ncbp->c_flags |= C_LOOP;
-		ncbp->c_dir = vertices[0].o_frameindex;
+		ncbp->c_dir = ovi.o_frameindex;
 		ncbp->c_framecnt[1] = fcnt - 1;
 		if (ncbp->c_framecnt[1] != 0) {
-		n = (vertices[0].o_intersect - ocbp->c_vertex) /
-			dd[ocbp->c_dir];
+		n = (ovi.o_intersect - ocbp->c_vertex) / dd[ocbp->c_dir];
 		ncbp->c_emask[1] = emask & ~(1 << n);
 		} else
 		ncbp->c_emask[1] = 0;
-		ncbp->c_voff[0] = vertices[0].o_off;
+		ncbp->c_voff[0] = ovi.o_off;
 	} else {
 		ncbp->c_dir = 0;
 		ncbp->c_framecnt[1] = fcnt;
@@ -1074,14 +1064,14 @@ appendcombo(struct combostr *cbp, int co
  * Return zero if it is valid to combine frame 'fcbp' with the frames
  * in 'cbp' and forms a linked chain of frames (i.e., a tree; no loops).
  * Return positive if combining frame 'fcbp' to the frames in 'cbp'
- * would form some kind of valid loop. Also return the intersection spots
- * in 'vertices[]' beside the known intersection at spot 'osp'.
+ * would form some kind of valid loop. Also return the intersection spot
+ * in 'ovi' beside the known intersection at spot 'osp'.
  * Return -1 if 'fcbp' should not be combined with 'cbp'.
  * 'cv' is the combo value for frame 'fcbp'.
  */
 static int
 checkframes(struct combostr *cbp, struct combostr *fcbp, struct spotstr *osp,
-	u_short cv, struct overlap_info *vertices)
+	u_short cv, struct overlap_info *ovi)
 {
 	struct combostr *tcbp, *lcbp;
 	int ovbit, n, mask, flags, fcnt;
@@ -1148,10 +1138,10 @@ checkframes(struct combostr *cbp, struct
  s == fcbp->c_vertex + 5 * dd[fcbp->c_dir]))
 	return -1;	/* invalid overlap */
 
-vertices->o_intersect = s;
-vertices->o_off = (s - tcbp->c_vertex) /
+ovi->o_intersect = s;
+ovi->o_off = (s - tcbp->c_vertex) /
 	dd[tcbp->c_dir];
-

CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 18:25:39 UTC 2022

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

Log Message:
gomoku: clean up overlap info in 'checkframes'

In 2009, GCC had complained that the overlap_info might only be
partially filled. All possible code paths are sane though, so that was
probably a bug in GCC.

Remove the comment and the unnecessary initialization, rename the
variable since it doesn't match its behavior anymore. Sync nearby
comments with reality; there is no array anywhere near.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 18:05:25 UTC 2022

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

Log Message:
gomoku: do not scan the upper border for combos

Adding the '+ 1' to the row coordinate added an offset of 20, while the
intended offset was 1.

No functional change, just a bit faster.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 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/pickmove.c
diff -u src/games/gomoku/pickmove.c:1.62 src/games/gomoku/pickmove.c:1.63
--- src/games/gomoku/pickmove.c:1.62	Sun May 29 17:01:42 2022
+++ src/games/gomoku/pickmove.c	Sun May 29 18:05:25 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pickmove.c,v 1.62 2022/05/29 17:01:42 rillig Exp $	*/
+/*	$NetBSD: pickmove.c,v 1.63 2022/05/29 18:05:25 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)pickmove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: pickmove.c,v 1.62 2022/05/29 17:01:42 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.63 2022/05/29 18:05:25 rillig Exp $");
 
 #include 
 #include 
@@ -92,8 +92,8 @@ pickmove(player_color us)
 		return PT((BSZ + 1) / 2, (BSZ + 1) / 2);
 
 	/* initialize all the board values */
-	for (unsigned pos = PT(BSZ, BSZ + 1); pos-- > PT(1, 1); ) {
-		struct spotstr *sp = [pos];
+	for (spot_index s = PT(BSZ, BSZ) + 1; s-- > PT(1, 1); ) {
+		struct spotstr *sp = [s];
 		sp->s_combo[BLACK].s = 0x601;
 		sp->s_combo[WHITE].s = 0x601;
 		sp->s_level[BLACK] = 255;
@@ -358,8 +358,8 @@ scanframes(int color)
 	}
 
 	/* scan for combos at empty spots */
-	for (unsigned pos = PT(BSZ, BSZ + 1); pos-- > PT(1, 1); ) {
-		sp = [pos];
+	for (spot_index s = PT(BSZ, BSZ) + 1; s-- > PT(1, 1); ) {
+		sp = [s];
 		for (struct elist *ep = sp->s_empty; ep != NULL; ep = nep) {
 			cbp = ep->e_combo;
 			if (cbp->c_combo.s <= sp->s_combo[color].s) {
@@ -566,8 +566,8 @@ addframes(unsigned int level)
 
 	/* scan for combos at empty spots */
 	int c = curcolor;
-	for (unsigned pos = PT(BSZ, BSZ + 1); pos-- > PT(1, 1); ) {
-		struct spotstr *sp = [pos];
+	for (spot_index s = PT(BSZ, BSZ) + 1; s-- > PT(1, 1); ) {
+		struct spotstr *sp = [s];
 		for (struct elist *ep = sp->s_empty; ep != NULL; ep = nep) {
 			cbp = ep->e_combo;
 			if (cbp->c_combo.s <= sp->s_combo[c].s) {



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 18:05:25 UTC 2022

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

Log Message:
gomoku: do not scan the upper border for combos

Adding the '+ 1' to the row coordinate added an offset of 20, while the
intended offset was 1.

No functional change, just a bit faster.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 17:01:42 UTC 2022

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

Log Message:
gomoku: refine the type of some functions and variables

Assisted by WARNS=6. At that level, there are several warnings about
type conversion between small integer types that would only clutter the
code, therefore stay at WARNS=5. Same for lint's -aa option.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/games/gomoku/Makefile
cvs rdiff -u -r1.54 -r1.55 src/games/gomoku/bdisp.c src/games/gomoku/gomoku.h
cvs rdiff -u -r1.70 -r1.71 src/games/gomoku/main.c
cvs rdiff -u -r1.41 -r1.42 src/games/gomoku/makemove.c
cvs rdiff -u -r1.61 -r1.62 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/Makefile
diff -u src/games/gomoku/Makefile:1.10 src/games/gomoku/Makefile:1.11
--- src/games/gomoku/Makefile:1.10	Sat May 21 14:55:26 2022
+++ src/games/gomoku/Makefile	Sun May 29 17:01:42 2022
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.10 2022/05/21 14:55:26 rillig Exp $
+#	$NetBSD: Makefile,v 1.11 2022/05/29 17:01:42 rillig Exp $
 #	@(#)Makefile	8.1 (Berkeley) 7/24/94
 
 PROG=	gomoku
@@ -9,6 +9,7 @@ LDADD=	-lcurses -lterminfo
 HIDEGAME=hidegame
 CPPFLAGS+=	${DEBUG:D-DDEBUG}
 
+#WARNS=		6	# would produce warnings about small integer types
 LINTFLAGS+=	-w	# treat warnings as errors
 LINTFLAGS+=	-T	# strict bool mode
 LINTFLAGS+=	-e	# strict enum checks

Index: src/games/gomoku/bdisp.c
diff -u src/games/gomoku/bdisp.c:1.54 src/games/gomoku/bdisp.c:1.55
--- src/games/gomoku/bdisp.c:1.54	Sun May 29 16:30:44 2022
+++ src/games/gomoku/bdisp.c	Sun May 29 17:01:42 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdisp.c,v 1.54 2022/05/29 16:30:44 rillig Exp $	*/
+/*	$NetBSD: bdisp.c,v 1.55 2022/05/29 17:01:42 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)bdisp.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdisp.c,v 1.54 2022/05/29 16:30:44 rillig Exp $");
+__RCSID("$NetBSD: bdisp.c,v 1.55 2022/05/29 17:01:42 rillig Exp $");
 
 #include 
 #include 
@@ -167,12 +167,12 @@ should_highlight(spot_index s)
 void
 bdisp(void)
 {
-	int c;
 	struct spotstr *sp;
 
 	for (int row = BSZ + 1; --row > 0; ) {
 		for (int col = 1; col <= BSZ; col++) {
 			sp = [PT(col, row)];
+			char c;
 			if (debug > 1 && sp->s_occ == EMPTY) {
 if ((sp->s_flags & IFLAGALL) != 0)
 	c = '+';
@@ -285,7 +285,6 @@ get_line(char *buf, int size, void (*on_
 	char *cp, *end;
 	int c;
 
-	c = 0;
 	cp = buf;
 	end = buf + size - 1;	/* save room for the '\0' */
 	while ((c = getchar()) != EOF && c != '\n' && c != '\r') {
@@ -352,7 +351,7 @@ get_coord_mouse(int *x, int *y)
  * Based on Eric S. Raymond's modifications to the battleship (bs) user
  * interface.
  */
-int
+spot_index
 get_coord(void)
 {
 	int x = game.user_x, y = game.user_y;
Index: src/games/gomoku/gomoku.h
diff -u src/games/gomoku/gomoku.h:1.54 src/games/gomoku/gomoku.h:1.55
--- src/games/gomoku/gomoku.h:1.54	Sun May 29 16:30:44 2022
+++ src/games/gomoku/gomoku.h	Sun May 29 17:01:42 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: gomoku.h,v 1.54 2022/05/29 16:30:44 rillig Exp $	*/
+/*	$NetBSD: gomoku.h,v 1.55 2022/05/29 17:01:42 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -256,7 +256,7 @@ extern bool interactive;
 extern const char *plyr[];
 
 void	init_board(void);
-int	get_coord(void);
+spot_index get_coord(void);
 int	get_key(const char *);
 bool	get_line(char *, int, void (*)(const char *));
 void	ask(const char *);

Index: src/games/gomoku/main.c
diff -u src/games/gomoku/main.c:1.70 src/games/gomoku/main.c:1.71
--- src/games/gomoku/main.c:1.70	Sun May 29 14:37:44 2022
+++ src/games/gomoku/main.c	Sun May 29 17:01:42 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.70 2022/05/29 14:37:44 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.71 2022/05/29 17:01:42 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.70 2022/05/29 14:37:44 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.71 2022/05/29 17:01:42 rillig Exp $");
 
 #include 
 #include 
@@ -82,7 +82,7 @@ spot_index intersect[FAREA * FAREA];	/* 
 struct game game;
 const char *plyr[2] = { "???", "???" };	/* who's who */
 
-static int readinput(FILE *);
+static spot_index readinput(FILE *);
 static void misclog(const char *, ...) __printflike(1, 2);
 static void quit(void) __dead;
 #if !defined(DEBUG)
@@ -281,10 +281,8 @@ struct outcome {
 static struct outcome
 main_game_loop(enum input_source *input)
 {
-	int color, curmove, outcome;
-
-	curmove = 0;		/* for GCC */
-	color = BLACK;
+	spot_index curmove = 0;
+	player_color color = BLACK;
 
 again:
 	switch (input[color]) {
@@ -316,6 

CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 17:01:42 UTC 2022

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

Log Message:
gomoku: refine the type of some functions and variables

Assisted by WARNS=6. At that level, there are several warnings about
type conversion between small integer types that would only clutter the
code, therefore stay at WARNS=5. Same for lint's -aa option.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/games/gomoku/Makefile
cvs rdiff -u -r1.54 -r1.55 src/games/gomoku/bdisp.c src/games/gomoku/gomoku.h
cvs rdiff -u -r1.70 -r1.71 src/games/gomoku/main.c
cvs rdiff -u -r1.41 -r1.42 src/games/gomoku/makemove.c
cvs rdiff -u -r1.61 -r1.62 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 16:30:44 UTC 2022

Modified Files:
src/games/gomoku: bdinit.c bdisp.c gomoku.h

Log Message:
gomoku: when starting a new game, start in the middle of the board

Previously, when starting a new game, the user coordinate was kept at
the previously selected spot. Since playing in the center is common
sense, reset the coordinate.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.53 -r1.54 src/games/gomoku/bdisp.c src/games/gomoku/gomoku.h

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/bdinit.c
diff -u src/games/gomoku/bdinit.c:1.34 src/games/gomoku/bdinit.c:1.35
--- src/games/gomoku/bdinit.c:1.34	Sun May 29 14:37:44 2022
+++ src/games/gomoku/bdinit.c	Sun May 29 16:30:44 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdinit.c,v 1.34 2022/05/29 14:37:44 rillig Exp $	*/
+/*	$NetBSD: bdinit.c,v 1.35 2022/05/29 16:30:44 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	from: @(#)bdinit.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdinit.c,v 1.34 2022/05/29 14:37:44 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.35 2022/05/29 16:30:44 rillig Exp $");
 
 #include 
 #include "gomoku.h"
@@ -130,6 +130,8 @@ init_board(void)
 
 	game.nmoves = 0;
 	game.win_spot = 0;
+	game.user_x = 1 + (BSZ - 1) / 2;
+	game.user_y = 1 + (BSZ - 1) / 2;
 
 	struct spotstr *sp = board;
 	for (int i = 0; i < 1 + BSZ + 1; i++, sp++) {

Index: src/games/gomoku/bdisp.c
diff -u src/games/gomoku/bdisp.c:1.53 src/games/gomoku/bdisp.c:1.54
--- src/games/gomoku/bdisp.c:1.53	Sun May 29 16:19:52 2022
+++ src/games/gomoku/bdisp.c	Sun May 29 16:30:44 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdisp.c,v 1.53 2022/05/29 16:19:52 rillig Exp $	*/
+/*	$NetBSD: bdisp.c,v 1.54 2022/05/29 16:30:44 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)bdisp.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdisp.c,v 1.53 2022/05/29 16:19:52 rillig Exp $");
+__RCSID("$NetBSD: bdisp.c,v 1.54 2022/05/29 16:30:44 rillig Exp $");
 
 #include 
 #include 
@@ -355,8 +355,7 @@ get_coord_mouse(int *x, int *y)
 int
 get_coord(void)
 {
-	static int x = 1 + (BSZ - 1) / 2;
-	static int y = 1 + (BSZ - 1) / 2;
+	int x = game.user_x, y = game.user_y;
 
 	move(scr_y(y), scr_x(x));
 	refresh();
@@ -457,6 +456,8 @@ get_coord(void)
 		case '\r':
 		selected:
 			(void)mvhline(BSZ + 3, 6, ' ', 6);
+			game.user_x = x;
+			game.user_y = y;
 			return PT(x, y);
 		}
 
Index: src/games/gomoku/gomoku.h
diff -u src/games/gomoku/gomoku.h:1.53 src/games/gomoku/gomoku.h:1.54
--- src/games/gomoku/gomoku.h:1.53	Sun May 29 15:31:12 2022
+++ src/games/gomoku/gomoku.h	Sun May 29 16:30:44 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: gomoku.h,v 1.53 2022/05/29 15:31:12 rillig Exp $	*/
+/*	$NetBSD: gomoku.h,v 1.54 2022/05/29 16:30:44 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -236,6 +236,8 @@ struct game {
 	spot_index	moves[BSZ * BSZ]; /* log of all played moves */
 	spot_index	win_spot;	/* the winning move, or 0 */
 	direction	win_dir;
+	int		user_x;
+	int		user_y;
 };
 
 extern	const char	letters[];



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 16:30:44 UTC 2022

Modified Files:
src/games/gomoku: bdinit.c bdisp.c gomoku.h

Log Message:
gomoku: when starting a new game, start in the middle of the board

Previously, when starting a new game, the user coordinate was kept at
the previously selected spot. Since playing in the center is common
sense, reset the coordinate.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.53 -r1.54 src/games/gomoku/bdisp.c src/games/gomoku/gomoku.h

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 16:19:52 UTC 2022

Modified Files:
src/games/gomoku: bdisp.c

Log Message:
gomoku: after accepting a spot via the mouse, clear current coordinate


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/games/gomoku/bdisp.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/bdisp.c
diff -u src/games/gomoku/bdisp.c:1.52 src/games/gomoku/bdisp.c:1.53
--- src/games/gomoku/bdisp.c:1.52	Sun May 29 14:37:44 2022
+++ src/games/gomoku/bdisp.c	Sun May 29 16:19:52 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdisp.c,v 1.52 2022/05/29 14:37:44 rillig Exp $	*/
+/*	$NetBSD: bdisp.c,v 1.53 2022/05/29 16:19:52 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)bdisp.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdisp.c,v 1.52 2022/05/29 14:37:44 rillig Exp $");
+__RCSID("$NetBSD: bdisp.c,v 1.53 2022/05/29 16:19:52 rillig Exp $");
 
 #include 
 #include 
@@ -444,7 +444,7 @@ get_coord(void)
 			break;
 		case KEY_MOUSE:
 			if (get_coord_mouse(, ))
-return PT(x, y);
+goto selected;
 			beep();
 			break;
 		case 'Q':
@@ -455,6 +455,7 @@ get_coord(void)
 			return SAVE;
 		case ' ':
 		case '\r':
+		selected:
 			(void)mvhline(BSZ + 3, 6, ' ', 6);
 			return PT(x, y);
 		}



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 16:19:52 UTC 2022

Modified Files:
src/games/gomoku: bdisp.c

Log Message:
gomoku: after accepting a spot via the mouse, clear current coordinate


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/games/gomoku/bdisp.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
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 
 /*	@(#)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 = >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 
 /*	@(#)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 
 #include 
@@ -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 

CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
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.



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 15:16:11 UTC 2022

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

Log Message:
gomoku: use unsigned integers for bit sets

As all access to the bit sets happens through the unsigned spot_index
type, drop the type casts in the macros.

No functional change on 2s complement machines.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 15:16:11 UTC 2022

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

Log Message:
gomoku: use unsigned integers for bit sets

As all access to the bit sets happens through the unsigned spot_index
type, drop the type casts in the macros.

No functional change on 2s complement machines.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 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/pickmove.c
diff -u src/games/gomoku/pickmove.c:1.59 src/games/gomoku/pickmove.c:1.60
--- src/games/gomoku/pickmove.c:1.59	Sun May 29 14:37:44 2022
+++ src/games/gomoku/pickmove.c	Sun May 29 15:16:11 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pickmove.c,v 1.59 2022/05/29 14:37:44 rillig Exp $	*/
+/*	$NetBSD: pickmove.c,v 1.60 2022/05/29 15:16:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)pickmove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: pickmove.c,v 1.59 2022/05/29 14:37:44 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.60 2022/05/29 15:16:11 rillig Exp $");
 
 #include 
 #include 
@@ -46,8 +46,8 @@ __RCSID("$NetBSD: pickmove.c,v 1.59 2022
 #define BITS_PER_INT	(sizeof(int) * CHAR_BIT)
 #define MAPSZ		(BAREA / BITS_PER_INT)
 
-#define BIT_SET(a, b)	((a)[(unsigned int)(b)/BITS_PER_INT] |= (1 << ((unsigned int)(b) % BITS_PER_INT)))
-#define BIT_TEST(a, b)	(((a)[(unsigned int)(b)/BITS_PER_INT] & (1 << ((unsigned int)(b) % BITS_PER_INT))) != 0)
+#define BIT_SET(a, b)	((a)[(b)/BITS_PER_INT] |= (1U << ((b) % BITS_PER_INT)))
+#define BIT_TEST(a, b)	(((a)[(b)/BITS_PER_INT] & (1U << ((b) % BITS_PER_INT))) != 0)
 
 /*
  * This structure is used to store overlap information between frames.
@@ -64,8 +64,8 @@ static int combolen;			/* number of comb
 static int nextcolor;			/* color of next move */
 static int elistcnt;			/* count of struct elist allocated */
 static int combocnt;			/* count of struct combostr allocated */
-static int forcemap[MAPSZ];		/* map for blocking <1,x> combos */
-static int tmpmap[MAPSZ];		/* map for blocking <1,x> combos */
+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);



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 14:50:37 UTC 2022

Modified Files:
src/games/gomoku: gomoku.h

Log Message:
gomoku: provide a more gentle introduction to the code

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/games/gomoku/gomoku.h

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.51 src/games/gomoku/gomoku.h:1.52
--- src/games/gomoku/gomoku.h:1.51	Sun May 29 14:37:44 2022
+++ src/games/gomoku/gomoku.h	Sun May 29 14:50:37 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: gomoku.h,v 1.51 2022/05/29 14:37:44 rillig Exp $	*/
+/*	$NetBSD: gomoku.h,v 1.52 2022/05/29 14:50:37 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -40,27 +40,32 @@
 #include 
 
 /*
- * The board consists of 19x19 spots, the coordinates are 1-based. The board
- * is surrounded by border spots.
+ * The gomoku 'board' mainly consists of the playing area of BSZ x BSZ spots.
+ * The playing area uses 1-based coordinates. Around the playing area is a
+ * rectangle of border spots, to avoid having to check the coordinates when
+ * calculating spot coordinates. The left and right border overlap, to save a
+ * few bytes.
  */
 
 #define BSZ	19
 #define BAREA	((1 + BSZ + 1) * (BSZ + 1) + 1)
 
 /*
- * A 'frame' is a group of five or six contiguous board locations. An
+ * A 'frame' is a group of five or six contiguous spots on the board. An
  * open-ended frame is one with spaces on both ends; otherwise, it is closed.
  */
 #define FAREA	(2 * BSZ * (BSZ - 4) + 2 * (BSZ - 4) * (BSZ - 4))
 
-/* values for s_occ */
+
+/* The content of a spot on the board; used in s_occ. */
 #define BLACK	0
 #define WHITE	1
 #define EMPTY	2
 #define BORDER	3
 
-/* A spot on the board, or in some cases one of the below special values. */
+/* 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))
 /* return values for makemove, readinput */
 #define MOVEOK	0
 #define RESIGN	1
@@ -69,11 +74,11 @@ typedef unsigned short spot_index;
 #define TIE	4
 #define SAVE	5
 #define END_OF_INPUT 6
-#define PT(x, y)	((x) + (BSZ + 1) * (y))
 
 /*
- * A 'combo' is a group of intersecting frames and consists of two numbers:
- * 'F' is the number of moves to make the combo non-blockable.
+ * A 'combo' is a group of intersecting or overlapping frames and consists of
+ * two numbers:
+ * 'F' is the number of moves still needed 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.



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 14:50:37 UTC 2022

Modified Files:
src/games/gomoku: gomoku.h

Log Message:
gomoku: provide a more gentle introduction to the code

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/games/gomoku/gomoku.h

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 14:37:44 UTC 2022

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

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

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.51 -r1.52 src/games/gomoku/bdisp.c
cvs rdiff -u -r1.50 -r1.51 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.69 -r1.70 src/games/gomoku/main.c
cvs rdiff -u -r1.39 -r1.40 src/games/gomoku/makemove.c
cvs rdiff -u -r1.58 -r1.59 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/bdinit.c
diff -u src/games/gomoku/bdinit.c:1.33 src/games/gomoku/bdinit.c:1.34
--- src/games/gomoku/bdinit.c:1.33	Sun May 29 14:01:57 2022
+++ src/games/gomoku/bdinit.c	Sun May 29 14:37:44 2022
@@ -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 
 /*	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 
 #include "gomoku.h"
@@ -42,11 +42,11 @@ __RCSID("$NetBSD: bdinit.c,v 1.33 2022/0
 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 @@ init_spot_flags_and_fval(struct spotstr 
 		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 @@ init_spot_flags_and_fval(struct spotstr 
 		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 @@ init_spot_flags_and_fval(struct spotstr 
 	} 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 @@ init_board(void)
 {
 
 	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++) {

Index: src/games/gomoku/bdisp.c
diff -u src/games/gomoku/bdisp.c:1.51 src/games/gomoku/bdisp.c:1.52
--- src/games/gomoku/bdisp.c:1.51	Sun May 29 00:12:11 2022
+++ src/games/gomoku/bdisp.c	Sun May 29 14:37:44 2022
@@ -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 
 /*	@(#)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 
 #include 
@@ -98,15 +98,15 @@ bdisp_init(void)
 {
 
 	/* 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 @@ should_highlight(spot_index s)
 
 	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 + 

CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 14:37:44 UTC 2022

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

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

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.51 -r1.52 src/games/gomoku/bdisp.c
cvs rdiff -u -r1.50 -r1.51 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.69 -r1.70 src/games/gomoku/main.c
cvs rdiff -u -r1.39 -r1.40 src/games/gomoku/makemove.c
cvs rdiff -u -r1.58 -r1.59 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 14:01:58 UTC 2022

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

Log Message:
gomoku: consistently name the offset of a spot in a frame 'off'

Leave 'i' for general purpose loops.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.38 -r1.39 src/games/gomoku/makemove.c
cvs rdiff -u -r1.57 -r1.58 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/bdinit.c
diff -u src/games/gomoku/bdinit.c:1.32 src/games/gomoku/bdinit.c:1.33
--- src/games/gomoku/bdinit.c:1.32	Sun May 29 13:49:10 2022
+++ src/games/gomoku/bdinit.c	Sun May 29 14:01:57 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdinit.c,v 1.32 2022/05/29 13:49:10 rillig Exp $	*/
+/*	$NetBSD: bdinit.c,v 1.33 2022/05/29 14:01:57 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	from: @(#)bdinit.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdinit.c,v 1.32 2022/05/29 13:49:10 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.33 2022/05/29 14:01:57 rillig Exp $");
 
 #include 
 #include "gomoku.h"
@@ -166,9 +166,8 @@ init_board(void)
  * Variable names for frames A and B:
  *
  * fi	index of the frame in the global 'frames'
- * r	direction: 0 = right, 1 = down right, 2 = down, 3 = down left
  * d	direction delta, difference between adjacent spot indexes
- * si	index of the spot in the frame, 0 to 5
+ * off	index of the spot in the frame, 0 to 5
  */
 
 /*
@@ -191,36 +190,36 @@ init_board(void)
  * spot will be removed from the overlap array by setting the entry to 0.
  */
 static u_char
-adjust_overlap(u_char ov, int ra, int sia, int rb, int sib, int mask)
+adjust_overlap(u_char ov, int ra, int offa, int rb, int offb, int mask)
 {
-	ov |= (sib == 5) ? mask & 0xA : mask;
+	ov |= (offb == 5) ? mask & 0xA : mask;
 	if (rb != ra)
 		return ov;
 
 	/* compute the multiple spot overlap values */
-	switch (sia) {
+	switch (offa) {
 	case 0:
-		if (sib == 4)
+		if (offb == 4)
 			ov |= 0xA0;
-		else if (sib != 5)
+		else if (offb != 5)
 			ov |= 0xF0;
 		break;
 	case 1:
-		if (sib == 5)
+		if (offb == 5)
 			ov |= 0xA0;
 		else
 			ov |= 0xF0;
 		break;
 	case 4:
-		if (sib == 0)
+		if (offb == 0)
 			ov |= 0xC0;
 		else
 			ov |= 0xF0;
 		break;
 	case 5:
-		if (sib == 1)
+		if (offb == 1)
 			ov |= 0xC0;
-		else if (sib != 0)
+		else if (offb != 0)
 			ov |= 0xF0;
 		break;
 	default:
@@ -235,15 +234,15 @@ adjust_overlap(u_char ov, int ra, int si
  * each frame B that overlaps frame A in that spot.
  */
 static void
-init_overlap_frame(int fia, int ra, int sia, spot_index s, int mask)
+init_overlap_frame(int fia, int ra, int offa, spot_index s, int mask)
 {
 
 	for (int rb = 4; --rb >= 0;) {
 		int db = dd[rb];
 
-		for (int sib = 0; sib < 6; sib++) {
+		for (int offb = 0; offb < 6; offb++) {
 			/* spb0 is the spot where frame B starts. */
-			const struct spotstr *spb0 = [s - sib * db];
+			const struct spotstr *spb0 = [s - offb * db];
 			if (spb0->s_occ == BORDER)
 break;
 			if ((spb0->s_flags & BFLAG << rb) != 0)
@@ -252,7 +251,7 @@ init_overlap_frame(int fia, int ra, int 
 			frame_index fib = spb0->s_frame[rb];
 			intersect[fia * FAREA + fib] = s;
 			u_char *op = [fia * FAREA + fib];
-			*op = adjust_overlap(*op, ra, sia, rb, sib, mask);
+			*op = adjust_overlap(*op, ra, offa, rb, offb, mask);
 		}
 	}
 }
@@ -276,11 +275,11 @@ init_overlap(void)
 		 */
 		int len = 5 + board[s].s_fval[BLACK][ra].cv_win;
 
-		for (int sia = 0; sia < len; sia++) {
+		for (int offa = 0; offa < len; offa++) {
 			/* spot[5] in frame A only overlaps if it is open */
-			int mask = (sia == 5) ? 0xC : 0xF;
+			int mask = (offa == 5) ? 0xC : 0xF;
 
-			init_overlap_frame(fia, ra, sia, s + sia * da, mask);
+			init_overlap_frame(fia, ra, offa, s + offa * da, mask);
 		}
 	}
 }

Index: src/games/gomoku/makemove.c
diff -u src/games/gomoku/makemove.c:1.38 src/games/gomoku/makemove.c:1.39
--- src/games/gomoku/makemove.c:1.38	Sun May 29 13:49:10 2022
+++ src/games/gomoku/makemove.c	Sun May 29 14:01:57 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: makemove.c,v 1.38 2022/05/29 13:49:10 rillig Exp $	*/
+/*	$NetBSD: makemove.c,v 1.39 2022/05/29 14:01:57 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)makemove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: makemove.c,v 1.38 2022/05/29 13:49:10 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.39 2022/05/29 14:01:57 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -134,7 +134,7 @@ makemove(int us, spot_index mv)
 		bool space = fsp->s_occ == EMPTY;
 		int n = 0;
 		sp = fsp;
-		for (int i = 5; --i >= 0; sp += d) {	/* for each spot */
+		for (int off = 5; off-- > 0; sp += d) {	/* for each spot */
 		if (sp->s_occ == us)
 			n++;
 		else if (sp->s_occ == EMPTY)
@@ -144,7 +144,7 @@ makemove(int us, 

CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 14:01:58 UTC 2022

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

Log Message:
gomoku: consistently name the offset of a spot in a frame 'off'

Leave 'i' for general purpose loops.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.38 -r1.39 src/games/gomoku/makemove.c
cvs rdiff -u -r1.57 -r1.58 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 13:49:10 UTC 2022

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

Log Message:
gomoku: add data type for one of the 4 directions of a frame

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.49 -r1.50 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.37 -r1.38 src/games/gomoku/makemove.c
cvs rdiff -u -r1.56 -r1.57 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/bdinit.c
diff -u src/games/gomoku/bdinit.c:1.31 src/games/gomoku/bdinit.c:1.32
--- src/games/gomoku/bdinit.c:1.31	Sun May 29 11:36:12 2022
+++ src/games/gomoku/bdinit.c	Sun May 29 13:49:10 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdinit.c,v 1.31 2022/05/29 11:36:12 rillig Exp $	*/
+/*	$NetBSD: bdinit.c,v 1.32 2022/05/29 13:49:10 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	from: @(#)bdinit.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdinit.c,v 1.31 2022/05/29 11:36:12 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.32 2022/05/29 13:49:10 rillig Exp $");
 
 #include 
 #include "gomoku.h"
@@ -109,7 +109,7 @@ static void
 init_spot_frame(struct spotstr *sp, frame_index *fip)
 {
 
-	for (int r = 4; --r >= 0; ) {
+	for (direction r = 4; r-- > 0; ) {
 		if ((sp->s_flags & (BFLAG << r)) != 0)
 			continue;
 

Index: src/games/gomoku/gomoku.h
diff -u src/games/gomoku/gomoku.h:1.49 src/games/gomoku/gomoku.h:1.50
--- src/games/gomoku/gomoku.h:1.49	Sun May 29 10:37:21 2022
+++ src/games/gomoku/gomoku.h	Sun May 29 13:49:10 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: gomoku.h,v 1.49 2022/05/29 10:37:21 rillig Exp $	*/
+/*	$NetBSD: gomoku.h,v 1.50 2022/05/29 13:49:10 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -190,18 +190,21 @@ struct	elist {
 /* The index of a frame in the global 'frames'. */
 typedef unsigned short frame_index;
 
+/* 0 = right, 1 = down right, 2 = down, 3 = down left. */
+typedef unsigned char direction;
+
 /*
  * One spot structure for each location on the board.
- * A frame consists of the combination for the current spot plus the five spots
- * 0: right, 1: right & down, 2: down, 3: down & left.
+ * A frame consists of the combination for the current spot plus the next
+ * five spots in the direction.
  */
 struct	spotstr {
 	short		s_occ;		/* color of occupant */
 	short		s_wval;		/* weighted value */
 	int		s_flags;	/* flags for graph walks */
 	frame_index	s_frame[4];	/* level 1 combo for [dir] */
-	union comboval	s_fval[2][4];	/* combo value for [color][frame] */
-	union comboval	s_combo[2];	/* minimum combo value for BLK & WHT */
+	union comboval	s_fval[2][4];	/* combo value for [color][dir] */
+	union comboval	s_combo[2];	/* minimum combo value for [color] */
 	u_char		s_level[2];	/* number of frames in the min combo */
 	u_char		s_nforce[2];	/* number of <1,x> combos */
 	struct elist	*s_empty;	/* level n combo completion spots */
@@ -221,10 +224,10 @@ struct	spotstr {
 #define BFLAGALL	0x0F	/* all frames dead */
 
 struct game {
-	spot_index moves[BSZ * BSZ];	/* log of all played moves */
-	unsigned int nmoves;		/* number of played moves */
-	spot_index winning_spot;
-	int winning_dir;
+	unsigned int	nmoves;		/* number of played moves */
+	spot_index	moves[BSZ * BSZ]; /* log of all played moves */
+	spot_index	winning_spot;
+	direction	winning_dir;
 };
 
 extern	const char	letters[];

Index: src/games/gomoku/makemove.c
diff -u src/games/gomoku/makemove.c:1.37 src/games/gomoku/makemove.c:1.38
--- src/games/gomoku/makemove.c:1.37	Sun May 29 11:36:12 2022
+++ src/games/gomoku/makemove.c	Sun May 29 13:49:10 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: makemove.c,v 1.37 2022/05/29 11:36:12 rillig Exp $	*/
+/*	$NetBSD: makemove.c,v 1.38 2022/05/29 13:49:10 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)makemove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: makemove.c,v 1.37 2022/05/29 11:36:12 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.38 2022/05/29 13:49:10 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -77,7 +77,7 @@ sortframes_remove(struct combostr *cbp)
 }
 
 static int
-old_weight_value(const struct spotstr *sp, int r)
+old_weight_value(const struct spotstr *sp, direction r)
 {
 	union comboval cb;
 	int val = 0;
@@ -115,7 +115,7 @@ makemove(int us, spot_index mv)
 
 	/* compute new frame values */
 	sp->s_wval = 0;
-	for (int r = 4; --r >= 0; ) {		/* for each direction */
+	for (direction r = 4; r-- > 0; ) {
 	int d = dd[r];
 	struct spotstr *fsp = [mv];
 
@@ -161,7 +161,8 @@ makemove(int us, spot_index mv)
 		}
 
 		/* compute new value & combo number for this frame & color */
-		fsp->s_fval[us != BLACK ? BLACK : WHITE][r].s = 0x600;
+		int them = us != BLACK ? BLACK : WHITE;
+		fsp->s_fval[them][r].s = 0x600;
 		union comboval *cp = >s_fval[us][r];
 		/* 

CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 13:49:10 UTC 2022

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

Log Message:
gomoku: add data type for one of the 4 directions of a frame

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.49 -r1.50 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.37 -r1.38 src/games/gomoku/makemove.c
cvs rdiff -u -r1.56 -r1.57 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 12:44:17 UTC 2022

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

Log Message:
gomoku: clean up four_in_a_row

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 12:44:17 UTC 2022

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

Log Message:
gomoku: clean up four_in_a_row

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 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/pickmove.c
diff -u src/games/gomoku/pickmove.c:1.55 src/games/gomoku/pickmove.c:1.56
--- src/games/gomoku/pickmove.c:1.55	Sun May 29 12:20:07 2022
+++ src/games/gomoku/pickmove.c	Sun May 29 12:44:17 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pickmove.c,v 1.55 2022/05/29 12:20:07 rillig Exp $	*/
+/*	$NetBSD: pickmove.c,v 1.56 2022/05/29 12:44:17 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)pickmove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: pickmove.c,v 1.55 2022/05/29 12:20:07 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.56 2022/05/29 12:44:17 rillig Exp $");
 
 #include 
 #include 
@@ -184,8 +184,9 @@ pickmove(int us)
 	 * away from completing a force, and we don't have a force that
 	 * we can complete which takes fewer moves to win).
 	 */
-	if (Tcp->cv_force <= 1 && (Ocp->cv_force > 1 ||
-	Tcp->cv_force + Tcp->cv_win < Ocp->cv_force + Ocp->cv_win))
+	if (Tcp->cv_force <= 1 &&
+	!(Ocp->cv_force <= 1 &&
+	  Tcp->cv_force + Tcp->cv_win >= Ocp->cv_force + Ocp->cv_win))
 		return s2;
 	return s1;
 }
@@ -226,15 +227,15 @@ static int curcolor;	/* implicit paramet
 static unsigned int curlevel;	/* implicit parameter to makecombo() */
 
 static bool
-quick_check(int color, struct combostr *cbp)
+four_in_a_row(int color, spot_index s, int r)
 {
 
-	struct spotstr *sp = [cbp->c_vertex];
-	union comboval cb = { .s = sp->s_fval[color][cbp->c_dir].s };
+	struct spotstr *sp = [s];
+	union comboval cb = { .s = sp->s_fval[color][r].s };
 	if (cb.s >= 0x101)
 		return false;
 
-	for (int i = 5 + cb.cv_win, d = dd[cbp->c_dir]; --i >= 0; sp += d) {
+	for (int i = 5 + cb.cv_win, d = dd[r]; --i >= 0; sp += d) {
 		if (sp->s_occ != EMPTY)
 			continue;
 		sp->s_combo[color].s = cb.s;
@@ -265,8 +266,7 @@ scanframes(int color)
 	if (cbp == NULL)
 		return;
 
-	/* quick check for four in a row */
-	if (quick_check(color, cbp))
+	if (four_in_a_row(color, cbp->c_vertex, cbp->c_dir))
 		return;
 
 	/*



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 12:20:07 UTC 2022

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

Log Message:
gomoku: extract quick_check from scanframes

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 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/pickmove.c
diff -u src/games/gomoku/pickmove.c:1.54 src/games/gomoku/pickmove.c:1.55
--- src/games/gomoku/pickmove.c:1.54	Sun May 29 11:36:12 2022
+++ src/games/gomoku/pickmove.c	Sun May 29 12:20:07 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pickmove.c,v 1.54 2022/05/29 11:36:12 rillig Exp $	*/
+/*	$NetBSD: pickmove.c,v 1.55 2022/05/29 12:20:07 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)pickmove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: pickmove.c,v 1.54 2022/05/29 11:36:12 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.55 2022/05/29 12:20:07 rillig Exp $");
 
 #include 
 #include 
@@ -225,6 +225,24 @@ better(spot_index s, spot_index s1, int 
 static int curcolor;	/* implicit parameter to makecombo() */
 static unsigned int curlevel;	/* implicit parameter to makecombo() */
 
+static bool
+quick_check(int color, struct combostr *cbp)
+{
+
+	struct spotstr *sp = [cbp->c_vertex];
+	union comboval cb = { .s = sp->s_fval[color][cbp->c_dir].s };
+	if (cb.s >= 0x101)
+		return false;
+
+	for (int i = 5 + cb.cv_win, d = dd[cbp->c_dir]; --i >= 0; sp += d) {
+		if (sp->s_occ != EMPTY)
+			continue;
+		sp->s_combo[color].s = cb.s;
+		sp->s_level[color] = 1;
+	}
+	return true;
+}
+
 /*
  * Scan the sorted list of non-empty frames and
  * update the minimum combo values for each empty spot.
@@ -248,18 +266,8 @@ scanframes(int color)
 		return;
 
 	/* quick check for four in a row */
-	sp = [cbp->c_vertex];
-	cb.s = sp->s_fval[color][cbp->c_dir].s;
-	if (cb.s < 0x101) {
-		int delta = dd[cbp->c_dir];
-		for (i = 5 + cb.cv_win; --i >= 0; sp += delta) {
-			if (sp->s_occ != EMPTY)
-continue;
-			sp->s_combo[color].s = cb.s;
-			sp->s_level[color] = 1;
-		}
+	if (quick_check(color, cbp))
 		return;
-	}
 
 	/*
 	 * Update the minimum combo value for each spot in the frame
@@ -335,7 +343,6 @@ scanframes(int color)
 	 * Try to make new 3rd level combos, 4th level, etc.
 	 * Limit the search depth early in the game.
 	 */
-	/* LINTED 117: bitwise '>>' on signed value possibly nonportable */
 	for (unsigned int level = 2;
 	 level <= 1 + game.nmoves / 2 && combolen > n; level++) {
 		if (level >= 9)



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 12:20:07 UTC 2022

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

Log Message:
gomoku: extract quick_check from scanframes

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 11:36:12 UTC 2022

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

Log Message:
gomoku: use proper types when indexing 'board' and 'frames'

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.36 -r1.37 src/games/gomoku/makemove.c
cvs rdiff -u -r1.53 -r1.54 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 11:36:12 UTC 2022

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

Log Message:
gomoku: use proper types when indexing 'board' and 'frames'

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.36 -r1.37 src/games/gomoku/makemove.c
cvs rdiff -u -r1.53 -r1.54 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/bdinit.c
diff -u src/games/gomoku/bdinit.c:1.30 src/games/gomoku/bdinit.c:1.31
--- src/games/gomoku/bdinit.c:1.30	Sun May 29 10:37:21 2022
+++ src/games/gomoku/bdinit.c	Sun May 29 11:36:12 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdinit.c,v 1.30 2022/05/29 10:37:21 rillig Exp $	*/
+/*	$NetBSD: bdinit.c,v 1.31 2022/05/29 11:36:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	from: @(#)bdinit.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdinit.c,v 1.30 2022/05/29 10:37:21 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.31 2022/05/29 11:36:12 rillig Exp $");
 
 #include 
 #include "gomoku.h"
@@ -118,7 +118,7 @@ init_spot_frame(struct spotstr *sp, fram
 
 		struct combostr *cbp = [fi];
 		cbp->c_combo.s = sp->s_fval[BLACK][r].s;
-		cbp->c_vertex = (u_short)(sp - board);
+		cbp->c_vertex = (spot_index)(sp - board);
 		cbp->c_nframes = 1;
 		cbp->c_dir = r;
 	}

Index: src/games/gomoku/makemove.c
diff -u src/games/gomoku/makemove.c:1.36 src/games/gomoku/makemove.c:1.37
--- src/games/gomoku/makemove.c:1.36	Sun May 29 10:37:21 2022
+++ src/games/gomoku/makemove.c	Sun May 29 11:36:12 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: makemove.c,v 1.36 2022/05/29 10:37:21 rillig Exp $	*/
+/*	$NetBSD: makemove.c,v 1.37 2022/05/29 11:36:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)makemove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: makemove.c,v 1.36 2022/05/29 10:37:21 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.37 2022/05/29 11:36:12 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -155,7 +155,7 @@ makemove(int us, spot_index mv)
 
 		/* check for game over */
 		if (n == 5) {
-		game.winning_spot = (int)(fsp - board);
+		game.winning_spot = (spot_index)(fsp - board);
 		game.winning_dir = r;
 		return WIN;
 		}

Index: src/games/gomoku/pickmove.c
diff -u src/games/gomoku/pickmove.c:1.53 src/games/gomoku/pickmove.c:1.54
--- src/games/gomoku/pickmove.c:1.53	Sun May 29 10:37:21 2022
+++ src/games/gomoku/pickmove.c	Sun May 29 11:36:12 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pickmove.c,v 1.53 2022/05/29 10:37:21 rillig Exp $	*/
+/*	$NetBSD: pickmove.c,v 1.54 2022/05/29 11:36:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)pickmove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: pickmove.c,v 1.53 2022/05/29 10:37:21 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.54 2022/05/29 11:36:12 rillig Exp $");
 
 #include 
 #include 
@@ -308,7 +308,8 @@ scanframes(int color)
 			if (cp->s == 0x101) {
 sp->s_nforce[color]++;
 if (color != nextcolor) {
-	n = (int)(sp - board);
+	/* XXX: suspicious use of 'n' */
+	n = (spot_index)(sp - board);
 	BIT_SET(tmpmap, n);
 }
 			}
@@ -493,7 +494,7 @@ makecombo2(struct combostr *ocbp, struct
 		ncbp->c_linkv[1].s = fcb.s;
 		ncbp->c_voff[0] = off;
 		ncbp->c_voff[1] = f;
-		ncbp->c_vertex = (u_short)(osp - board);
+		ncbp->c_vertex = (spot_index)(osp - board);
 		ncbp->c_nframes = 2;
 		ncbp->c_dir = 0;
 		ncbp->c_frameindex = 0;
@@ -681,7 +682,7 @@ makecombo(struct combostr *ocbp, struct 
 #ifdef DEBUG
 		if (sp->s_occ != EMPTY) {
 		debuglog("loop: %c %s", "BW"[curcolor],
-			stoc((int)(sp - board)));
+			stoc((spot_index)(sp - board)));
 		whatsup(0);
 		}
 #endif
@@ -732,7 +733,7 @@ makecombo(struct combostr *ocbp, struct 
 	ncbp->c_link[1] = ocbp;
 	ncbp->c_linkv[1].s = ocb.s;
 	ncbp->c_voff[1] = off;
-	ncbp->c_vertex = (u_short)(osp - board);
+	ncbp->c_vertex = (spot_index)(osp - board);
 	ncbp->c_nframes = cbp->c_nframes + 1;
 	ncbp->c_flags = ocb.cv_win != 0 ? C_OPEN_1 : 0;
 	ncbp->c_frameindex = ep->e_frameindex;
@@ -931,7 +932,7 @@ makeempty(struct combostr *ocbp)
 			nep->e_fval.s = ep->e_fval.s;
 			if (debug > 2) {
 debuglog("e %s o%d i%d c%d m%x %x",
-stoc((int)(sp - board)),
+stoc((spot_index)(sp - board)),
 nep->e_off,
 nep->e_frameindex,
 nep->e_framecnt,
@@ -1087,7 +1088,7 @@ checkframes(struct combostr *cbp, struct
 	fcnt = cb.cv_force - 2;
 	verts = 0;
 	myindex = cbp->c_nframes;
-	n = (int)(fcbp - frames) * FAREA;
+	n = (frame_index)(fcbp - frames) * FAREA;
 	str = [n];
 	spot_index *ip = [n];
 	/*
@@ -1248,7 +1249,7 @@ sortcombo(struct combostr **scbpp, struc
 inserted:
 
 	/* now check to see if this list of frames has already been seen */
-	cbp = 

CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 10:37:21 UTC 2022

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

Log Message:
gomoku: turn spotstr.s_frame into a frame index

Most calculations are done on the frame index, not the pointer. This
avoids dealing with ptrdiff_t conversion to int.

Changing the type of s_frame changes the size of struct spotstr, it is
now 56 bytes on LP64 and 48 bytes on ILP32, neither of which is a power
of two. Remove the dummy padding since compilers no longer generate
division instructions for divisions by small integer constants, so that
optimization is no longer necessary.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.48 -r1.49 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.68 -r1.69 src/games/gomoku/main.c
cvs rdiff -u -r1.35 -r1.36 src/games/gomoku/makemove.c
cvs rdiff -u -r1.52 -r1.53 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/bdinit.c
diff -u src/games/gomoku/bdinit.c:1.29 src/games/gomoku/bdinit.c:1.30
--- src/games/gomoku/bdinit.c:1.29	Sun May 29 00:38:26 2022
+++ src/games/gomoku/bdinit.c	Sun May 29 10:37:21 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdinit.c,v 1.29 2022/05/29 00:38:26 rillig Exp $	*/
+/*	$NetBSD: bdinit.c,v 1.30 2022/05/29 10:37:21 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	from: @(#)bdinit.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdinit.c,v 1.29 2022/05/29 00:38:26 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.30 2022/05/29 10:37:21 rillig Exp $");
 
 #include 
 #include "gomoku.h"
@@ -106,19 +106,21 @@ init_spot_flags_and_fval(struct spotstr 
 
 /* Allocate one of the pre-allocated frames for each non-blocked frame. */
 static void
-init_spot_frame(struct spotstr *sp, struct combostr **cbpp)
+init_spot_frame(struct spotstr *sp, frame_index *fip)
 {
 
 	for (int r = 4; --r >= 0; ) {
 		if ((sp->s_flags & (BFLAG << r)) != 0)
 			continue;
 
-		struct combostr *cbp = (*cbpp)++;
+		frame_index fi = (*fip)++;
+		sp->s_frame[r] = fi;
+
+		struct combostr *cbp = [fi];
 		cbp->c_combo.s = sp->s_fval[BLACK][r].s;
 		cbp->c_vertex = (u_short)(sp - board);
 		cbp->c_nframes = 1;
 		cbp->c_dir = r;
-		sp->s_frame[r] = cbp;
 	}
 }
 
@@ -136,14 +138,14 @@ init_board(void)
 	}
 
 	/* fill the playing area of the board with EMPTY spots */
-	struct combostr *cbp = frames;
+	frame_index fi = 0;
 	memset(frames, 0, sizeof(frames));
 	for (int row = 1; row <= BSZ; row++, sp++) {
 		for (int col = 1; col <= BSZ; col++, sp++) {
 			sp->s_occ = EMPTY;
 			sp->s_wval = 0;
 			init_spot_flags_and_fval(sp, col, row);
-			init_spot_frame(sp, );
+			init_spot_frame(sp, );
 		}
 		sp->s_occ = BORDER;	/* combined left and right border */
 		sp->s_flags = BFLAGALL;
@@ -247,7 +249,7 @@ init_overlap_frame(int fia, int ra, int 
 			if ((spb0->s_flags & BFLAG << rb) != 0)
 continue;
 
-			int fib = (int)(spb0->s_frame[rb] - frames);
+			frame_index fib = spb0->s_frame[rb];
 			intersect[fia * FAREA + fib] = s;
 			u_char *op = [fia * FAREA + fib];
 			*op = adjust_overlap(*op, ra, sia, rb, sib, mask);

Index: src/games/gomoku/gomoku.h
diff -u src/games/gomoku/gomoku.h:1.48 src/games/gomoku/gomoku.h:1.49
--- src/games/gomoku/gomoku.h:1.48	Sun May 29 00:38:26 2022
+++ src/games/gomoku/gomoku.h	Sun May 29 10:37:21 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: gomoku.h,v 1.48 2022/05/29 00:38:26 rillig Exp $	*/
+/*	$NetBSD: gomoku.h,v 1.49 2022/05/29 10:37:21 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -154,7 +154,7 @@ struct combostr {
 	union comboval	c_linkv[2];	/* C: combo value for link[0, 1] */
 	union comboval	c_combo;	/* F: initial combo value (read-only),
 	 * C: combo value for this level */
-	u_short		c_vertex;	/* F: frame head,
+	spot_index	c_vertex;	/* F: frame head,
 	 * C: intersection */
 	u_char		c_nframes;	/* F: 1,
 	 * C: number of frames in the combo */
@@ -187,6 +187,9 @@ struct	elist {
 	union comboval	e_fval;		/* frame combo value */
 };
 
+/* The index of a frame in the global 'frames'. */
+typedef unsigned short frame_index;
+
 /*
  * One spot structure for each location on the board.
  * A frame consists of the combination for the current spot plus the five spots
@@ -196,14 +199,13 @@ struct	spotstr {
 	short		s_occ;		/* color of occupant */
 	short		s_wval;		/* weighted value */
 	int		s_flags;	/* flags for graph walks */
-	struct combostr	*s_frame[4];	/* level 1 combo for frame[dir] */
+	frame_index	s_frame[4];	/* level 1 combo for [dir] */
 	union comboval	s_fval[2][4];	/* combo value for [color][frame] */
 	union comboval	s_combo[2];	/* minimum combo value for BLK & WHT */
 	u_char		s_level[2];	/* number of frames in the min combo */
 	u_char		s_nforce[2];	/* number of <1,x> combos */
 	struct elist	*s_empty;	/* level n combo 

CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 10:37:21 UTC 2022

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

Log Message:
gomoku: turn spotstr.s_frame into a frame index

Most calculations are done on the frame index, not the pointer. This
avoids dealing with ptrdiff_t conversion to int.

Changing the type of s_frame changes the size of struct spotstr, it is
now 56 bytes on LP64 and 48 bytes on ILP32, neither of which is a power
of two. Remove the dummy padding since compilers no longer generate
division instructions for divisions by small integer constants, so that
optimization is no longer necessary.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.48 -r1.49 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.68 -r1.69 src/games/gomoku/main.c
cvs rdiff -u -r1.35 -r1.36 src/games/gomoku/makemove.c
cvs rdiff -u -r1.52 -r1.53 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 10:06:43 UTC 2022

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

Log Message:
gomoku: document where to fix the unnecessarily long thinking time


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 10:06:43 UTC 2022

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

Log Message:
gomoku: document where to fix the unnecessarily long thinking time


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 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/pickmove.c
diff -u src/games/gomoku/pickmove.c:1.51 src/games/gomoku/pickmove.c:1.52
--- src/games/gomoku/pickmove.c:1.51	Sun May 29 01:17:55 2022
+++ src/games/gomoku/pickmove.c	Sun May 29 10:06:43 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pickmove.c,v 1.51 2022/05/29 01:17:55 rillig Exp $	*/
+/*	$NetBSD: pickmove.c,v 1.52 2022/05/29 10:06:43 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)pickmove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: pickmove.c,v 1.51 2022/05/29 01:17:55 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.52 2022/05/29 10:06:43 rillig Exp $");
 
 #include 
 #include 
@@ -107,6 +107,12 @@ pickmove(int us)
 
 	/* compute new values */
 	nextcolor = us;
+	/*
+	 * TODO: Scanning for both frames misses that after loading the game
+	 *  K10 J9 M10 J10 O10 J11 Q10 J8 and playing K9, there are 2
+	 *  immediate winning moves J12 and J7. Finding the winning move
+	 *  takes too long.
+	 */
 	scanframes(BLACK);
 	scanframes(WHITE);
 
@@ -242,11 +248,6 @@ scanframes(int color)
 		return;
 
 	/* quick check for four in a row */
-	/*
-	 * TODO: This quick check misses that after loading the game K10 J9
-	 *  M10 J10 O10 J11 Q10 J8 and playing K9, there are 2 immediate
-	 *  winning moves J12 and J7.
-	 */
 	sp = [cbp->c_vertex];
 	cb.s = sp->s_fval[color][cbp->c_dir].s;
 	if (cb.s < 0x101) {



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 01:34:49 UTC 2022

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

Log Message:
gomoku: migrate 'makemove' to using spot_index instead of pointer

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/games/gomoku/makemove.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/makemove.c
diff -u src/games/gomoku/makemove.c:1.34 src/games/gomoku/makemove.c:1.35
--- src/games/gomoku/makemove.c:1.34	Sun May 29 00:38:26 2022
+++ src/games/gomoku/makemove.c	Sun May 29 01:34:49 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: makemove.c,v 1.34 2022/05/29 00:38:26 rillig Exp $	*/
+/*	$NetBSD: makemove.c,v 1.35 2022/05/29 01:34:49 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)makemove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: makemove.c,v 1.34 2022/05/29 00:38:26 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.35 2022/05/29 01:34:49 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -48,7 +48,7 @@ const int dd[4] = {
 
 static const int weight[5] = { 0, 1, 7, 22, 100 };
 
-static void update_overlap(struct spotstr *);
+static void update_overlap(spot_index);
 
 static bool
 is_tie(void)
@@ -223,7 +223,7 @@ makemove(int us, spot_index mv)
 	;
 	}
 
-	update_overlap([mv]);
+	update_overlap(mv);
 
 	if (is_tie())
 		return TIE;
@@ -232,8 +232,7 @@ makemove(int us, spot_index mv)
 }
 
 static void
-update_overlap_same_direction(const struct spotstr *sp1,
-			  const struct spotstr *sp2,
+update_overlap_same_direction(spot_index s1, spot_index s2,
 			  int a, int d, int i_minus_f, int r)
 {
 	/*
@@ -241,36 +240,36 @@ update_overlap_same_direction(const stru
 	 * still an overlap.
 	 */
 	int n = 0;
-	const struct spotstr *sp = sp1;
-	const struct spotstr *esp = NULL;
-	for (int b = i_minus_f; b < 5; b++, sp += d) {
-		if (sp->s_occ == EMPTY) {
-			esp = sp;	/* save the intersection point */
+	spot_index s = s1;
+	spot_index es = 0;
+	for (int b = i_minus_f; b < 5; b++, s += d) {
+		if (board[s].s_occ == EMPTY) {
+			es = s;	/* save the intersection point */
 			n++;
 		}
 	}
 
-	int b = (int)(sp2->s_frame[r] - frames);
+	int b = (int)(board[s2].s_frame[r] - frames);
 	if (n == 0) {
-		if (sp->s_occ == EMPTY) {
+		if (board[s].s_occ == EMPTY) {
 			overlap[a * FAREA + b] &= 0xA;
 			overlap[b * FAREA + a] &= 0xC;
-			intersect[a * FAREA + b] = (short)(sp - board);
-			intersect[b * FAREA + a] = (short)(sp - board);
+			intersect[a * FAREA + b] = s;
+			intersect[b * FAREA + a] = s;
 		} else {
 			overlap[a * FAREA + b] = 0;
 			overlap[b * FAREA + a] = 0;
 		}
 	} else if (n == 1) {
-		if (sp->s_occ == EMPTY) {
+		if (board[s].s_occ == EMPTY) {
 			overlap[a * FAREA + b] &= 0xAF;
 			overlap[b * FAREA + a] &= 0xCF;
 		} else {
 			overlap[a * FAREA + b] &= 0xF;
 			overlap[b * FAREA + a] &= 0xF;
 		}
-		intersect[a * FAREA + b] = (short)(esp - board);
-		intersect[b * FAREA + a] = (short)(esp - board);
+		intersect[a * FAREA + b] = es;
+		intersect[b * FAREA + a] = es;
 	}
 	/* else no change, still multiple overlap */
 }
@@ -282,12 +281,12 @@ update_overlap_same_direction(const stru
  * frames as non-overlapping with frame 'a'.
  */
 static void
-update_overlap_different_direction(const struct spotstr *osp, int a, int rb)
+update_overlap_different_direction(spot_index os, int a, int rb)
 {
 
 	int db = dd[rb];
 	for (int i = 0; i < 6; i++) {
-		const struct spotstr *sp = osp - db * i;
+		const struct spotstr *sp = [os - db * i];
 		if (sp->s_occ == BORDER)
 			break;
 		if ((sp->s_flags & BFLAG << rb) != 0)
@@ -303,18 +302,18 @@ update_overlap_different_direction(const
  * fix up the overlap array according to the changed 'osp'.
  */
 static void
-update_overlap(struct spotstr *osp)
+update_overlap(spot_index os)
 {
 
 	for (int r = 4; --r >= 0; ) {		/* for each direction */
 	int d = dd[r];
-	struct spotstr *sp1 = osp;
+	spot_index s1 = os;
 
 	/* for each frame 'a' that contains the spot 'osp' */
-	for (int f = 0; f < 6; f++, sp1 -= d) {
-		if (sp1->s_occ == BORDER)
+	for (int f = 0; f < 6; f++, s1 -= d) {
+		if (board[s1].s_occ == BORDER)
 		break;
-		if ((sp1->s_flags & BFLAG << r) != 0)
+		if ((board[s1].s_flags & BFLAG << r) != 0)
 		continue;
 
 		/*
@@ -324,21 +323,21 @@ update_overlap(struct spotstr *osp)
 		 * do the rows 0 <= r1 <= r. The r1 == r case is special
 		 * since the two frames can overlap at more than one point.
 		 */
-		int a = (int)(sp1->s_frame[r] - frames);
+		int a = (int)(board[s1].s_frame[r] - frames);
 
-		struct spotstr *sp2 = sp1 - d;
-		for (int i = f + 1; i < 6; i++, sp2 -= d) {
-		if (sp2->s_occ == BORDER)
+		spot_index s2 = s1 - d;
+		for (int i = f + 1; i < 6; i++, s2 -= d) {
+		if (board[s2].s_occ == BORDER)
 			break;
-		if ((sp2->s_flags & BFLAG << r) != 0)
+		if 

CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 01:34:49 UTC 2022

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

Log Message:
gomoku: migrate 'makemove' to using spot_index instead of pointer

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/games/gomoku/makemove.c

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



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 01:17:55 UTC 2022

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

Log Message:
gomoku: migrate pickmove to use spot_index instead of pointers

Using spot_index instead of pointers leads to simpler code since there
is no need to deal with conversion from ptrdiff_t to spot_index.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 01:17:55 UTC 2022

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

Log Message:
gomoku: migrate pickmove to use spot_index instead of pointers

Using spot_index instead of pointers leads to simpler code since there
is no need to deal with conversion from ptrdiff_t to spot_index.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 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/pickmove.c
diff -u src/games/gomoku/pickmove.c:1.50 src/games/gomoku/pickmove.c:1.51
--- src/games/gomoku/pickmove.c:1.50	Sun May 29 00:38:26 2022
+++ src/games/gomoku/pickmove.c	Sun May 29 01:17:55 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pickmove.c,v 1.50 2022/05/29 00:38:26 rillig Exp $	*/
+/*	$NetBSD: pickmove.c,v 1.51 2022/05/29 01:17:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)pickmove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: pickmove.c,v 1.50 2022/05/29 00:38:26 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.51 2022/05/29 01:17:55 rillig Exp $");
 
 #include 
 #include 
@@ -68,7 +68,7 @@ static int forcemap[MAPSZ];		/* map for 
 static int tmpmap[MAPSZ];		/* map for blocking <1,x> combos */
 static int nforce;			/* count of opponent <1,x> combos */
 
-static bool better(const struct spotstr *, const struct spotstr *, int);
+static bool better(spot_index, spot_index, int);
 static void scanframes(int);
 static void makecombo2(struct combostr *, struct spotstr *, int, int);
 static void addframes(unsigned int);
@@ -111,17 +111,17 @@ pickmove(int us)
 	scanframes(WHITE);
 
 	/* find the spot with the highest value */
-	unsigned pos = PT(BSZ, BSZ);
-	struct spotstr *sp1 = [pos];
-	struct spotstr *sp2 = sp1;
-	for ( ; pos-- > PT(1, 1); ) {
-		struct spotstr *sp = [pos];
+	spot_index s = PT(BSZ, BSZ);
+	spot_index s1 = s;
+	spot_index s2 = s;
+	for ( ; s-- > PT(1, 1); ) {
+		struct spotstr *sp = [s];
 		if (sp->s_occ != EMPTY)
 			continue;
 		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)),
+			stoc(s),
 			sp->s_combo[BLACK].s, sp->s_level[BLACK],
 			sp->s_nforce[BLACK],
 			sp->s_combo[WHITE].s, sp->s_level[WHITE],
@@ -129,22 +129,23 @@ pickmove(int us)
 			sp->s_wval);
 		}
 		/* pick the best black move */
-		if (better(sp, sp1, BLACK))
-			sp1 = sp;
+		if (better(s, s1, BLACK))
+			s1 = s;
 		/* pick the best white move */
-		if (better(sp, sp2, WHITE))
-			sp2 = sp;
+		if (better(s, s2, WHITE))
+			s2 = s;
 	}
 
 	if (debug != 0) {
+		const struct spotstr *sp1 = [s1], *sp2 = [s2];
 		debuglog("B %s %x/%d %d %x/%d %d %d",
-		stoc((int)(sp1 - board)),
+		stoc(s1),
 		sp1->s_combo[BLACK].s, sp1->s_level[BLACK],
 		sp1->s_nforce[BLACK],
 		sp1->s_combo[WHITE].s, sp1->s_level[WHITE],
 		sp1->s_nforce[WHITE], sp1->s_wval);
 		debuglog("W %s %x/%d %d %x/%d %d %d",
-		stoc((int)(sp2 - board)),
+		stoc(s2),
 		sp2->s_combo[WHITE].s, sp2->s_level[WHITE],
 		sp2->s_nforce[WHITE],
 		sp2->s_combo[BLACK].s, sp2->s_level[BLACK],
@@ -153,24 +154,24 @@ pickmove(int us)
 		 * Check for more than one force that can't
 		 * all be blocked with one move.
 		 */
-		struct spotstr *sp = (us == BLACK) ? sp2 : sp1;
-		int m = (int)(sp - board);
-		if (sp->s_combo[us != BLACK ? BLACK : WHITE].cv_force == 1 &&
+		spot_index m = us == BLACK ? s2 : s1;
+		int them = us != BLACK ? BLACK : WHITE;
+		if (board[m].s_combo[them].cv_force == 1 &&
 		!BIT_TEST(forcemap, m))
 			debuglog("*** Can't be blocked");
 	}
 
 	union comboval *Ocp, *Tcp;
 	if (us == BLACK) {
-		Ocp = >s_combo[BLACK];
-		Tcp = >s_combo[WHITE];
+		Ocp = [s1].s_combo[BLACK];
+		Tcp = [s2].s_combo[WHITE];
 	} else {
-		Tcp = >s_combo[BLACK];
-		Ocp = >s_combo[WHITE];
+		Tcp = [s1].s_combo[BLACK];
+		Ocp = [s2].s_combo[WHITE];
 
-		struct spotstr *sp = sp1;
-		sp1 = sp2;
-		sp2 = sp;
+		spot_index tmp = s1;
+		s1 = s2;
+		s2 = tmp;
 	}
 	/*
 	 * Block their combo only if we have to (i.e., if they are one move
@@ -179,16 +180,17 @@ pickmove(int us)
 	 */
 	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);
+		return s2;
+	return s1;
 }
 
 /*
  * Return true if spot 'sp' is better than spot 'sp1' for color 'us'.
  */
 static bool
-better(const struct spotstr *sp, const struct spotstr *sp1, int us)
+better(spot_index s, spot_index s1, int us)
 {
+	const struct spotstr *sp = [s], *sp1 = [s1];
 
 	if (/*  */ sp->s_combo[us].s != sp1->s_combo[us].s)
 		return sp->s_combo[us].s < sp1->s_combo[us].s;
@@ -198,8 +200,6 @@ better(const struct spotstr *sp, const s
 		return sp->s_nforce[us] > 

CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 00:38:26 UTC 2022

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

Log Message:
gomoku: migrate spot_index from int to unsigned short

This matches the type of 'intersect'.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.47 -r1.48 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.67 -r1.68 src/games/gomoku/main.c
cvs rdiff -u -r1.33 -r1.34 src/games/gomoku/makemove.c
cvs rdiff -u -r1.49 -r1.50 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/bdinit.c
diff -u src/games/gomoku/bdinit.c:1.28 src/games/gomoku/bdinit.c:1.29
--- src/games/gomoku/bdinit.c:1.28	Sun May 29 00:12:11 2022
+++ src/games/gomoku/bdinit.c	Sun May 29 00:38:26 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdinit.c,v 1.28 2022/05/29 00:12:11 rillig Exp $	*/
+/*	$NetBSD: bdinit.c,v 1.29 2022/05/29 00:38:26 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	from: @(#)bdinit.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdinit.c,v 1.28 2022/05/29 00:12:11 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.29 2022/05/29 00:38:26 rillig Exp $");
 
 #include 
 #include "gomoku.h"
@@ -248,7 +248,7 @@ init_overlap_frame(int fia, int ra, int 
 continue;
 
 			int fib = (int)(spb0->s_frame[rb] - frames);
-			intersect[fia * FAREA + fib] = (short)s;
+			intersect[fia * FAREA + fib] = s;
 			u_char *op = [fia * FAREA + fib];
 			*op = adjust_overlap(*op, ra, sia, rb, sib, mask);
 		}

Index: src/games/gomoku/gomoku.h
diff -u src/games/gomoku/gomoku.h:1.47 src/games/gomoku/gomoku.h:1.48
--- src/games/gomoku/gomoku.h:1.47	Sun May 29 00:12:11 2022
+++ src/games/gomoku/gomoku.h	Sun May 29 00:38:26 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: gomoku.h,v 1.47 2022/05/29 00:12:11 rillig Exp $	*/
+/*	$NetBSD: gomoku.h,v 1.48 2022/05/29 00:38:26 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -59,8 +59,9 @@
 #define EMPTY	2
 #define BORDER	3
 
+/* A spot on the board, or in some cases one of the below special values. */
+typedef unsigned short spot_index;
 /* return values for makemove, readinput */
-typedef int spot_index;
 #define MOVEOK	0
 #define RESIGN	1
 #define ILLEGAL	2
@@ -232,7 +233,7 @@ extern	struct	spotstr	board[BAREA];		/* 
 extern	struct	combostr frames[FAREA];		/* storage for single frames */
 extern	struct	combostr *sortframes[2];	/* sorted, non-empty frames */
 extern	u_char	overlap[FAREA * FAREA];
-extern	short	intersect[FAREA * FAREA];	/* frame [a][b] intersection */
+extern	spot_index intersect[FAREA * FAREA];	/* frame [a][b] intersection */
 extern	struct game	game;
 extern	int	debug;
 
@@ -256,7 +257,7 @@ void	debuglog(const char *, ...) __print
 void	whatsup(int);
 const char *stoc(spot_index);
 spot_index ctos(const char *);
-int	makemove(int, int);
+int	makemove(int, spot_index);
 void	clearcombo(struct combostr *, int);
 void	markcombo(struct combostr *);
 int	pickmove(int);

Index: src/games/gomoku/main.c
diff -u src/games/gomoku/main.c:1.67 src/games/gomoku/main.c:1.68
--- src/games/gomoku/main.c:1.67	Sun May 29 00:12:11 2022
+++ src/games/gomoku/main.c	Sun May 29 00:38:26 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.67 2022/05/29 00:12:11 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.68 2022/05/29 00:38:26 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.67 2022/05/29 00:12:11 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.68 2022/05/29 00:38:26 rillig Exp $");
 
 #include 
 #include 
@@ -78,7 +78,7 @@ struct	combostr frames[FAREA];		/* stora
 struct	combostr *sortframes[2];	/* sorted list of non-empty frames */
 u_char	overlap[FAREA * FAREA];		/* non-zero if frame [a][b] overlap;
 	 * see init_overlap */
-short	intersect[FAREA * FAREA];	/* frame [a][b] intersection */
+spot_index intersect[FAREA * FAREA];	/* frame [a][b] intersection */
 struct game game;
 const char *plyr[2] = { "???", "???" };	/* who's who */
 

Index: src/games/gomoku/makemove.c
diff -u src/games/gomoku/makemove.c:1.33 src/games/gomoku/makemove.c:1.34
--- src/games/gomoku/makemove.c:1.33	Sat May 28 08:32:55 2022
+++ src/games/gomoku/makemove.c	Sun May 29 00:38:26 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: makemove.c,v 1.33 2022/05/28 08:32:55 rillig Exp $	*/
+/*	$NetBSD: makemove.c,v 1.34 2022/05/29 00:38:26 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)makemove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: makemove.c,v 1.33 2022/05/28 08:32:55 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.34 2022/05/29 00:38:26 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -97,7 +97,7 @@ old_weight_value(const struct spotstr *s
  *	TIE	

CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 00:38:26 UTC 2022

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

Log Message:
gomoku: migrate spot_index from int to unsigned short

This matches the type of 'intersect'.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.47 -r1.48 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.67 -r1.68 src/games/gomoku/main.c
cvs rdiff -u -r1.33 -r1.34 src/games/gomoku/makemove.c
cvs rdiff -u -r1.49 -r1.50 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 00:12:11 UTC 2022

Modified Files:
src/games/gomoku: bdinit.c bdisp.c gomoku.h main.c pickmove.c stoc.c

Log Message:
gomoku: use consistent variable names

Previously, the name 's' was used for the index of a spot on the board,
as well as for the value of a combo, and for a few other purposes. Use
different names and mark the spot indexes using a custom type.

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.50 -r1.51 src/games/gomoku/bdisp.c
cvs rdiff -u -r1.46 -r1.47 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.66 -r1.67 src/games/gomoku/main.c
cvs rdiff -u -r1.48 -r1.49 src/games/gomoku/pickmove.c
cvs rdiff -u -r1.20 -r1.21 src/games/gomoku/stoc.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/bdinit.c
diff -u src/games/gomoku/bdinit.c:1.27 src/games/gomoku/bdinit.c:1.28
--- src/games/gomoku/bdinit.c:1.27	Sat May 28 19:47:24 2022
+++ src/games/gomoku/bdinit.c	Sun May 29 00:12:11 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdinit.c,v 1.27 2022/05/28 19:47:24 rillig Exp $	*/
+/*	$NetBSD: bdinit.c,v 1.28 2022/05/29 00:12:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	from: @(#)bdinit.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdinit.c,v 1.27 2022/05/28 19:47:24 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.28 2022/05/29 00:12:11 rillig Exp $");
 
 #include 
 #include "gomoku.h"
@@ -233,7 +233,7 @@ adjust_overlap(u_char ov, int ra, int si
  * each frame B that overlaps frame A in that spot.
  */
 static void
-init_overlap_frame(int fia, int ra, int sia, int s, int mask)
+init_overlap_frame(int fia, int ra, int sia, spot_index s, int mask)
 {
 
 	for (int rb = 4; --rb >= 0;) {
@@ -264,7 +264,7 @@ init_overlap(void)
 
 	for (int fia = FAREA; fia-- > 0;) {
 		const struct combostr *fa = [fia];
-		int s = fa->c_vertex;
+		spot_index s = fa->c_vertex;
 		u_char ra = fa->c_dir;
 		int da = dd[ra];
 

Index: src/games/gomoku/bdisp.c
diff -u src/games/gomoku/bdisp.c:1.50 src/games/gomoku/bdisp.c:1.51
--- src/games/gomoku/bdisp.c:1.50	Sat May 28 20:54:31 2022
+++ src/games/gomoku/bdisp.c	Sun May 29 00:12:11 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdisp.c,v 1.50 2022/05/28 20:54:31 rillig Exp $	*/
+/*	$NetBSD: bdisp.c,v 1.51 2022/05/29 00:12:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)bdisp.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdisp.c,v 1.50 2022/05/28 20:54:31 rillig Exp $");
+__RCSID("$NetBSD: bdisp.c,v 1.51 2022/05/29 00:12:11 rillig Exp $");
 
 #include 
 #include 
@@ -149,7 +149,7 @@ bdwho(void)
 }
 
 static bool
-should_highlight(int s)
+should_highlight(spot_index s)
 {
 
 	if (game.nmoves > 0 && game.moves[game.nmoves - 1] == s)

Index: src/games/gomoku/gomoku.h
diff -u src/games/gomoku/gomoku.h:1.46 src/games/gomoku/gomoku.h:1.47
--- src/games/gomoku/gomoku.h:1.46	Sat May 28 23:05:45 2022
+++ src/games/gomoku/gomoku.h	Sun May 29 00:12:11 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: gomoku.h,v 1.46 2022/05/28 23:05:45 rillig Exp $	*/
+/*	$NetBSD: gomoku.h,v 1.47 2022/05/29 00:12:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -60,6 +60,7 @@
 #define BORDER	3
 
 /* return values for makemove, readinput */
+typedef int spot_index;
 #define MOVEOK	0
 #define RESIGN	1
 #define ILLEGAL	2
@@ -217,9 +218,9 @@ struct	spotstr {
 #define BFLAGALL	0x0F	/* all frames dead */
 
 struct game {
-	int moves[BSZ * BSZ];		/* log of all played moves */
+	spot_index moves[BSZ * BSZ];	/* log of all played moves */
 	unsigned int nmoves;		/* number of played moves */
-	int winning_spot;
+	spot_index winning_spot;
 	int winning_dir;
 };
 
@@ -253,8 +254,8 @@ void	bdwho(void);
 void	panic(const char *, ...) __printflike(1, 2) __dead;
 void	debuglog(const char *, ...) __printflike(1, 2);
 void	whatsup(int);
-const char   *stoc(int);
-int	ctos(const char *);
+const char *stoc(spot_index);
+spot_index ctos(const char *);
 int	makemove(int, int);
 void	clearcombo(struct combostr *, int);
 void	markcombo(struct combostr *);

Index: src/games/gomoku/main.c
diff -u src/games/gomoku/main.c:1.66 src/games/gomoku/main.c:1.67
--- src/games/gomoku/main.c:1.66	Sat May 28 23:05:45 2022
+++ src/games/gomoku/main.c	Sun May 29 00:12:11 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.66 2022/05/28 23:05:45 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.67 2022/05/29 00:12:11 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.66 2022/05/28 23:05:45 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.67 2022/05/29 00:12:11 rillig Exp $");
 
 #include 
 #include 
@@ -222,13 +222,13 @@ read_color(void)
 	/* NOTREACHED */
 }
 
-static int
+static 

CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 29 00:12:11 UTC 2022

Modified Files:
src/games/gomoku: bdinit.c bdisp.c gomoku.h main.c pickmove.c stoc.c

Log Message:
gomoku: use consistent variable names

Previously, the name 's' was used for the index of a spot on the board,
as well as for the value of a combo, and for a few other purposes. Use
different names and mark the spot indexes using a custom type.

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.50 -r1.51 src/games/gomoku/bdisp.c
cvs rdiff -u -r1.46 -r1.47 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.66 -r1.67 src/games/gomoku/main.c
cvs rdiff -u -r1.48 -r1.49 src/games/gomoku/pickmove.c
cvs rdiff -u -r1.20 -r1.21 src/games/gomoku/stoc.c

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



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 23:05:45 UTC 2022

Modified Files:
src/games/gomoku: gomoku.h main.c

Log Message:
gomoku: use custom magic value for end of file input

This allows the type for a spot index to be changed to an unsigned type.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.65 -r1.66 src/games/gomoku/main.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.45 src/games/gomoku/gomoku.h:1.46
--- src/games/gomoku/gomoku.h:1.45	Sat May 28 17:51:27 2022
+++ src/games/gomoku/gomoku.h	Sat May 28 23:05:45 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: gomoku.h,v 1.45 2022/05/28 17:51:27 rillig Exp $	*/
+/*	$NetBSD: gomoku.h,v 1.46 2022/05/28 23:05:45 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -66,6 +66,7 @@
 #define WIN	3
 #define TIE	4
 #define SAVE	5
+#define END_OF_INPUT 6
 #define PT(x, y)	((x) + (BSZ + 1) * (y))
 
 /*

Index: src/games/gomoku/main.c
diff -u src/games/gomoku/main.c:1.65 src/games/gomoku/main.c:1.66
--- src/games/gomoku/main.c:1.65	Sat May 28 21:31:41 2022
+++ src/games/gomoku/main.c	Sat May 28 23:05:45 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.65 2022/05/28 21:31:41 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.66 2022/05/28 23:05:45 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.65 2022/05/28 21:31:41 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.66 2022/05/28 23:05:45 rillig Exp $");
 
 #include 
 #include 
@@ -290,7 +290,7 @@ again:
 	switch (input[color]) {
 	case INPUTF:
 		curmove = readinput(inputfp);
-		if (curmove != EOF)
+		if (curmove != END_OF_INPUT)
 			break;
 		set_input_sources(input, color);
 		plyr[BLACK] = input[BLACK] == USER ? user : prog;
@@ -409,7 +409,7 @@ readinput(FILE *fp)
 	while ((c = getc(fp)) != EOF && c != '\n' && pos < sizeof(buf) - 1)
 		buf[pos++] = c;
 	buf[pos] = '\0';
-	return c == EOF ? EOF : ctos(buf);
+	return c == EOF ? END_OF_INPUT : ctos(buf);
 }
 
 #ifdef DEBUG



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 23:05:45 UTC 2022

Modified Files:
src/games/gomoku: gomoku.h main.c

Log Message:
gomoku: use custom magic value for end of file input

This allows the type for a spot index to be changed to an unsigned type.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.65 -r1.66 src/games/gomoku/main.c

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



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 21:48:21 UTC 2022

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

Log Message:
gomoku: use unsigned arithmetic for bitboard

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 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/pickmove.c
diff -u src/games/gomoku/pickmove.c:1.47 src/games/gomoku/pickmove.c:1.48
--- src/games/gomoku/pickmove.c:1.47	Sat May 28 08:19:18 2022
+++ src/games/gomoku/pickmove.c	Sat May 28 21:48:21 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pickmove.c,v 1.47 2022/05/28 08:19:18 rillig Exp $	*/
+/*	$NetBSD: pickmove.c,v 1.48 2022/05/28 21:48:21 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)pickmove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: pickmove.c,v 1.47 2022/05/28 08:19:18 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.48 2022/05/28 21:48:21 rillig Exp $");
 
 #include 
 #include 
@@ -46,9 +46,8 @@ __RCSID("$NetBSD: pickmove.c,v 1.47 2022
 #define BITS_PER_INT	(sizeof(int) * CHAR_BIT)
 #define MAPSZ		(BAREA / BITS_PER_INT)
 
-#define BIT_SET(a, b)	((a)[(b)/BITS_PER_INT] |= (1 << ((b) % BITS_PER_INT)))
-#define BIT_CLR(a, b)	((a)[(b)/BITS_PER_INT] &= ~(1 << ((b) % BITS_PER_INT)))
-#define BIT_TEST(a, b)	(((a)[(b)/BITS_PER_INT] & (1 << ((b) % BITS_PER_INT))) != 0)
+#define BIT_SET(a, b)	((a)[(unsigned int)(b)/BITS_PER_INT] |= (1 << ((unsigned int)(b) % BITS_PER_INT)))
+#define BIT_TEST(a, b)	(((a)[(unsigned int)(b)/BITS_PER_INT] & (1 << ((unsigned int)(b) % BITS_PER_INT))) != 0)
 
 /*
  * This structure is used to store overlap information between frames.



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 21:48:21 UTC 2022

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

Log Message:
gomoku: use unsigned arithmetic for bitboard

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 21:31:41 UTC 2022

Modified Files:
src/games/gomoku: main.c

Log Message:
gomoku: document that 'whatsup' is called on ^C as well


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/games/gomoku/main.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/main.c
diff -u src/games/gomoku/main.c:1.64 src/games/gomoku/main.c:1.65
--- src/games/gomoku/main.c:1.64	Sat May 28 20:57:26 2022
+++ src/games/gomoku/main.c	Sat May 28 21:31:41 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.64 2022/05/28 20:57:26 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.65 2022/05/28 21:31:41 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.64 2022/05/28 20:57:26 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.65 2022/05/28 21:31:41 rillig Exp $");
 
 #include 
 #include 
@@ -414,11 +414,11 @@ readinput(FILE *fp)
 
 #ifdef DEBUG
 /*
- * Handle strange situations.
+ * Handle strange situations and ^C.
  */
 /* ARGSUSED */
 void
-whatsup(int signum)
+whatsup(int signum __unused)
 {
 	int i, n, s1, s2, d1, d2;
 	struct spotstr *sp;



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 21:31:41 UTC 2022

Modified Files:
src/games/gomoku: main.c

Log Message:
gomoku: document that 'whatsup' is called on ^C as well


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/games/gomoku/main.c

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



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 20:57:26 UTC 2022

Modified Files:
src/games/gomoku: main.c

Log Message:
gomoku: allow saving a finished game without pressing Shift


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/games/gomoku/main.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/main.c
diff -u src/games/gomoku/main.c:1.63 src/games/gomoku/main.c:1.64
--- src/games/gomoku/main.c:1.63	Sat May 28 20:54:31 2022
+++ src/games/gomoku/main.c	Sat May 28 20:57:26 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.63 2022/05/28 20:54:31 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.64 2022/05/28 20:57:26 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.63 2022/05/28 20:54:31 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.64 2022/05/28 20:57:26 rillig Exp $");
 
 #include 
 #include 
@@ -389,7 +389,7 @@ again:
 			int ch = get_key("YyNnQqSs");
 			if (ch == 'Y' || ch == 'y')
 goto again;
-			if (ch == 'S') {	/* TODO: add 's' */
+			if (ch == 'S' || ch == 's') {
 save_game();
 goto replay;
 			}



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 20:57:26 UTC 2022

Modified Files:
src/games/gomoku: main.c

Log Message:
gomoku: allow saving a finished game without pressing Shift


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/games/gomoku/main.c

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



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 20:54:31 UTC 2022

Modified Files:
src/games/gomoku: bdisp.c main.c

Log Message:
gomoku: remove redundant parentheses, braces, newlines, clean up get_key

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/games/gomoku/bdisp.c
cvs rdiff -u -r1.62 -r1.63 src/games/gomoku/main.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/bdisp.c
diff -u src/games/gomoku/bdisp.c:1.49 src/games/gomoku/bdisp.c:1.50
--- src/games/gomoku/bdisp.c:1.49	Sat May 28 08:32:55 2022
+++ src/games/gomoku/bdisp.c	Sat May 28 20:54:31 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdisp.c,v 1.49 2022/05/28 08:32:55 rillig Exp $	*/
+/*	$NetBSD: bdisp.c,v 1.50 2022/05/28 20:54:31 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)bdisp.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdisp.c,v 1.49 2022/05/28 08:32:55 rillig Exp $");
+__RCSID("$NetBSD: bdisp.c,v 1.50 2022/05/28 20:54:31 rillig Exp $");
 
 #include 
 #include 
@@ -60,13 +60,13 @@ void
 cursinit(void)
 {
 
-	if (initscr() == NULL) {
+	if (initscr() == NULL)
 		errx(EXIT_FAILURE, "Couldn't initialize screen");
-	}
-	if ((LINES < SCRNH) || (COLS < SCRNW)) {
+
+	if (LINES < SCRNH || COLS < SCRNW)
 		errx(EXIT_FAILURE, "Screen too small (need %dx%d)",
 		SCRNW, SCRNH);
-	}
+
 	keypad(stdscr, true);
 	nonl();
 	noecho();
@@ -254,7 +254,6 @@ dislog(const char *str)
 /*
  * Display a question.
  */
-
 void
 ask(const char *str)
 {
@@ -269,19 +268,15 @@ ask(const char *str)
 int
 get_key(const char *allowed)
 {
-	int ch;
 
 	for (;;) {
-		ch = getch();
-		if (allowed != NULL &&
-		ch != '\0' && strchr(allowed, ch) == NULL) {
-			beep();
-			refresh();
-			continue;
-		}
-		break;
+		int ch = getch();
+		if (allowed == NULL || ch == '\0' ||
+		strchr(allowed, ch) != NULL)
+			return ch;
+		beep();
+		refresh();
 	}
-	return ch;
 }
 
 bool

Index: src/games/gomoku/main.c
diff -u src/games/gomoku/main.c:1.62 src/games/gomoku/main.c:1.63
--- src/games/gomoku/main.c:1.62	Sat May 28 17:51:27 2022
+++ src/games/gomoku/main.c	Sat May 28 20:54:31 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.62 2022/05/28 17:51:27 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.63 2022/05/28 20:54:31 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.62 2022/05/28 17:51:27 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.63 2022/05/28 20:54:31 rillig Exp $");
 
 #include 
 #include 
@@ -389,7 +389,7 @@ again:
 			int ch = get_key("YyNnQqSs");
 			if (ch == 'Y' || ch == 'y')
 goto again;
-			if (ch == 'S') {
+			if (ch == 'S') {	/* TODO: add 's' */
 save_game();
 goto replay;
 			}



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 20:54:31 UTC 2022

Modified Files:
src/games/gomoku: bdisp.c main.c

Log Message:
gomoku: remove redundant parentheses, braces, newlines, clean up get_key

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/games/gomoku/bdisp.c
cvs rdiff -u -r1.62 -r1.63 src/games/gomoku/main.c

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



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 19:47:24 UTC 2022

Modified Files:
src/games/gomoku: bdinit.c

Log Message:
gomoku: clean up initialization of overlap information

Fix variable names 'ia' and 'ib', which I forgot in the previous commit.

Move the documentation in the right places.

Split off another part of init_overlap, to make each function fit on a
single screen. Reducing the number of nested 'for' loops allows the
indentation to follow the NetBSD style.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/games/gomoku/bdinit.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/bdinit.c
diff -u src/games/gomoku/bdinit.c:1.26 src/games/gomoku/bdinit.c:1.27
--- src/games/gomoku/bdinit.c:1.26	Sat May 28 18:55:16 2022
+++ src/games/gomoku/bdinit.c	Sat May 28 19:47:24 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdinit.c,v 1.26 2022/05/28 18:55:16 rillig Exp $	*/
+/*	$NetBSD: bdinit.c,v 1.27 2022/05/28 19:47:24 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	from: @(#)bdinit.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdinit.c,v 1.26 2022/05/28 18:55:16 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.27 2022/05/28 19:47:24 rillig Exp $");
 
 #include 
 #include "gomoku.h"
@@ -160,43 +160,65 @@ init_board(void)
 	init_overlap();
 }
 
-/*-
- * ra	direction of frame A
- * ia	index of the spot in frame A (0 to 5)
- * rb	direction of frame B
- * ib	index of the spot in frame B (0 to 5)
+/*
+ * Variable names for frames A and B:
+ *
+ * fi	index of the frame in the global 'frames'
+ * r	direction: 0 = right, 1 = down right, 2 = down, 3 = down left
+ * d	direction delta, difference between adjacent spot indexes
+ * si	index of the spot in the frame, 0 to 5
+ */
+
+/*
+ * Each entry in the overlap array is a bit mask with eight bits corresponding
+ * to whether frame B overlaps frame A (as indexed by overlap[A * FAREA + B]).
+ *
+ * The eight bits correspond to whether A and B are open-ended (length 6) or
+ * closed (length 5).
+ *
+ *	0	A closed and B closed
+ *	1	A closed and B open
+ *	2	A open and B closed
+ *	3	A open and B open
+ *	4	A closed and B closed and overlaps in more than one spot
+ *	5	A closed and B open and overlaps in more than one spot
+ *	6	A open and B closed and overlaps in more than one spot
+ *	7	A open and B open and overlaps in more than one spot
+ *
+ * As pieces are played during the game, frames that no longer share an empty
+ * spot will be removed from the overlap array by setting the entry to 0.
  */
 static u_char
-adjust_overlap(u_char ov, int ra, int ia, int rb, int ib, int mask)
+adjust_overlap(u_char ov, int ra, int sia, int rb, int sib, int mask)
 {
-	ov |= (ib == 5) ? mask & 0xA : mask;
+	ov |= (sib == 5) ? mask & 0xA : mask;
 	if (rb != ra)
 		return ov;
 
 	/* compute the multiple spot overlap values */
-	switch (ia) {
+	switch (sia) {
 	case 0:
-		if (ib == 4)
+		if (sib == 4)
 			ov |= 0xA0;
-		else if (ib != 5)
+		else if (sib != 5)
 			ov |= 0xF0;
 		break;
 	case 1:
-		if (ib == 5)
+		if (sib == 5)
 			ov |= 0xA0;
 		else
 			ov |= 0xF0;
 		break;
 	case 4:
-		if (ib == 0)
+		if (sib == 0)
 			ov |= 0xC0;
 		else
 			ov |= 0xF0;
 		break;
 	case 5:
-		if (ib == 1)
+		if (sib == 1)
 			ov |= 0xC0;
-		else if (ib != 0)
+		else if (sib != 0)
 			ov |= 0xF0;
 		break;
 	default:
@@ -207,73 +229,56 @@ adjust_overlap(u_char ov, int ra, int ia
 }
 
 /*
- * Initialize the overlap array.
- * Each entry in the array is a bit mask with eight bits corresponding
- * to whether frame B overlaps frame A (as indexed by overlap[A * FAREA + B]).
- * The eight bits correspond to whether A and B are open-ended (length 6) or
- * closed (length 5).
- *	0	A closed and B closed
- *	1	A closed and B open
- *	2	A open and B closed
- *	3	A open and B open
- *	4	A closed and B closed and overlaps in more than one spot
- *	5	A closed and B open and overlaps in more than one spot
- *	6	A open and B closed and overlaps in more than one spot
- *	7	A open and B open and overlaps in more than one spot
- * As pieces are played, it can make frames not overlap if there are no
- * common open spaces shared between the two frames.
+ * Given a single spot 's' of frame A, update the overlap information for
+ * each frame B that overlaps frame A in that spot.
  */
 static void
+init_overlap_frame(int fia, int ra, int sia, int s, int mask)
+{
+
+	for (int rb = 4; --rb >= 0;) {
+		int db = dd[rb];
+
+		for (int sib = 0; sib < 6; sib++) {
+			/* spb0 is the spot where frame B starts. */
+			const struct spotstr *spb0 = [s - sib * db];
+			if (spb0->s_occ == BORDER)
+break;
+			if ((spb0->s_flags & BFLAG << rb) != 0)
+continue;
+
+			int fib = (int)(spb0->s_frame[rb] - frames);
+			intersect[fia * FAREA + fib] = (short)s;
+			u_char *op = [fia * FAREA + fib];
+			*op = adjust_overlap(*op, ra, sia, 

CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 19:47:24 UTC 2022

Modified Files:
src/games/gomoku: bdinit.c

Log Message:
gomoku: clean up initialization of overlap information

Fix variable names 'ia' and 'ib', which I forgot in the previous commit.

Move the documentation in the right places.

Split off another part of init_overlap, to make each function fit on a
single screen. Reducing the number of nested 'for' loops allows the
indentation to follow the NetBSD style.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/games/gomoku/bdinit.c

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



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 18:55:16 UTC 2022

Modified Files:
src/games/gomoku: bdinit.c

Log Message:
gomoku: clean up local variable names in init_overlap

By clearly associating each variable to either frame A or frame B,
suddenly the code becomes understandable. For the benefit of future
readers, explain the naming scheme.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/games/gomoku/bdinit.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/bdinit.c
diff -u src/games/gomoku/bdinit.c:1.25 src/games/gomoku/bdinit.c:1.26
--- src/games/gomoku/bdinit.c:1.25	Sat May 28 17:51:27 2022
+++ src/games/gomoku/bdinit.c	Sat May 28 18:55:16 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdinit.c,v 1.25 2022/05/28 17:51:27 rillig Exp $	*/
+/*	$NetBSD: bdinit.c,v 1.26 2022/05/28 18:55:16 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	from: @(#)bdinit.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdinit.c,v 1.25 2022/05/28 17:51:27 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.26 2022/05/28 18:55:16 rillig Exp $");
 
 #include 
 #include "gomoku.h"
@@ -160,6 +160,52 @@ init_board(void)
 	init_overlap();
 }
 
+/*-
+ * ra	direction of frame A
+ * ia	index of the spot in frame A (0 to 5)
+ * rb	direction of frame B
+ * ib	index of the spot in frame B (0 to 5)
+ */
+static u_char
+adjust_overlap(u_char ov, int ra, int ia, int rb, int ib, int mask)
+{
+	ov |= (ib == 5) ? mask & 0xA : mask;
+	if (rb != ra)
+		return ov;
+
+	/* compute the multiple spot overlap values */
+	switch (ia) {
+	case 0:
+		if (ib == 4)
+			ov |= 0xA0;
+		else if (ib != 5)
+			ov |= 0xF0;
+		break;
+	case 1:
+		if (ib == 5)
+			ov |= 0xA0;
+		else
+			ov |= 0xF0;
+		break;
+	case 4:
+		if (ib == 0)
+			ov |= 0xC0;
+		else
+			ov |= 0xF0;
+		break;
+	case 5:
+		if (ib == 1)
+			ov |= 0xC0;
+		else if (ib != 0)
+			ov |= 0xF0;
+		break;
+	default:
+		ov |= 0xF0;
+	}
+
+	return ov;
+}
+
 /*
  * Initialize the overlap array.
  * Each entry in the array is a bit mask with eight bits corresponding
@@ -183,69 +229,49 @@ init_overlap(void)
 
 	memset(overlap, 0, sizeof(overlap));
 	memset(intersect, 0, sizeof(intersect));
-	u_char *op = [FAREA * FAREA];
-	short *ip = [FAREA * FAREA];
 
-	for (unsigned fi = FAREA; fi-- > 0; ) {	/* each frame */
-	struct combostr *cbp = [fi];
-	op -= FAREA;
-	ip -= FAREA;
-	int vertex = cbp->c_vertex;
-	struct spotstr *sp1 = [vertex];
-	int d1 = dd[cbp->c_dir];
+	/*-
+	 * Variables for frames A and B:
+	 *
+	 * fi	index of the frame in the global 'frames'
+	 * r	direction: 0 = right, 1 = down right, 2 = down, 3 = down left
+	 * d	direction delta, difference between adjacent spot indexes
+	 * si	index of the spot in the frame, 0 to 5
+	 * sp	data of the spot at index i
+	 */
+
+	for (unsigned fia = FAREA; fia-- > 0; ) {
+	struct combostr *fa = [fia];
+	int vertex = fa->c_vertex;
+	struct spotstr *spa = [vertex];
+	u_char ra = fa->c_dir;
+	int da = dd[ra];
+
 	/*
-	 * s = 5 if closed, 6 if open.
-	 * At this point black & white are the same.
+	 * len = 5 if closed, 6 if open.
+	 * At this point, Black and White have the same values.
 	 */
-	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) {
+	int len = 5 + spa->s_fval[BLACK][ra].cv_win;
+
+	for (int sia = 0; sia < len; sia++, spa += da, vertex += da) {
 		/* the sixth spot in frame A only overlaps if it is open */
-		int mask = (i == 5) ? 0xC : 0xF;
-		/* for each direction */
-		for (int r = 4; --r >= 0; ) {
-		struct spotstr *sp2 = sp1;
-		int d2 = dd[r];
-		/* for each frame that intersects at spot sp1 */
-		for (int f = 0; f < 6; f++, sp2 -= d2) {
-			if (sp2->s_occ == BORDER)
+		int mask = (sia == 5) ? 0xC : 0xF;
+
+		for (int rb = 4; --rb >= 0; ) {
+		struct spotstr *spb = spa;
+		int db = dd[rb];
+
+		/* for each frame that intersects at spot spa */
+		for (int sib = 0; sib < 6; sib++, spb -= db) {
+			if (spb->s_occ == BORDER)
 			break;
-			if ((sp2->s_flags & BFLAG << r) != 0)
+			if ((spb->s_flags & BFLAG << rb) != 0)
 			continue;
-			int n = (int)(sp2->s_frame[r] - frames);
-			ip[n] = (short)vertex;
-			op[n] |= (f == 5) ? mask & 0xA : mask;
-			if (r == cbp->c_dir) {
-			/* compute the multiple spot overlap values */
-			switch (i) {
-			case 0:	/* sp1 is the first spot in A */
-if (f == 4)
-op[n] |= 0xA0;
-else if (f != 5)
-op[n] |= 0xF0;
-break;
-			case 1:	/* sp1 is the second spot in A */
-if (f == 5)
-op[n] |= 0xA0;
-else
-op[n] |= 0xF0;
-break;
-			case 4:	/* sp1 is the penultimate spot in A */
-if (f == 0)
-op[n] |= 0xC0;
-else
-

CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 18:55:16 UTC 2022

Modified Files:
src/games/gomoku: bdinit.c

Log Message:
gomoku: clean up local variable names in init_overlap

By clearly associating each variable to either frame A or frame B,
suddenly the code becomes understandable. For the benefit of future
readers, explain the naming scheme.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/games/gomoku/bdinit.c

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



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 17:51:27 UTC 2022

Modified Files:
src/games/gomoku: bdinit.c gomoku.h main.c

Log Message:
gomoku: split initialization of the board into smaller functions

The comments about the "top border" and "bottom border" had been wrong
all the time. Mention the corners in the comments, to remove the magic
from the various '+ 1' in the code.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.44 -r1.45 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.61 -r1.62 src/games/gomoku/main.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/bdinit.c
diff -u src/games/gomoku/bdinit.c:1.24 src/games/gomoku/bdinit.c:1.25
--- src/games/gomoku/bdinit.c:1.24	Sat May 28 08:32:55 2022
+++ src/games/gomoku/bdinit.c	Sat May 28 17:51:27 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdinit.c,v 1.24 2022/05/28 08:32:55 rillig Exp $	*/
+/*	$NetBSD: bdinit.c,v 1.25 2022/05/28 17:51:27 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,119 +34,129 @@
 
 #include 
 /*	from: @(#)bdinit.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdinit.c,v 1.24 2022/05/28 08:32:55 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.25 2022/05/28 17:51:27 rillig Exp $");
 
 #include 
 #include "gomoku.h"
 
 static void init_overlap(void);
 
+static void
+init_spot_flags_and_fval(struct spotstr *sp, int i, int j)
+{
+
+	sp->s_flags = 0;
+	if (j < 5) {
+		/* directions 1, 2, 3 are blocked */
+		sp->s_flags |= (BFLAG << 1) | (BFLAG << 2) |
+		(BFLAG << 3);
+		sp->s_fval[BLACK][1].s = 0x600;
+		sp->s_fval[BLACK][2].s = 0x600;
+		sp->s_fval[BLACK][3].s = 0x600;
+		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) {
+		/* five spaces, blocked on one side */
+		sp->s_fval[BLACK][1].s = 0x500;
+		sp->s_fval[BLACK][2].s = 0x500;
+		sp->s_fval[BLACK][3].s = 0x500;
+		sp->s_fval[WHITE][1].s = 0x500;
+		sp->s_fval[WHITE][2].s = 0x500;
+		sp->s_fval[WHITE][3].s = 0x500;
+	} else {
+		/* six spaces, not blocked */
+		sp->s_fval[BLACK][1].s = 0x401;
+		sp->s_fval[BLACK][2].s = 0x401;
+		sp->s_fval[BLACK][3].s = 0x401;
+		sp->s_fval[WHITE][1].s = 0x401;
+		sp->s_fval[WHITE][2].s = 0x401;
+		sp->s_fval[WHITE][3].s = 0x401;
+	}
+	if (i > (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)) {
+		sp->s_fval[BLACK][0].s = 0x500;
+		sp->s_fval[WHITE][0].s = 0x500;
+		/* if direction 1 is not blocked */
+		if ((sp->s_flags & (BFLAG << 1)) == 0) {
+			sp->s_fval[BLACK][1].s = 0x500;
+			sp->s_fval[WHITE][1].s = 0x500;
+		}
+	} else {
+		sp->s_fval[BLACK][0].s = 0x401;
+		sp->s_fval[WHITE][0].s = 0x401;
+		if (i < 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 &&
+		(sp->s_flags & (BFLAG << 3)) == 0) {
+			sp->s_fval[BLACK][3].s = 0x500;
+			sp->s_fval[WHITE][3].s = 0x500;
+		}
+	}
+}
+
+/* Allocate one of the pre-allocated frames for each non-blocked frame. */
+static void
+init_spot_frame(struct spotstr *sp, struct combostr **cbpp)
+{
+
+	for (int r = 4; --r >= 0; ) {
+		if ((sp->s_flags & (BFLAG << r)) != 0)
+			continue;
+
+		struct combostr *cbp = (*cbpp)++;
+		cbp->c_combo.s = sp->s_fval[BLACK][r].s;
+		cbp->c_vertex = (u_short)(sp - board);
+		cbp->c_nframes = 1;
+		cbp->c_dir = r;
+		sp->s_frame[r] = cbp;
+	}
+}
+
 void
-bdinit(struct spotstr *bp)
+init_board(void)
 {
-	struct spotstr *sp;
-	struct combostr *cbp;
 
 	game.nmoves = 0;
 	game.winning_spot = 0;
 
-	/* mark the borders as such */
-	sp = bp;
+	struct spotstr *sp = board;
 	for (int i = 0; i < 1 + BSZ + 1; i++, sp++) {
-		sp->s_occ = BORDER;			/* top border */
+		sp->s_occ = BORDER;	/* bottom border and corners */
 		sp->s_flags = BFLAGALL;
 	}
 
-	/* fill entire board with EMPTY spots */
+	/* fill the playing area of the board with EMPTY spots */
+	struct combostr *cbp = frames;
 	memset(frames, 0, sizeof(frames));
-	cbp = frames;
-	for (int j = 0; ++j < BSZ + 1; sp++) {		/* for each row */
-		for (int i = 0; ++i < BSZ + 1; sp++) {	/* for each column */
+	for (int row = 1; row <= BSZ; row++, sp++) {
+		for (int col = 1; col <= BSZ; col++, sp++) {
 			sp->s_occ = EMPTY;
-			sp->s_flags = 0;
 			sp->s_wval = 0;
-			if (j < 5) {
-/* directions 1, 2, 3 are blocked */
-sp->s_flags |= (BFLAG << 1) | (BFLAG << 2) |
-(BFLAG << 3);
-sp->s_fval[BLACK][1].s = 0x600;
-sp->s_fval[BLACK][2].s = 0x600;
-sp->s_fval[BLACK][3].s = 0x600;
-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) 

CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 17:51:27 UTC 2022

Modified Files:
src/games/gomoku: bdinit.c gomoku.h main.c

Log Message:
gomoku: split initialization of the board into smaller functions

The comments about the "top border" and "bottom border" had been wrong
all the time. Mention the corners in the comments, to remove the magic
from the various '+ 1' in the code.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.44 -r1.45 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.61 -r1.62 src/games/gomoku/main.c

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



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 08:32:56 UTC 2022

Modified Files:
src/games/gomoku: bdinit.c bdisp.c gomoku.h makemove.c

Log Message:
gomoku: highlight the winning frame


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.48 -r1.49 src/games/gomoku/bdisp.c
cvs rdiff -u -r1.43 -r1.44 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.32 -r1.33 src/games/gomoku/makemove.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/bdinit.c
diff -u src/games/gomoku/bdinit.c:1.23 src/games/gomoku/bdinit.c:1.24
--- src/games/gomoku/bdinit.c:1.23	Sat May 28 08:19:18 2022
+++ src/games/gomoku/bdinit.c	Sat May 28 08:32:55 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdinit.c,v 1.23 2022/05/28 08:19:18 rillig Exp $	*/
+/*	$NetBSD: bdinit.c,v 1.24 2022/05/28 08:32:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	from: @(#)bdinit.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdinit.c,v 1.23 2022/05/28 08:19:18 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.24 2022/05/28 08:32:55 rillig Exp $");
 
 #include 
 #include "gomoku.h"
@@ -48,6 +48,7 @@ bdinit(struct spotstr *bp)
 	struct combostr *cbp;
 
 	game.nmoves = 0;
+	game.winning_spot = 0;
 
 	/* mark the borders as such */
 	sp = bp;

Index: src/games/gomoku/bdisp.c
diff -u src/games/gomoku/bdisp.c:1.48 src/games/gomoku/bdisp.c:1.49
--- src/games/gomoku/bdisp.c:1.48	Sat May 28 08:19:18 2022
+++ src/games/gomoku/bdisp.c	Sat May 28 08:32:55 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdisp.c,v 1.48 2022/05/28 08:19:18 rillig Exp $	*/
+/*	$NetBSD: bdisp.c,v 1.49 2022/05/28 08:32:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)bdisp.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdisp.c,v 1.48 2022/05/28 08:19:18 rillig Exp $");
+__RCSID("$NetBSD: bdisp.c,v 1.49 2022/05/28 08:32:55 rillig Exp $");
 
 #include 
 #include 
@@ -148,6 +148,19 @@ bdwho(void)
 	bw, plyr[BLACK], ww, plyr[WHITE]);
 }
 
+static bool
+should_highlight(int s)
+{
+
+	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])
+return true;
+	return false;
+}
+
 /*
  * Update the board display after a move.
  */
@@ -171,8 +184,7 @@ bdisp(void)
 c = pcolor[sp->s_occ];
 
 			move(scr_y(j), scr_x(i));
-			if (game.nmoves > 0 &&
-			game.moves[game.nmoves - 1] == PT(i, j)) {
+			if (should_highlight(PT(i, j))) {
 attron(A_BOLD);
 addch(c);
 attroff(A_BOLD);

Index: src/games/gomoku/gomoku.h
diff -u src/games/gomoku/gomoku.h:1.43 src/games/gomoku/gomoku.h:1.44
--- src/games/gomoku/gomoku.h:1.43	Sat May 28 08:19:18 2022
+++ src/games/gomoku/gomoku.h	Sat May 28 08:32:55 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: gomoku.h,v 1.43 2022/05/28 08:19:18 rillig Exp $	*/
+/*	$NetBSD: gomoku.h,v 1.44 2022/05/28 08:32:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -218,6 +218,8 @@ struct	spotstr {
 struct game {
 	int moves[BSZ * BSZ];		/* log of all played moves */
 	unsigned int nmoves;		/* number of played moves */
+	int winning_spot;
+	int winning_dir;
 };
 
 extern	const char	letters[];

Index: src/games/gomoku/makemove.c
diff -u src/games/gomoku/makemove.c:1.32 src/games/gomoku/makemove.c:1.33
--- src/games/gomoku/makemove.c:1.32	Sat May 28 08:19:18 2022
+++ src/games/gomoku/makemove.c	Sat May 28 08:32:55 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: makemove.c,v 1.32 2022/05/28 08:19:18 rillig Exp $	*/
+/*	$NetBSD: makemove.c,v 1.33 2022/05/28 08:32:55 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)makemove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: makemove.c,v 1.32 2022/05/28 08:19:18 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.33 2022/05/28 08:32:55 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -154,8 +154,11 @@ makemove(int us, int mv)
 		}
 
 		/* check for game over */
-		if (n == 5)
+		if (n == 5) {
+		game.winning_spot = (int)(fsp - board);
+		game.winning_dir = r;
 		return WIN;
+		}
 
 		/* compute new value & combo number for this frame & color */
 		fsp->s_fval[us != BLACK ? BLACK : WHITE][r].s = 0x600;



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 08:32:56 UTC 2022

Modified Files:
src/games/gomoku: bdinit.c bdisp.c gomoku.h makemove.c

Log Message:
gomoku: highlight the winning frame


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.48 -r1.49 src/games/gomoku/bdisp.c
cvs rdiff -u -r1.43 -r1.44 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.32 -r1.33 src/games/gomoku/makemove.c

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



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 08:19:19 UTC 2022

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

Log Message:
gomoku: group movelog and nmoves into a game struct

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.47 -r1.48 src/games/gomoku/bdisp.c
cvs rdiff -u -r1.42 -r1.43 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.60 -r1.61 src/games/gomoku/main.c
cvs rdiff -u -r1.31 -r1.32 src/games/gomoku/makemove.c
cvs rdiff -u -r1.46 -r1.47 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/bdinit.c
diff -u src/games/gomoku/bdinit.c:1.22 src/games/gomoku/bdinit.c:1.23
--- src/games/gomoku/bdinit.c:1.22	Fri May 27 19:59:56 2022
+++ src/games/gomoku/bdinit.c	Sat May 28 08:19:18 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdinit.c,v 1.22 2022/05/27 19:59:56 rillig Exp $	*/
+/*	$NetBSD: bdinit.c,v 1.23 2022/05/28 08:19:18 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	from: @(#)bdinit.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdinit.c,v 1.22 2022/05/27 19:59:56 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.23 2022/05/28 08:19:18 rillig Exp $");
 
 #include 
 #include "gomoku.h"
@@ -47,7 +47,7 @@ bdinit(struct spotstr *bp)
 	struct spotstr *sp;
 	struct combostr *cbp;
 
-	nmoves = 0;
+	game.nmoves = 0;
 
 	/* mark the borders as such */
 	sp = bp;

Index: src/games/gomoku/bdisp.c
diff -u src/games/gomoku/bdisp.c:1.47 src/games/gomoku/bdisp.c:1.48
--- src/games/gomoku/bdisp.c:1.47	Fri May 27 19:59:56 2022
+++ src/games/gomoku/bdisp.c	Sat May 28 08:19:18 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdisp.c,v 1.47 2022/05/27 19:59:56 rillig Exp $	*/
+/*	$NetBSD: bdisp.c,v 1.48 2022/05/28 08:19:18 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)bdisp.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdisp.c,v 1.47 2022/05/27 19:59:56 rillig Exp $");
+__RCSID("$NetBSD: bdisp.c,v 1.48 2022/05/28 08:19:18 rillig Exp $");
 
 #include 
 #include 
@@ -171,7 +171,8 @@ bdisp(void)
 c = pcolor[sp->s_occ];
 
 			move(scr_y(j), scr_x(i));
-			if (nmoves > 0 && movelog[nmoves - 1] == PT(i, j)) {
+			if (game.nmoves > 0 &&
+			game.moves[game.nmoves - 1] == PT(i, j)) {
 attron(A_BOLD);
 addch(c);
 attroff(A_BOLD);

Index: src/games/gomoku/gomoku.h
diff -u src/games/gomoku/gomoku.h:1.42 src/games/gomoku/gomoku.h:1.43
--- src/games/gomoku/gomoku.h:1.42	Sat May 28 06:25:35 2022
+++ src/games/gomoku/gomoku.h	Sat May 28 08:19:18 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: gomoku.h,v 1.42 2022/05/28 06:25:35 rillig Exp $	*/
+/*	$NetBSD: gomoku.h,v 1.43 2022/05/28 08:19:18 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -215,6 +215,11 @@ struct	spotstr {
 #define BFLAG		0x01	/* frame intersects border or dead */
 #define BFLAGALL	0x0F	/* all frames dead */
 
+struct game {
+	int moves[BSZ * BSZ];		/* log of all played moves */
+	unsigned int nmoves;		/* number of played moves */
+};
+
 extern	const char	letters[];
 extern	const char	pdir[];
 
@@ -224,8 +229,7 @@ extern	struct	combostr frames[FAREA];		/
 extern	struct	combostr *sortframes[2];	/* sorted, non-empty frames */
 extern	u_char	overlap[FAREA * FAREA];
 extern	short	intersect[FAREA * FAREA];	/* frame [a][b] intersection */
-extern	int	movelog[BSZ * BSZ];
-extern	unsigned int nmoves;
+extern	struct game	game;
 extern	int	debug;
 
 extern bool interactive;

Index: src/games/gomoku/main.c
diff -u src/games/gomoku/main.c:1.60 src/games/gomoku/main.c:1.61
--- src/games/gomoku/main.c:1.60	Sat May 28 06:25:35 2022
+++ src/games/gomoku/main.c	Sat May 28 08:19:18 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.60 2022/05/28 06:25:35 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.61 2022/05/28 08:19:18 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.60 2022/05/28 06:25:35 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.61 2022/05/28 08:19:18 rillig Exp $");
 
 #include 
 #include 
@@ -79,8 +79,7 @@ struct	combostr *sortframes[2];	/* sorte
 u_char	overlap[FAREA * FAREA];		/* non-zero if frame [a][b] overlap;
 	 * see init_overlap */
 short	intersect[FAREA * FAREA];	/* frame [a][b] intersection */
-int	movelog[BSZ * BSZ];		/* log of all played moves */
-unsigned int nmoves;			/* number of played moves */
+struct game game;
 const char *plyr[2] = { "???", "???" };	/* who's who */
 
 static int readinput(FILE *);
@@ -116,8 +115,8 @@ save_game(void)
 		misclog("cannot create save file");
 		return;
 	}
-	for (unsigned int i = 0; i < nmoves; i++)
-		fprintf(fp, "%s\n", stoc(movelog[i]));
+	for (unsigned int i = 0; i < game.nmoves; i++)
+		

CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 08:19:19 UTC 2022

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

Log Message:
gomoku: group movelog and nmoves into a game struct

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.47 -r1.48 src/games/gomoku/bdisp.c
cvs rdiff -u -r1.42 -r1.43 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.60 -r1.61 src/games/gomoku/main.c
cvs rdiff -u -r1.31 -r1.32 src/games/gomoku/makemove.c
cvs rdiff -u -r1.46 -r1.47 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 08:09:22 UTC 2022

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

Log Message:
gomoku: split makemove into smaller functions

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/games/gomoku/makemove.c

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



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 08:09:22 UTC 2022

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

Log Message:
gomoku: split makemove into smaller functions

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/games/gomoku/makemove.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/makemove.c
diff -u src/games/gomoku/makemove.c:1.30 src/games/gomoku/makemove.c:1.31
--- src/games/gomoku/makemove.c:1.30	Sat May 28 07:58:35 2022
+++ src/games/gomoku/makemove.c	Sat May 28 08:09:22 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: makemove.c,v 1.30 2022/05/28 07:58:35 rillig Exp $	*/
+/*	$NetBSD: makemove.c,v 1.31 2022/05/28 08:09:22 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)makemove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: makemove.c,v 1.30 2022/05/28 07:58:35 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.31 2022/05/28 08:09:22 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -61,6 +61,33 @@ is_tie(void)
 	return true;
 }
 
+static void
+sortframes_remove(struct combostr *cbp)
+{
+
+	if (cbp->c_next == NULL)
+		return;
+
+	if (sortframes[BLACK] == cbp)
+		sortframes[BLACK] = cbp->c_next;
+	if (sortframes[WHITE] == cbp)
+		sortframes[WHITE] = cbp->c_next;
+	cbp->c_next->c_prev = cbp->c_prev;
+	cbp->c_prev->c_next = cbp->c_next;
+}
+
+static int
+old_weight_value(const struct spotstr *sp, int r)
+{
+	union comboval cb;
+	int val = 0;
+	if ((cb = sp->s_fval[BLACK][r]).s <= 0x500)
+		val += weight[5 - cb.cv_force - cb.cv_win];
+	if ((cb = sp->s_fval[WHITE][r]).s <= 0x500)
+		val += weight[5 - cb.cv_force - cb.cv_win];
+	return val;
+}
+
 /*
  * Return values:
  *	MOVEOK	everything is OK.
@@ -91,32 +118,17 @@ makemove(int us, int mv)
 	for (int r = 4; --r >= 0; ) {		/* for each direction */
 	int d = dd[r];
 	struct spotstr *fsp = [mv];
-	int bmask = BFLAG << r;
 
 	for (int f = 5; --f >= 0; fsp -= d) {	/* for each frame */
 		if (fsp->s_occ == BORDER)
 		goto nextr;
-		if ((fsp->s_flags & bmask) != 0)
+		if ((fsp->s_flags & BFLAG << r) != 0)
 		continue;
 
-		/* remove this frame from the sorted list of frames */
 		struct combostr *cbp = fsp->s_frame[r];
-		if (cbp->c_next != NULL) {
-			if (sortframes[BLACK] == cbp)
-			sortframes[BLACK] = cbp->c_next;
-			if (sortframes[WHITE] == cbp)
-			sortframes[WHITE] = cbp->c_next;
-			cbp->c_next->c_prev = cbp->c_prev;
-			cbp->c_prev->c_next = cbp->c_next;
-		}
+		sortframes_remove(cbp);
 
-		/* compute old weight value for this frame */
-		union comboval cb;
-		int val = 0;
-		if ((cb = fsp->s_fval[BLACK][r]).s <= 0x500)
-		val += weight[5 - cb.cv_force - cb.cv_win];
-		if ((cb = fsp->s_fval[WHITE][r]).s <= 0x500)
-		val += weight[5 - cb.cv_force - cb.cv_win];
+		int val = old_weight_value(fsp, r);
 
 		/* compute new combo value for this frame */
 		bool space = fsp->s_occ == EMPTY;
@@ -129,7 +141,7 @@ makemove(int us, int mv)
 			sp->s_wval -= val;
 		else {
 			/* this frame is now blocked, adjust values */
-			fsp->s_flags |= bmask;
+			fsp->s_flags |= BFLAG << r;
 			fsp->s_fval[BLACK][r].s = 0x600;
 			fsp->s_fval[WHITE][r].s = 0x600;
 			while (--i >= 0) {



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 07:58:36 UTC 2022

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

Log Message:
gomoku: announce tie as early as possible


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/games/gomoku/makemove.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/makemove.c
diff -u src/games/gomoku/makemove.c:1.29 src/games/gomoku/makemove.c:1.30
--- src/games/gomoku/makemove.c:1.29	Sat May 28 06:25:35 2022
+++ src/games/gomoku/makemove.c	Sat May 28 07:58:35 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: makemove.c,v 1.29 2022/05/28 06:25:35 rillig Exp $	*/
+/*	$NetBSD: makemove.c,v 1.30 2022/05/28 07:58:35 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)makemove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: makemove.c,v 1.29 2022/05/28 06:25:35 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.30 2022/05/28 07:58:35 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -50,6 +50,17 @@ static const int weight[5] = { 0, 1, 7, 
 
 static void update_overlap(struct spotstr *);
 
+static bool
+is_tie(void)
+{
+
+	for (int y = 1; y <= BSZ; y++)
+		for (int x = 1; x <= BSZ; x++)
+			if (board[PT(x, y)].s_wval != 0)
+return false;
+	return true;
+}
+
 /*
  * Return values:
  *	MOVEOK	everything is OK.
@@ -199,11 +210,7 @@ makemove(int us, int mv)
 
 	update_overlap([mv]);
 
-	/*
-	 * TODO: Declare a tie as soon as all frames are blocked. This is
-	 *  usually much earlier than when the whole board is filled.
-	 */
-	if (nmoves == BSZ * BSZ)
+	if (is_tie())
 		return TIE;
 
 	return MOVEOK;



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 07:58:36 UTC 2022

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

Log Message:
gomoku: announce tie as early as possible


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/games/gomoku/makemove.c

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



CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 06:25:35 UTC 2022

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

Log Message:
gomoku: extract update_overlap_different_direction

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.59 -r1.60 src/games/gomoku/main.c
cvs rdiff -u -r1.28 -r1.29 src/games/gomoku/makemove.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.41 src/games/gomoku/gomoku.h:1.42
--- src/games/gomoku/gomoku.h:1.41	Fri May 27 23:10:54 2022
+++ src/games/gomoku/gomoku.h	Sat May 28 06:25:35 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: gomoku.h,v 1.41 2022/05/27 23:10:54 rillig Exp $	*/
+/*	$NetBSD: gomoku.h,v 1.42 2022/05/28 06:25:35 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -222,7 +222,7 @@ extern	const int dd[4];
 extern	struct	spotstr	board[BAREA];		/* info for board */
 extern	struct	combostr frames[FAREA];		/* storage for single frames */
 extern	struct	combostr *sortframes[2];	/* sorted, non-empty frames */
-extern	u_char	overlap[FAREA * FAREA];		/* frame [a][b] overlap */
+extern	u_char	overlap[FAREA * FAREA];
 extern	short	intersect[FAREA * FAREA];	/* frame [a][b] intersection */
 extern	int	movelog[BSZ * BSZ];
 extern	unsigned int nmoves;

Index: src/games/gomoku/main.c
diff -u src/games/gomoku/main.c:1.59 src/games/gomoku/main.c:1.60
--- src/games/gomoku/main.c:1.59	Fri May 27 19:59:56 2022
+++ src/games/gomoku/main.c	Sat May 28 06:25:35 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.59 2022/05/27 19:59:56 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.60 2022/05/28 06:25:35 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.59 2022/05/27 19:59:56 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.60 2022/05/28 06:25:35 rillig Exp $");
 
 #include 
 #include 
@@ -76,7 +76,8 @@ const char	pdir[4]		= "-\\|/";
 struct	spotstr	board[BAREA];		/* info for board */
 struct	combostr frames[FAREA];		/* storage for all frames */
 struct	combostr *sortframes[2];	/* sorted list of non-empty frames */
-u_char	overlap[FAREA * FAREA];		/* true if frame [a][b] overlap */
+u_char	overlap[FAREA * FAREA];		/* non-zero if frame [a][b] overlap;
+	 * see init_overlap */
 short	intersect[FAREA * FAREA];	/* frame [a][b] intersection */
 int	movelog[BSZ * BSZ];		/* log of all played moves */
 unsigned int nmoves;			/* number of played moves */

Index: src/games/gomoku/makemove.c
diff -u src/games/gomoku/makemove.c:1.28 src/games/gomoku/makemove.c:1.29
--- src/games/gomoku/makemove.c:1.28	Sat May 28 05:44:41 2022
+++ src/games/gomoku/makemove.c	Sat May 28 06:25:35 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: makemove.c,v 1.28 2022/05/28 05:44:41 rillig Exp $	*/
+/*	$NetBSD: makemove.c,v 1.29 2022/05/28 06:25:35 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)makemove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: makemove.c,v 1.28 2022/05/28 05:44:41 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.29 2022/05/28 06:25:35 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -254,6 +254,30 @@ update_overlap_same_direction(const stru
 }
 
 /*
+ * The last move was at 'osp', which is part of frame 'a'. There are 6 frames
+ * with direction 'rb' that cross frame 'a' in 'osp'. Since the spot 'osp'
+ * cannot be used as a double threat anymore, mark each of these crossing
+ * frames as non-overlapping with frame 'a'.
+ */
+static void
+update_overlap_different_direction(const struct spotstr *osp, int a, int rb)
+{
+
+	int db = dd[rb];
+	for (int i = 0; i < 6; i++) {
+		const struct spotstr *sp = osp - db * i;
+		if (sp->s_occ == BORDER)
+			break;
+		if ((sp->s_flags & BFLAG << rb) != 0)
+			continue;
+
+		int b = (int)(sp->s_frame[rb] - frames);
+		overlap[a * FAREA + b] = 0;
+		overlap[b * FAREA + a] = 0;
+	}
+}
+
+/*
  * fix up the overlap array according to the changed 'osp'.
  */
 static void
@@ -264,7 +288,7 @@ update_overlap(struct spotstr *osp)
 	int d = dd[r];
 	struct spotstr *sp1 = osp;
 
-	/* for each frame that contains 'osp' */
+	/* for each frame 'a' that contains the spot 'osp' */
 	for (int f = 0; f < 6; f++, sp1 -= d) {
 		if (sp1->s_occ == BORDER)
 		break;
@@ -279,8 +303,8 @@ update_overlap(struct spotstr *osp)
 		 * since the two frames can overlap at more than one point.
 		 */
 		int a = (int)(sp1->s_frame[r] - frames);
-		struct spotstr *sp2 = sp1 - d;
 
+		struct spotstr *sp2 = sp1 - d;
 		for (int i = f + 1; i < 6; i++, sp2 -= d) {
 		if (sp2->s_occ == BORDER)
 			break;
@@ -291,19 +315,8 @@ update_overlap(struct spotstr *osp)
 		}
 
 		/* the other directions can only intersect at spot osp */
-		

CVS commit: src/games/gomoku

2022-05-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 06:25:35 UTC 2022

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

Log Message:
gomoku: extract update_overlap_different_direction

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.59 -r1.60 src/games/gomoku/main.c
cvs rdiff -u -r1.28 -r1.29 src/games/gomoku/makemove.c

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



CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 05:44:41 UTC 2022

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

Log Message:
gomoku: extract separate function update_overlap_same_direction

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/games/gomoku/makemove.c

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



CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 05:44:41 UTC 2022

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

Log Message:
gomoku: extract separate function update_overlap_same_direction

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/games/gomoku/makemove.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/makemove.c
diff -u src/games/gomoku/makemove.c:1.27 src/games/gomoku/makemove.c:1.28
--- src/games/gomoku/makemove.c:1.27	Sat May 28 05:14:34 2022
+++ src/games/gomoku/makemove.c	Sat May 28 05:44:41 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: makemove.c,v 1.27 2022/05/28 05:14:34 rillig Exp $	*/
+/*	$NetBSD: makemove.c,v 1.28 2022/05/28 05:44:41 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)makemove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: makemove.c,v 1.27 2022/05/28 05:14:34 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.28 2022/05/28 05:44:41 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -77,10 +77,9 @@ makemove(int us, int mv)
 
 	/* compute new frame values */
 	sp->s_wval = 0;
-	struct spotstr *osp = sp;
 	for (int r = 4; --r >= 0; ) {		/* for each direction */
 	int d = dd[r];
-	struct spotstr *fsp = osp;
+	struct spotstr *fsp = [mv];
 	int bmask = BFLAG << r;
 
 	for (int f = 5; --f >= 0; fsp -= d) {	/* for each frame */
@@ -198,7 +197,7 @@ makemove(int us, int mv)
 	;
 	}
 
-	update_overlap(osp);
+	update_overlap([mv]);
 
 	/*
 	 * TODO: Declare a tie as soon as all frames are blocked. This is
@@ -210,8 +209,52 @@ makemove(int us, int mv)
 	return MOVEOK;
 }
 
+static void
+update_overlap_same_direction(const struct spotstr *sp1,
+			  const struct spotstr *sp2,
+			  int a, int d, int i_minus_f, int r)
+{
+	/*
+	 * count the number of empty spots to see if there is
+	 * still an overlap.
+	 */
+	int n = 0;
+	const struct spotstr *sp = sp1;
+	const struct spotstr *esp = NULL;
+	for (int b = i_minus_f; b < 5; b++, sp += d) {
+		if (sp->s_occ == EMPTY) {
+			esp = sp;	/* save the intersection point */
+			n++;
+		}
+	}
+
+	int b = (int)(sp2->s_frame[r] - frames);
+	if (n == 0) {
+		if (sp->s_occ == EMPTY) {
+			overlap[a * FAREA + b] &= 0xA;
+			overlap[b * FAREA + a] &= 0xC;
+			intersect[a * FAREA + b] = (short)(sp - board);
+			intersect[b * FAREA + a] = (short)(sp - board);
+		} else {
+			overlap[a * FAREA + b] = 0;
+			overlap[b * FAREA + a] = 0;
+		}
+	} else if (n == 1) {
+		if (sp->s_occ == EMPTY) {
+			overlap[a * FAREA + b] &= 0xAF;
+			overlap[b * FAREA + a] &= 0xCF;
+		} else {
+			overlap[a * FAREA + b] &= 0xF;
+			overlap[b * FAREA + a] &= 0xF;
+		}
+		intersect[a * FAREA + b] = (short)(esp - board);
+		intersect[b * FAREA + a] = (short)(esp - board);
+	}
+	/* else no change, still multiple overlap */
+}
+
 /*
- * fix up the overlap array due to updating spot osp.
+ * fix up the overlap array according to the changed 'osp'.
  */
 static void
 update_overlap(struct spotstr *osp)
@@ -221,11 +264,13 @@ update_overlap(struct spotstr *osp)
 	int d = dd[r];
 	struct spotstr *sp1 = osp;
 
-	for (int f = 0; f < 6; f++, sp1 -= d) {	/* for each frame */
+	/* for each frame that contains 'osp' */
+	for (int f = 0; f < 6; f++, sp1 -= d) {
 		if (sp1->s_occ == BORDER)
 		break;
 		if ((sp1->s_flags & BFLAG << r) != 0)
 		continue;
+
 		/*
 		 * Update all other frames that intersect the current one
 		 * to indicate whether they still overlap or not.
@@ -242,43 +287,7 @@ update_overlap(struct spotstr *osp)
 		if ((sp2->s_flags & BFLAG << r) != 0)
 			continue;
 
-		/*
-		 * count the number of empty spots to see if there is
-		 * still an overlap.
-		 */
-		int n = 0;
-		struct spotstr *sp = sp1;
-		struct spotstr *esp = NULL;
-		for (int b = i - f; b < 5; b++, sp += d) {
-			if (sp->s_occ == EMPTY) {
-			esp = sp;	/* save the intersection point */
-			n++;
-			}
-		}
-
-		int b = (int)(sp2->s_frame[r] - frames);
-		if (n == 0) {
-			if (sp->s_occ == EMPTY) {
-			overlap[a * FAREA + b] &= 0xA;
-			overlap[b * FAREA + a] &= 0xC;
-			intersect[a * FAREA + b] = (short)(sp - board);
-			intersect[b * FAREA + a] = (short)(sp - board);
-			} else {
-			overlap[a * FAREA + b] = 0;
-			overlap[b * FAREA + a] = 0;
-			}
-		} else if (n == 1) {
-			if (sp->s_occ == EMPTY) {
-			overlap[a * FAREA + b] &= 0xAF;
-			overlap[b * FAREA + a] &= 0xCF;
-			} else {
-			overlap[a * FAREA + b] &= 0xF;
-			overlap[b * FAREA + a] &= 0xF;
-			}
-			intersect[a * FAREA + b] = (short)(esp - board);
-			intersect[b * FAREA + a] = (short)(esp - board);
-		}
-		/* else no change, still multiple overlap */
+		update_overlap_same_direction(sp1, sp2, a, d, i - f, r);
 		}
 
 		/* the other directions can only intersect at spot osp */



CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 05:14:34 UTC 2022

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

Log Message:
gomoku: reduce number of variables in update_overlap

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/games/gomoku/makemove.c

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



CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 05:14:34 UTC 2022

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

Log Message:
gomoku: reduce number of variables in update_overlap

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/games/gomoku/makemove.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/makemove.c
diff -u src/games/gomoku/makemove.c:1.26 src/games/gomoku/makemove.c:1.27
--- src/games/gomoku/makemove.c:1.26	Sat May 28 04:52:23 2022
+++ src/games/gomoku/makemove.c	Sat May 28 05:14:34 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: makemove.c,v 1.26 2022/05/28 04:52:23 rillig Exp $	*/
+/*	$NetBSD: makemove.c,v 1.27 2022/05/28 05:14:34 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)makemove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: makemove.c,v 1.26 2022/05/28 04:52:23 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.27 2022/05/28 05:14:34 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -220,12 +220,11 @@ update_overlap(struct spotstr *osp)
 	for (int r = 4; --r >= 0; ) {		/* for each direction */
 	int d = dd[r];
 	struct spotstr *sp1 = osp;
-	int bmask = BFLAG << r;
 
 	for (int f = 0; f < 6; f++, sp1 -= d) {	/* for each frame */
 		if (sp1->s_occ == BORDER)
 		break;
-		if ((sp1->s_flags & bmask) != 0)
+		if ((sp1->s_flags & BFLAG << r) != 0)
 		continue;
 		/*
 		 * Update all other frames that intersect the current one
@@ -235,13 +234,12 @@ update_overlap(struct spotstr *osp)
 		 * since the two frames can overlap at more than one point.
 		 */
 		int a = (int)(sp1->s_frame[r] - frames);
-		u_char *str = [a * FAREA];
 		struct spotstr *sp2 = sp1 - d;
 
 		for (int i = f + 1; i < 6; i++, sp2 -= d) {
 		if (sp2->s_occ == BORDER)
 			break;
-		if ((sp2->s_flags & bmask) != 0)
+		if ((sp2->s_flags & BFLAG << r) != 0)
 			continue;
 
 		/*
@@ -261,20 +259,20 @@ update_overlap(struct spotstr *osp)
 		int b = (int)(sp2->s_frame[r] - frames);
 		if (n == 0) {
 			if (sp->s_occ == EMPTY) {
-			str[b] &= 0xA;
+			overlap[a * FAREA + b] &= 0xA;
 			overlap[b * FAREA + a] &= 0xC;
 			intersect[a * FAREA + b] = (short)(sp - board);
 			intersect[b * FAREA + a] = (short)(sp - board);
 			} else {
-			str[b] = 0;
+			overlap[a * FAREA + b] = 0;
 			overlap[b * FAREA + a] = 0;
 			}
 		} else if (n == 1) {
 			if (sp->s_occ == EMPTY) {
-			str[b] &= 0xAF;
+			overlap[a * FAREA + b] &= 0xAF;
 			overlap[b * FAREA + a] &= 0xCF;
 			} else {
-			str[b] &= 0xF;
+			overlap[a * FAREA + b] &= 0xF;
 			overlap[b * FAREA + a] &= 0xF;
 			}
 			intersect[a * FAREA + b] = (short)(esp - board);
@@ -286,15 +284,14 @@ update_overlap(struct spotstr *osp)
 		/* the other directions can only intersect at spot osp */
 		for (int r1 = r; --r1 >= 0; ) {
 		int d1 = dd[r1];
-		int bmask1 = BFLAG << r1;
 		struct spotstr *sp = osp;
 		for (int i = 6; --i >= 0; sp -= d1) { /* for each spot */
 			if (sp->s_occ == BORDER)
 			break;
-			if ((sp->s_flags & bmask1) != 0)
+			if ((sp->s_flags & BFLAG << r1) != 0)
 			continue;
 			int b = (int)(sp->s_frame[r1] - frames);
-			str[b] = 0;
+			overlap[a * FAREA + b] = 0;
 			overlap[b * FAREA + a] = 0;
 		}
 		}



CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 04:52:23 UTC 2022

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

Log Message:
gomoku: reduce scope of local variable

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/games/gomoku/makemove.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/makemove.c
diff -u src/games/gomoku/makemove.c:1.25 src/games/gomoku/makemove.c:1.26
--- src/games/gomoku/makemove.c:1.25	Fri May 27 23:29:15 2022
+++ src/games/gomoku/makemove.c	Sat May 28 04:52:23 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: makemove.c,v 1.25 2022/05/27 23:29:15 rillig Exp $	*/
+/*	$NetBSD: makemove.c,v 1.26 2022/05/28 04:52:23 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)makemove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: makemove.c,v 1.25 2022/05/27 23:29:15 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.26 2022/05/28 04:52:23 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -217,7 +217,6 @@ static void
 update_overlap(struct spotstr *osp)
 {
 
-	struct spotstr *esp = NULL;
 	for (int r = 4; --r >= 0; ) {		/* for each direction */
 	int d = dd[r];
 	struct spotstr *sp1 = osp;
@@ -251,12 +250,14 @@ update_overlap(struct spotstr *osp)
 		 */
 		int n = 0;
 		struct spotstr *sp = sp1;
+		struct spotstr *esp = NULL;
 		for (int b = i - f; b < 5; b++, sp += d) {
 			if (sp->s_occ == EMPTY) {
 			esp = sp;	/* save the intersection point */
 			n++;
 			}
 		}
+
 		int b = (int)(sp2->s_frame[r] - frames);
 		if (n == 0) {
 			if (sp->s_occ == EMPTY) {



CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 28 04:52:23 UTC 2022

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

Log Message:
gomoku: reduce scope of local variable

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/games/gomoku/makemove.c

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



CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 27 23:29:16 UTC 2022

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

Log Message:
gomoku: reduce variable reuse, make code more uniform

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/games/gomoku/makemove.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/makemove.c
diff -u src/games/gomoku/makemove.c:1.24 src/games/gomoku/makemove.c:1.25
--- src/games/gomoku/makemove.c:1.24	Fri May 27 23:10:54 2022
+++ src/games/gomoku/makemove.c	Fri May 27 23:29:15 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: makemove.c,v 1.24 2022/05/27 23:10:54 rillig Exp $	*/
+/*	$NetBSD: makemove.c,v 1.25 2022/05/27 23:29:15 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)makemove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: makemove.c,v 1.24 2022/05/27 23:10:54 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.25 2022/05/27 23:29:15 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -101,16 +101,12 @@ makemove(int us, int mv)
 		}
 
 		/* compute old weight value for this frame */
-		union comboval *cp = >s_fval[BLACK][r];
-
-		int val;
-		if (cp->s <= 0x500)
-		val = weight[5 - cp->cv_force - cp->cv_win];
-		else
-		val = 0;
-		cp = >s_fval[WHITE][r];
-		if (cp->s <= 0x500)
-		val += weight[5 - cp->cv_force - cp->cv_win];
+		union comboval cb;
+		int val = 0;
+		if ((cb = fsp->s_fval[BLACK][r]).s <= 0x500)
+		val += weight[5 - cb.cv_force - cb.cv_win];
+		if ((cb = fsp->s_fval[WHITE][r]).s <= 0x500)
+		val += weight[5 - cb.cv_force - cb.cv_win];
 
 		/* compute new combo value for this frame */
 		bool space = fsp->s_occ == EMPTY;
@@ -141,7 +137,7 @@ makemove(int us, int mv)
 
 		/* compute new value & combo number for this frame & color */
 		fsp->s_fval[us != BLACK ? BLACK : WHITE][r].s = 0x600;
-		cp = >s_fval[us][r];
+		union comboval *cp = >s_fval[us][r];
 		/* both ends open? */
 		if (space && sp->s_occ == EMPTY) {
 		cp->cv_force = 4 - n;
@@ -266,8 +262,8 @@ update_overlap(struct spotstr *osp)
 			if (sp->s_occ == EMPTY) {
 			str[b] &= 0xA;
 			overlap[b * FAREA + a] &= 0xC;
-			intersect[a * FAREA + b] = n = (int)(sp - board);
-			intersect[b * FAREA + a] = n;
+			intersect[a * FAREA + b] = (short)(sp - board);
+			intersect[b * FAREA + a] = (short)(sp - board);
 			} else {
 			str[b] = 0;
 			overlap[b * FAREA + a] = 0;
@@ -280,8 +276,8 @@ update_overlap(struct spotstr *osp)
 			str[b] &= 0xF;
 			overlap[b * FAREA + a] &= 0xF;
 			}
-			intersect[a * FAREA + b] = n = (int)(esp - board);
-			intersect[b * FAREA + a] = n;
+			intersect[a * FAREA + b] = (short)(esp - board);
+			intersect[b * FAREA + a] = (short)(esp - board);
 		}
 		/* else no change, still multiple overlap */
 		}



CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 27 23:29:16 UTC 2022

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

Log Message:
gomoku: reduce variable reuse, make code more uniform

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/games/gomoku/makemove.c

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



CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 27 23:10:54 UTC 2022

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

Log Message:
gomoku: reduce scope of local variables

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.23 -r1.24 src/games/gomoku/makemove.c
cvs rdiff -u -r1.45 -r1.46 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.40 src/games/gomoku/gomoku.h:1.41
--- src/games/gomoku/gomoku.h:1.40	Fri May 27 19:59:56 2022
+++ src/games/gomoku/gomoku.h	Fri May 27 23:10:54 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: gomoku.h,v 1.40 2022/05/27 19:59:56 rillig Exp $	*/
+/*	$NetBSD: gomoku.h,v 1.41 2022/05/27 23:10:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -53,11 +53,6 @@
  */
 #define FAREA	(2 * BSZ * (BSZ - 4) + 2 * (BSZ - 4) * (BSZ - 4))
 
-#define MUP	(BSZ + 1)
-#define MDOWN	(-(BSZ + 1))
-#define MLEFT	(-1)
-#define MRIGHT	(1)
-
 /* values for s_occ */
 #define BLACK	0
 #define WHITE	1

Index: src/games/gomoku/makemove.c
diff -u src/games/gomoku/makemove.c:1.23 src/games/gomoku/makemove.c:1.24
--- src/games/gomoku/makemove.c:1.23	Fri May 27 20:48:42 2022
+++ src/games/gomoku/makemove.c	Fri May 27 23:10:54 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: makemove.c,v 1.23 2022/05/27 20:48:42 rillig Exp $	*/
+/*	$NetBSD: makemove.c,v 1.24 2022/05/27 23:10:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,13 +34,16 @@
 
 #include 
 /*	@(#)makemove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: makemove.c,v 1.23 2022/05/27 20:48:42 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.24 2022/05/27 23:10:54 rillig Exp $");
 
 #include "gomoku.h"
 
 		/* direction deltas */
 const int dd[4] = {
-	MRIGHT, MRIGHT+MDOWN, MDOWN, MDOWN+MLEFT
+	1,			/* right */
+	-(BSZ + 1) + 1,		/* down + right */
+	-(BSZ + 1),		/* down */
+	-(BSZ + 1) - 1		/* down + left */
 };
 
 static const int weight[5] = { 0, 1, 7, 22, 100 };
@@ -58,21 +61,13 @@ static void update_overlap(struct spotst
 int
 makemove(int us, int mv)
 {
-	struct spotstr *sp, *fsp;
-	union comboval *cp;
-	struct spotstr *osp;
-	struct combostr *cbp, *cbp1;
-	union comboval *cp1;
-	int d, n;
-	int val, bmask;
-	bool space;
 
 	/* check for end of game */
 	if (mv == RESIGN)
 		return RESIGN;
 
 	/* check for illegal move */
-	sp = [mv];
+	struct spotstr *sp = [mv];
 	if (sp->s_occ != EMPTY)
 		return ILLEGAL;
 
@@ -82,11 +77,12 @@ makemove(int us, int mv)
 
 	/* compute new frame values */
 	sp->s_wval = 0;
-	osp = sp;
+	struct spotstr *osp = sp;
 	for (int r = 4; --r >= 0; ) {		/* for each direction */
-	d = dd[r];
-	fsp = osp;
-	bmask = BFLAG << r;
+	int d = dd[r];
+	struct spotstr *fsp = osp;
+	int bmask = BFLAG << r;
+
 	for (int f = 5; --f >= 0; fsp -= d) {	/* for each frame */
 		if (fsp->s_occ == BORDER)
 		goto nextr;
@@ -94,7 +90,7 @@ makemove(int us, int mv)
 		continue;
 
 		/* remove this frame from the sorted list of frames */
-		cbp = fsp->s_frame[r];
+		struct combostr *cbp = fsp->s_frame[r];
 		if (cbp->c_next != NULL) {
 			if (sortframes[BLACK] == cbp)
 			sortframes[BLACK] = cbp->c_next;
@@ -105,7 +101,9 @@ makemove(int us, int mv)
 		}
 
 		/* compute old weight value for this frame */
-		cp = >s_fval[BLACK][r];
+		union comboval *cp = >s_fval[BLACK][r];
+
+		int val;
 		if (cp->s <= 0x500)
 		val = weight[5 - cp->cv_force - cp->cv_win];
 		else
@@ -115,9 +113,9 @@ makemove(int us, int mv)
 		val += weight[5 - cp->cv_force - cp->cv_win];
 
 		/* compute new combo value for this frame */
+		bool space = fsp->s_occ == EMPTY;
+		int n = 0;
 		sp = fsp;
-		space = sp->s_occ == EMPTY;
-		n = 0;
 		for (int i = 5; --i >= 0; sp += d) {	/* for each spot */
 		if (sp->s_occ == us)
 			n++;
@@ -139,7 +137,7 @@ makemove(int us, int mv)
 
 		/* check for game over */
 		if (n == 5)
-		return(WIN);
+		return WIN;
 
 		/* compute new value & combo number for this frame & color */
 		fsp->s_fval[us != BLACK ? BLACK : WHITE][r].s = 0x600;
@@ -159,11 +157,12 @@ makemove(int us, int mv)
 			sp->s_wval += val;
 
 		/* add this frame to the sorted list of frames by combo value */
-		cbp1 = sortframes[us];
+		struct combostr *cbp1 = sortframes[us];
 		if (cbp1 == NULL)
 		sortframes[us] = cbp->c_next = cbp->c_prev = cbp;
 		else {
-		cp1 = [cbp1->c_vertex].s_fval[us][cbp1->c_dir];
+		union comboval *cp1 =
+			[cbp1->c_vertex].s_fval[us][cbp1->c_dir];
 		if (cp->s <= cp1->s) {
 			/* insert at the head of the list */
 			sortframes[us] = cbp;
@@ -187,7 +186,7 @@ makemove(int us, int mv)
 
 	/* both ends open? */
 	if (fsp->s_occ == EMPTY) {
-		cp = >s_fval[BLACK][r];
+		union comboval *cp = >s_fval[BLACK][r];
 		if (cp->cv_win != 0) {
 		cp->cv_force++;
 		cp->cv_win = 0;
@@ -221,17 

CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 27 23:10:54 UTC 2022

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

Log Message:
gomoku: reduce scope of local variables

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.23 -r1.24 src/games/gomoku/makemove.c
cvs rdiff -u -r1.45 -r1.46 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 27 20:48:43 UTC 2022

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

Log Message:
gomoku: allow Black to win the game in the very last move


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/games/gomoku/makemove.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/makemove.c
diff -u src/games/gomoku/makemove.c:1.22 src/games/gomoku/makemove.c:1.23
--- src/games/gomoku/makemove.c:1.22	Fri May 27 20:35:58 2022
+++ src/games/gomoku/makemove.c	Fri May 27 20:48:42 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: makemove.c,v 1.22 2022/05/27 20:35:58 rillig Exp $	*/
+/*	$NetBSD: makemove.c,v 1.23 2022/05/27 20:48:42 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)makemove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: makemove.c,v 1.22 2022/05/27 20:35:58 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.23 2022/05/27 20:48:42 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -80,36 +80,6 @@ makemove(int us, int mv)
 	sp->s_occ = us;
 	movelog[nmoves++] = mv;
 
-	/*
-	 * FIXME: The last spot on the board can still complete a frame.
-	 *
-	 * Example game: A1 B1 C1 D1 E1 F1 G1 H1 J1 K1 L1 M1 N1 O1 P1 Q1 R1
-	 * S1 T1 A2 B2 C2 D2 E2 F2 G2 H2 J2 K2 L2 M2 N2 O2 P2 Q2 R2 S2 T2 A3
-	 * B3 C3 D3 E3 F3 G3 H3 J3 K3 L3 M3 N3 O3 P3 Q3 R3 S3 T3 A4 B4 C4 D4
-	 * E4 F4 G4 H4 J4 K4 L4 M4 N4 O4 P4 Q4 R4 S4 T4 B5 C5 D5 E5 F5 G5 H5
-	 * J5 K5 L5 M5 N5 O5 P5 Q5 R5 S5 T5 B6 C6 D6 E6 F6 G6 H6 J6 K6 L6 M6
-	 * N6 O6 P6 Q6 R6 S6 T6 B7 C7 D7 E7 F7 G7 H7 J7 K7 L7 M7 N7 O7 P7 Q7
-	 * R7 S7 T7 A8 B8 C8 D8 E8 F8 G8 H8 J8 K8 L8 M8 N8 O8 P8 Q8 R8 S8 T8
-	 * A9 B9 C9 D9 E9 F9 G9 H9 J9 K9 L9 M9 N9 O9 P9 Q9 R9 S9 T9 A10 B10
-	 * C10 D10 E10 F10 G10 H10 J10 K10 L10 M10 N10 O10 P10 Q10 R10 S10
-	 * T10 B11 C11 D11 E11 F11 G11 H11 J11 K11 L11 M11 N11 O11 P11 Q11
-	 * R11 S11 T11 B12 C12 D12 E12 F12 G12 H12 J12 K12 L12 M12 N12 O12
-	 * P12 Q12 R12 S12 T12 B13 C13 D13 E13 F13 G13 H13 J13 K13 L13 M13
-	 * N13 O13 P13 Q13 R13 S13 T13 A14 B14 C14 D14 E14 F14 G14 H14 J14
-	 * K14 L14 M14 N14 O14 P14 Q14 R14 S14 T14 A15 B15 C15 D15 E15 F15
-	 * G15 H15 J15 K15 L15 M15 N15 O15 P15 Q15 R15 S15 T15 A16 B16 C16
-	 * D16 E16 F16 G16 H16 J16 K16 L16 M16 N16 O16 P16 Q16 R16 S16 T16
-	 * B17 C17 D17 E17 F17 G17 H17 J17 K17 L17 M17 N17 O17 P17 Q17 R17
-	 * S17 T17 B18 C18 D18 E18 F18 G18 H18 J18 K18 L18 M18 N18 O18 P18
-	 * Q18 R18 S18 T18 A11 A5 A12 A6 A13 A7 A18 A17 A19 B19 C19 D19 E19
-	 * F19 G19 H19 J19 K19 L19 T19 M19 S19 N19 R19 O19 Q19
-	 *
-	 * Now P19 is the last remaining spot, and when Black plays there,
-	 * the frame L19-P19 is complete.
-	 */
-	if (nmoves == BSZ * BSZ)
-		return TIE;
-
 	/* compute new frame values */
 	sp->s_wval = 0;
 	osp = sp;
@@ -235,6 +205,13 @@ makemove(int us, int mv)
 
 	update_overlap(osp);
 
+	/*
+	 * TODO: Declare a tie as soon as all frames are blocked. This is
+	 *  usually much earlier than when the whole board is filled.
+	 */
+	if (nmoves == BSZ * BSZ)
+		return TIE;
+
 	return MOVEOK;
 }
 



CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 27 20:48:43 UTC 2022

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

Log Message:
gomoku: allow Black to win the game in the very last move


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/games/gomoku/makemove.c

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



CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 27 20:35:58 UTC 2022

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

Log Message:
gomoku: fix off-by-one error when deciding that the game is a tie


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/games/gomoku/makemove.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/makemove.c
diff -u src/games/gomoku/makemove.c:1.21 src/games/gomoku/makemove.c:1.22
--- src/games/gomoku/makemove.c:1.21	Fri May 27 19:59:56 2022
+++ src/games/gomoku/makemove.c	Fri May 27 20:35:58 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: makemove.c,v 1.21 2022/05/27 19:59:56 rillig Exp $	*/
+/*	$NetBSD: makemove.c,v 1.22 2022/05/27 20:35:58 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)makemove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: makemove.c,v 1.21 2022/05/27 19:59:56 rillig Exp $");
+__RCSID("$NetBSD: makemove.c,v 1.22 2022/05/27 20:35:58 rillig Exp $");
 
 #include "gomoku.h"
 
@@ -79,7 +79,35 @@ makemove(int us, int mv)
 	/* make move */
 	sp->s_occ = us;
 	movelog[nmoves++] = mv;
-	if (nmoves + 1 == BSZ * BSZ)	/* FIXME: off-by-one */
+
+	/*
+	 * FIXME: The last spot on the board can still complete a frame.
+	 *
+	 * Example game: A1 B1 C1 D1 E1 F1 G1 H1 J1 K1 L1 M1 N1 O1 P1 Q1 R1
+	 * S1 T1 A2 B2 C2 D2 E2 F2 G2 H2 J2 K2 L2 M2 N2 O2 P2 Q2 R2 S2 T2 A3
+	 * B3 C3 D3 E3 F3 G3 H3 J3 K3 L3 M3 N3 O3 P3 Q3 R3 S3 T3 A4 B4 C4 D4
+	 * E4 F4 G4 H4 J4 K4 L4 M4 N4 O4 P4 Q4 R4 S4 T4 B5 C5 D5 E5 F5 G5 H5
+	 * J5 K5 L5 M5 N5 O5 P5 Q5 R5 S5 T5 B6 C6 D6 E6 F6 G6 H6 J6 K6 L6 M6
+	 * N6 O6 P6 Q6 R6 S6 T6 B7 C7 D7 E7 F7 G7 H7 J7 K7 L7 M7 N7 O7 P7 Q7
+	 * R7 S7 T7 A8 B8 C8 D8 E8 F8 G8 H8 J8 K8 L8 M8 N8 O8 P8 Q8 R8 S8 T8
+	 * A9 B9 C9 D9 E9 F9 G9 H9 J9 K9 L9 M9 N9 O9 P9 Q9 R9 S9 T9 A10 B10
+	 * C10 D10 E10 F10 G10 H10 J10 K10 L10 M10 N10 O10 P10 Q10 R10 S10
+	 * T10 B11 C11 D11 E11 F11 G11 H11 J11 K11 L11 M11 N11 O11 P11 Q11
+	 * R11 S11 T11 B12 C12 D12 E12 F12 G12 H12 J12 K12 L12 M12 N12 O12
+	 * P12 Q12 R12 S12 T12 B13 C13 D13 E13 F13 G13 H13 J13 K13 L13 M13
+	 * N13 O13 P13 Q13 R13 S13 T13 A14 B14 C14 D14 E14 F14 G14 H14 J14
+	 * K14 L14 M14 N14 O14 P14 Q14 R14 S14 T14 A15 B15 C15 D15 E15 F15
+	 * G15 H15 J15 K15 L15 M15 N15 O15 P15 Q15 R15 S15 T15 A16 B16 C16
+	 * D16 E16 F16 G16 H16 J16 K16 L16 M16 N16 O16 P16 Q16 R16 S16 T16
+	 * B17 C17 D17 E17 F17 G17 H17 J17 K17 L17 M17 N17 O17 P17 Q17 R17
+	 * S17 T17 B18 C18 D18 E18 F18 G18 H18 J18 K18 L18 M18 N18 O18 P18
+	 * Q18 R18 S18 T18 A11 A5 A12 A6 A13 A7 A18 A17 A19 B19 C19 D19 E19
+	 * F19 G19 H19 J19 K19 L19 T19 M19 S19 N19 R19 O19 Q19
+	 *
+	 * Now P19 is the last remaining spot, and when Black plays there,
+	 * the frame L19-P19 is complete.
+	 */
+	if (nmoves == BSZ * BSZ)
 		return TIE;
 
 	/* compute new frame values */



CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 27 20:35:58 UTC 2022

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

Log Message:
gomoku: fix off-by-one error when deciding that the game is a tie


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/games/gomoku/makemove.c

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



CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 27 19:59:56 UTC 2022

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

Log Message:
gomoku: replace 1-based movenum with 0-based nmoves

No functional change, not even the TIE that is wrongly announced when
the very last spot on the board is yet to be filled by Black.  Even
without this off-by-one error, it could be that filling the very last
spot completes a frame, so that code has been wrong all the time.

In practical terms, this situation only arises when the human player is
unconcentrated or the computer player has a bad strategy.  The latter
may well be, as the computer moves in the (boring) endgame are not
directed towards winning -- they fill irrelevant spots before relevant
ones.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.46 -r1.47 src/games/gomoku/bdisp.c
cvs rdiff -u -r1.39 -r1.40 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.58 -r1.59 src/games/gomoku/main.c
cvs rdiff -u -r1.20 -r1.21 src/games/gomoku/makemove.c
cvs rdiff -u -r1.44 -r1.45 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 27 19:59:56 UTC 2022

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

Log Message:
gomoku: replace 1-based movenum with 0-based nmoves

No functional change, not even the TIE that is wrongly announced when
the very last spot on the board is yet to be filled by Black.  Even
without this off-by-one error, it could be that filling the very last
spot completes a frame, so that code has been wrong all the time.

In practical terms, this situation only arises when the human player is
unconcentrated or the computer player has a bad strategy.  The latter
may well be, as the computer moves in the (boring) endgame are not
directed towards winning -- they fill irrelevant spots before relevant
ones.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/games/gomoku/bdinit.c
cvs rdiff -u -r1.46 -r1.47 src/games/gomoku/bdisp.c
cvs rdiff -u -r1.39 -r1.40 src/games/gomoku/gomoku.h
cvs rdiff -u -r1.58 -r1.59 src/games/gomoku/main.c
cvs rdiff -u -r1.20 -r1.21 src/games/gomoku/makemove.c
cvs rdiff -u -r1.44 -r1.45 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/bdinit.c
diff -u src/games/gomoku/bdinit.c:1.21 src/games/gomoku/bdinit.c:1.22
--- src/games/gomoku/bdinit.c:1.21	Sat May 21 16:39:14 2022
+++ src/games/gomoku/bdinit.c	Fri May 27 19:59:56 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdinit.c,v 1.21 2022/05/21 16:39:14 rillig Exp $	*/
+/*	$NetBSD: bdinit.c,v 1.22 2022/05/27 19:59:56 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	from: @(#)bdinit.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdinit.c,v 1.21 2022/05/21 16:39:14 rillig Exp $");
+__RCSID("$NetBSD: bdinit.c,v 1.22 2022/05/27 19:59:56 rillig Exp $");
 
 #include 
 #include "gomoku.h"
@@ -47,7 +47,7 @@ bdinit(struct spotstr *bp)
 	struct spotstr *sp;
 	struct combostr *cbp;
 
-	movenum = 1;
+	nmoves = 0;
 
 	/* mark the borders as such */
 	sp = bp;

Index: src/games/gomoku/bdisp.c
diff -u src/games/gomoku/bdisp.c:1.46 src/games/gomoku/bdisp.c:1.47
--- src/games/gomoku/bdisp.c:1.46	Sun May 22 13:38:08 2022
+++ src/games/gomoku/bdisp.c	Fri May 27 19:59:56 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bdisp.c,v 1.46 2022/05/22 13:38:08 rillig Exp $	*/
+/*	$NetBSD: bdisp.c,v 1.47 2022/05/27 19:59:56 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)bdisp.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: bdisp.c,v 1.46 2022/05/22 13:38:08 rillig Exp $");
+__RCSID("$NetBSD: bdisp.c,v 1.47 2022/05/27 19:59:56 rillig Exp $");
 
 #include 
 #include 
@@ -171,7 +171,7 @@ bdisp(void)
 c = pcolor[sp->s_occ];
 
 			move(scr_y(j), scr_x(i));
-			if (movenum > 1 && movelog[movenum - 2] == PT(i, j)) {
+			if (nmoves > 0 && movelog[nmoves - 1] == PT(i, j)) {
 attron(A_BOLD);
 addch(c);
 attroff(A_BOLD);

Index: src/games/gomoku/gomoku.h
diff -u src/games/gomoku/gomoku.h:1.39 src/games/gomoku/gomoku.h:1.40
--- src/games/gomoku/gomoku.h:1.39	Sun May 22 10:45:02 2022
+++ src/games/gomoku/gomoku.h	Fri May 27 19:59:56 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: gomoku.h,v 1.39 2022/05/22 10:45:02 rillig Exp $	*/
+/*	$NetBSD: gomoku.h,v 1.40 2022/05/27 19:59:56 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -229,8 +229,8 @@ extern	struct	combostr frames[FAREA];		/
 extern	struct	combostr *sortframes[2];	/* sorted, non-empty frames */
 extern	u_char	overlap[FAREA * FAREA];		/* frame [a][b] overlap */
 extern	short	intersect[FAREA * FAREA];	/* frame [a][b] intersection */
-extern	int	movelog[BSZ * BSZ];		/* history of moves */
-extern	int	movenum;
+extern	int	movelog[BSZ * BSZ];
+extern	unsigned int nmoves;
 extern	int	debug;
 
 extern bool interactive;

Index: src/games/gomoku/main.c
diff -u src/games/gomoku/main.c:1.58 src/games/gomoku/main.c:1.59
--- src/games/gomoku/main.c:1.58	Sun May 22 09:17:15 2022
+++ src/games/gomoku/main.c	Fri May 27 19:59:56 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.58 2022/05/22 09:17:15 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.59 2022/05/27 19:59:56 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.58 2022/05/22 09:17:15 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.59 2022/05/27 19:59:56 rillig Exp $");
 
 #include 
 #include 
@@ -78,8 +78,8 @@ struct	combostr frames[FAREA];		/* stora
 struct	combostr *sortframes[2];	/* sorted list of non-empty frames */
 u_char	overlap[FAREA * FAREA];		/* true if frame [a][b] overlap */
 short	intersect[FAREA * FAREA];	/* frame [a][b] intersection */
-int	movelog[BSZ * BSZ];		/* log of all the moves */
-int	movenum;			/* current move number */
+int	movelog[BSZ * BSZ];		/* log of all played moves */

CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 27 19:30:56 UTC 2022

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

Log Message:
gomoku: split local variable into separate variables

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/games/gomoku/pickmove.c

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



CVS commit: src/games/gomoku

2022-05-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 27 19:30:56 UTC 2022

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

Log Message:
gomoku: split local variable into separate variables

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 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/pickmove.c
diff -u src/games/gomoku/pickmove.c:1.43 src/games/gomoku/pickmove.c:1.44
--- src/games/gomoku/pickmove.c:1.43	Sun May 22 10:45:02 2022
+++ src/games/gomoku/pickmove.c	Fri May 27 19:30:56 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: pickmove.c,v 1.43 2022/05/22 10:45:02 rillig Exp $	*/
+/*	$NetBSD: pickmove.c,v 1.44 2022/05/27 19:30:56 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994
@@ -34,7 +34,7 @@
 
 #include 
 /*	@(#)pickmove.c	8.2 (Berkeley) 5/3/95	*/
-__RCSID("$NetBSD: pickmove.c,v 1.43 2022/05/22 10:45:02 rillig Exp $");
+__RCSID("$NetBSD: pickmove.c,v 1.44 2022/05/27 19:30:56 rillig Exp $");
 
 #include 
 #include 
@@ -232,7 +232,7 @@ scanframes(int color)
 	struct spotstr *sp;
 	union comboval *cp;
 	struct elist *nep;
-	int i, r, d, n;
+	int i, r, n;
 	union comboval cb;
 
 	curcolor = color;
@@ -249,10 +249,10 @@ scanframes(int color)
 	 *  winning moves J12 and J7.
 	 */
 	sp = [cbp->c_vertex];
-	cb.s = sp->s_fval[color][d = cbp->c_dir].s;
+	cb.s = sp->s_fval[color][cbp->c_dir].s;
 	if (cb.s < 0x101) {
-		d = dd[d];
-		for (i = 5 + cb.cv_win; --i >= 0; sp += d) {
+		int delta = dd[cbp->c_dir];
+		for (i = 5 + cb.cv_win; --i >= 0; sp += delta) {
 			if (sp->s_occ != EMPTY)
 continue;
 			sp->s_combo[color].s = cb.s;
@@ -271,7 +271,7 @@ scanframes(int color)
 	do {
 		sp = [cbp->c_vertex];
 		cp = >s_fval[color][r = cbp->c_dir];
-		d = dd[r];
+		int delta = dd[r];
 		if (cp->cv_win != 0) {
 			/*
 			 * Since this is the first spot of an open-ended
@@ -292,13 +292,13 @@ scanframes(int color)
 cb.s = cp->s;
 			else if (color != nextcolor)
 memset(tmpmap, 0, sizeof(tmpmap));
-			sp += d;
+			sp += delta;
 			i = 1;
 		} else {
 			cb.s = cp->s;
 			i = 0;
 		}
-		for (; i < 5; i++, sp += d) {	/* for each spot */
+		for (; i < 5; i++, sp += delta) {	/* for each spot */
 			if (sp->s_occ != EMPTY)
 continue;
 			if (cp->s < sp->s_combo[color].s) {
@@ -334,19 +334,18 @@ scanframes(int color)
 	 * Try to make new 3rd level combos, 4th level, etc.
 	 * Limit the search depth early in the game.
 	 */
-	d = 2;
 	/* LINTED 117: bitwise '>>' on signed value possibly nonportable */
-	while (d <= ((movenum + 1) >> 1) && combolen > n) {
-		if (d >= 9)
+	for (int level = 2;
+	 level <= ((movenum + 1) >> 1) && combolen > n; level++) {
+		if (level >= 9)
 			break;	/* Do not think too long. */
 		if (debug != 0) {
 			debuglog("%cL%d %d %d %d", "BW"[color],
-			d, combolen - n, combocnt, elistcnt);
+			level, combolen - n, combocnt, elistcnt);
 			refresh();
 		}
 		n = combolen;
-		addframes(d);
-		d++;
+		addframes(level);
 	}
 
 	/* scan for combos at empty spots */



  1   2   3   >