diff --git a/games/gomoku/bdinit.c b/games/gomoku/bdinit.c index bb8f827803bf..bc11cef86177 100644 --- a/games/gomoku/bdinit.c +++ b/games/gomoku/bdinit.c @@ -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; diff --git a/games/gomoku/bdisp.c b/games/gomoku/bdisp.c index 2a9dc778423b..019c55635c7c 100644 --- a/games/gomoku/bdisp.c +++ b/games/gomoku/bdisp.c @@ -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); diff --git a/games/gomoku/gomoku.h b/games/gomoku/gomoku.h index 3f90f7e8515d..43159fd69045 100644 --- a/games/gomoku/gomoku.h +++ b/games/gomoku/gomoku.h @@ -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[]; diff --git a/games/gomoku/makemove.c b/games/gomoku/makemove.c index 2f38a9d1b1a9..604919e3bb97 100644 --- a/games/gomoku/makemove.c +++ b/games/gomoku/makemove.c @@ -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;