Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/games/gomoku gomoku: highlight the winning frame
details: https://anonhg.NetBSD.org/src/rev/9198fcd47b64
branches: trunk
changeset: 366465:9198fcd47b64
user: rillig <rillig%NetBSD.org@localhost>
date: Sat May 28 08:32:55 2022 +0000
description:
gomoku: highlight the winning frame
diffstat:
games/gomoku/bdinit.c | 5 +++--
games/gomoku/bdisp.c | 20 ++++++++++++++++----
games/gomoku/gomoku.h | 4 +++-
games/gomoku/makemove.c | 9 ++++++---
4 files changed, 28 insertions(+), 10 deletions(-)
diffs (123 lines):
diff -r 4c3e87132c4f -r 9198fcd47b64 games/gomoku/bdinit.c
--- a/games/gomoku/bdinit.c Sat May 28 08:19:18 2022 +0000
+++ b/games/gomoku/bdinit.c Sat May 28 08:32:55 2022 +0000
@@ -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 @@
struct combostr *cbp;
game.nmoves = 0;
+ game.winning_spot = 0;
/* mark the borders as such */
sp = bp;
diff -r 4c3e87132c4f -r 9198fcd47b64 games/gomoku/bdisp.c
--- a/games/gomoku/bdisp.c Sat May 28 08:19:18 2022 +0000
+++ b/games/gomoku/bdisp.c Sat May 28 08:32:55 2022 +0000
@@ -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 @@
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 @@
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);
diff -r 4c3e87132c4f -r 9198fcd47b64 games/gomoku/gomoku.h
--- a/games/gomoku/gomoku.h Sat May 28 08:19:18 2022 +0000
+++ b/games/gomoku/gomoku.h Sat May 28 08:32:55 2022 +0000
@@ -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 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[];
diff -r 4c3e87132c4f -r 9198fcd47b64 games/gomoku/makemove.c
--- a/games/gomoku/makemove.c Sat May 28 08:19:18 2022 +0000
+++ b/games/gomoku/makemove.c Sat May 28 08:32:55 2022 +0000
@@ -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 @@
}
/* 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;
Home |
Main Index |
Thread Index |
Old Index