Source-Changes-HG archive

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

[src/trunk]: src/games/gomoku gomoku: use combined curses functions



details:   https://anonhg.NetBSD.org/src/rev/0a5c6b7d4c48
branches:  trunk
changeset: 366245:0a5c6b7d4c48
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu May 19 22:49:05 2022 +0000

description:
gomoku: use combined curses functions

To save some screen space in the source code and some bytes in the
generated binary.

No functional change.

diffstat:

 games/gomoku/bdisp.c |  45 ++++++++++++++++++---------------------------
 games/gomoku/main.c  |   7 +++----
 2 files changed, 21 insertions(+), 31 deletions(-)

diffs (144 lines):

diff -r 7cf1ac15b716 -r 0a5c6b7d4c48 games/gomoku/bdisp.c
--- a/games/gomoku/bdisp.c      Thu May 19 22:29:36 2022 +0000
+++ b/games/gomoku/bdisp.c      Thu May 19 22:49:05 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bdisp.c,v 1.35 2022/05/19 22:24:54 rillig Exp $        */
+/*     $NetBSD: bdisp.c,v 1.36 2022/05/19 22:49:05 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.35 2022/05/19 22:24:54 rillig Exp $");
+__RCSID("$NetBSD: bdisp.c,v 1.36 2022/05/19 22:49:05 rillig Exp $");
 
 #include <curses.h>
 #include <string.h>
@@ -97,26 +97,20 @@
 bdisp_init(void)
 {
 
-       /* top border */
+       /* top and bottom borders */
        for (int i = 1; i < BSZ + 1; i++) {
-               move(scr_y(BSZ + 1), scr_x(i));
-               addch(letters[i]);
+               mvaddch(scr_y(BSZ + 1), scr_x(i), letters[i]);
+               mvaddch(scr_y(0), scr_x(i), letters[i]);
        }
+
        /* left and right edges */
        for (int j = BSZ + 1; --j > 0; ) {
-               move(scr_y(j), 0);
-               printw("%2d ", j);
-               move(scr_y(j), scr_x(BSZ) + 2);
-               printw("%d ", j);
+               mvprintw(scr_y(j), 0, "%2d ", j);
+               mvprintw(scr_y(j), scr_x(BSZ) + 2, "%d ", j);
        }
-       /* bottom border */
-       for (int i = 1; i < BSZ + 1; i++) {
-               move(scr_y(0), scr_x(i));
-               addch(letters[i]);
-       }
+
        bdwho(false);
-       move(0, TRANSCRIPT_COL + 1);
-       addstr("#  black  white");
+       mvaddstr(0, TRANSCRIPT_COL + 1, "#  black  white");
        lastline = 0;
        bdisp();
 }
@@ -133,12 +127,11 @@
        int fixed = (int)sizeof("BLACK/ (*) vs. WHITE/ (O)") - 1;
        int total = fixed + bw + ww;
 
-       move(BSZ + 2, 0);
-       hline(' ', available);
+       mvhline(BSZ + 2, 0, ' ', available);
 
        if (total <= available) {
-               move(BSZ + 2, (available - total) / 2);
-               printw("BLACK/%s (*) vs. WHITE/%s (O)",
+               mvprintw(BSZ + 2, (available - total) / 2,
+                   "BLACK/%s (*) vs. WHITE/%s (O)",
                    plyr[BLACK], plyr[WHITE]);
        } else {
                int remaining = available - fixed;
@@ -151,8 +144,7 @@
                else
                        bw = half, ww = remaining - half;
 
-               move(BSZ + 2, 0);
-               printw("BLACK/%.*s (*) vs. WHITE/%.*s (O)",
+               mvprintw(BSZ + 2, 0, "BLACK/%.*s (*) vs. WHITE/%.*s (O)",
                    bw, plyr[BLACK], ww, plyr[WHITE]);
        }
        if (update)
@@ -170,7 +162,6 @@
 
        for (int j = BSZ + 1; --j > 0; ) {
                for (int i = 1; i < BSZ + 1; i++) {
-                       move(scr_y(j), scr_x(i));
                        sp = &board[i + j * (BSZ + 1)];
                        if (debug > 1 && sp->s_occ == EMPTY) {
                                if ((sp->s_flags & IFLAGALL) != 0)
@@ -181,6 +172,8 @@
                                        c = '.';
                        } else
                                c = pcolor[sp->s_occ];
+
+                       move(scr_y(j), scr_x(i));
                        if (movenum > 1 && movelog[movenum - 2] == PT(i, j)) {
                                attron(A_BOLD);
                                addch(c);
@@ -242,8 +235,7 @@
                /* move 'em up */
                lastline = 1;
        }
-       move(lastline, TRANSCRIPT_COL);
-       addnstr(str, SCRNW - TRANSCRIPT_COL - 1);
+       mvaddnstr(lastline, TRANSCRIPT_COL, str, SCRNW - TRANSCRIPT_COL - 1);
        clrtoeol();
        move(lastline + 1, TRANSCRIPT_COL);
        clrtoeol();
@@ -258,8 +250,7 @@
 {
        int len = (int)strlen(str);
 
-       move(BSZ + 4, 0);
-       addstr(str);
+       mvaddstr(BSZ + 4, 0, str);
        clrtoeol();
        move(BSZ + 4, len);
        refresh();
diff -r 7cf1ac15b716 -r 0a5c6b7d4c48 games/gomoku/main.c
--- a/games/gomoku/main.c       Thu May 19 22:29:36 2022 +0000
+++ b/games/gomoku/main.c       Thu May 19 22:49:05 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.41 2022/05/19 22:19:18 rillig Exp $ */
+/*     $NetBSD: main.c,v 1.42 2022/05/19 22:49:05 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.41 2022/05/19 22:19:18 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.42 2022/05/19 22:49:05 rillig Exp $");
 
 #include <curses.h>
 #include <err.h>
@@ -157,8 +157,7 @@
 #endif
 
                if (inputfp == NULL && test == 0) {
-                       move(BSZ + 3, 0);
-                       printw("Black moves first. ");
+                       mvprintw(BSZ + 3, 0, "Black moves first. ");
                        ask("(B)lack or (W)hite? ");
                        for (;;) {
                                ch = get_key(NULL);



Home | Main Index | Thread Index | Old Index