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 <sys/cdefs.h>
/* 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 <string.h>
#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 <sys/cdefs.h>
/* @(#)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 <curses.h>
#include <string.h>
@@ -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 <sys/cdefs.h>
/* @(#)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;