Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games/gomoku gomoku: when starting a new game, start in the ...



details:   https://anonhg.NetBSD.org/src/rev/6bd4d2491b9c
branches:  trunk
changeset: 366522:6bd4d2491b9c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun May 29 16:30:44 2022 +0000

description:
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.

diffstat:

 games/gomoku/bdinit.c |  6 ++++--
 games/gomoku/bdisp.c  |  9 +++++----
 games/gomoku/gomoku.h |  4 +++-
 3 files changed, 12 insertions(+), 7 deletions(-)

diffs (82 lines):

diff -r a0b0d1e63683 -r 6bd4d2491b9c games/gomoku/bdinit.c
--- a/games/gomoku/bdinit.c     Sun May 29 16:19:52 2022 +0000
+++ b/games/gomoku/bdinit.c     Sun May 29 16:30:44 2022 +0000
@@ -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 <sys/cdefs.h>
 /*     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 <string.h>
 #include "gomoku.h"
@@ -130,6 +130,8 @@
 
        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++) {
diff -r a0b0d1e63683 -r 6bd4d2491b9c games/gomoku/bdisp.c
--- a/games/gomoku/bdisp.c      Sun May 29 16:19:52 2022 +0000
+++ b/games/gomoku/bdisp.c      Sun May 29 16:30:44 2022 +0000
@@ -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 <sys/cdefs.h>
 /*     @(#)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 <curses.h>
 #include <string.h>
@@ -355,8 +355,7 @@
 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 @@
                case '\r':
                selected:
                        (void)mvhline(BSZ + 3, 6, ' ', 6);
+                       game.user_x = x;
+                       game.user_y = y;
                        return PT(x, y);
                }
 
diff -r a0b0d1e63683 -r 6bd4d2491b9c games/gomoku/gomoku.h
--- a/games/gomoku/gomoku.h     Sun May 29 16:19:52 2022 +0000
+++ b/games/gomoku/gomoku.h     Sun May 29 16:30:44 2022 +0000
@@ -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 @@
        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[];



Home | Main Index | Thread Index | Old Index