summaryrefslogtreecommitdiffstats
path: root/games/boggle
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2008-03-20 12:02:27 +0000
committermillert <millert@openbsd.org>2008-03-20 12:02:27 +0000
commitf234f5d5b6343e6eaf2ee23a7b0546ad29e86cf3 (patch)
treefd6a99cdbb6221f011aaa3a2ddfcd17326426b70 /games/boggle
parentFix HISTORY. OK reyk@ (diff)
downloadwireguard-openbsd-f234f5d5b6343e6eaf2ee23a7b0546ad29e86cf3.tar.xz
wireguard-openbsd-f234f5d5b6343e6eaf2ee23a7b0546ad29e86cf3.zip
Make the bog code generic enough to handle arbitrary NxN grids and
add cubes for 5x5 mode based on Boggle Deluxe (aka Big Boggle) as well as support for the "challenge cube" shipped with some versions of Boggle. Also Dynamically allocate record keeping structures so we can deal with large word lists and add a --More-- prompt for when there are too many wwords found by the computer to fit on the terminal. OK deraadt@
Diffstat (limited to 'games/boggle')
-rw-r--r--games/boggle/boggle/bog.c278
-rw-r--r--games/boggle/boggle/bog.h24
-rw-r--r--games/boggle/boggle/boggle.621
-rw-r--r--games/boggle/boggle/mach.c90
-rw-r--r--games/boggle/boggle/prtable.c20
-rw-r--r--games/boggle/boggle/timer.c6
6 files changed, 299 insertions, 140 deletions
diff --git a/games/boggle/boggle/bog.c b/games/boggle/boggle/bog.c
index 19008281675..996fd0e1783 100644
--- a/games/boggle/boggle/bog.c
+++ b/games/boggle/boggle/bog.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bog.c,v 1.16 2008/03/17 09:17:56 sobrado Exp $ */
+/* $OpenBSD: bog.c,v 1.17 2008/03/20 12:02:27 millert Exp $ */
/* $NetBSD: bog.c,v 1.5 1995/04/24 12:22:32 cgd Exp $ */
/*-
@@ -43,12 +43,13 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)bog.c 8.1 (Berkeley) 6/11/93";
#else
-static char rcsid[] = "$OpenBSD: bog.c,v 1.16 2008/03/17 09:17:56 sobrado Exp $";
+static char rcsid[] = "$OpenBSD: bog.c,v 1.17 2008/03/20 12:02:27 millert Exp $";
#endif
#endif /* not lint */
#include <ctype.h>
#include <err.h>
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -58,50 +59,26 @@ static char rcsid[] = "$OpenBSD: bog.c,v 1.16 2008/03/17 09:17:56 sobrado Exp $"
#include "bog.h"
#include "extern.h"
+static void init(void);
+static void init_adjacencies(void);
static int compar(const void *, const void *);
struct dictindex dictindex[26];
-/*
- * Cube position numbering:
- *
- * 0 1 2 3
- * 4 5 6 7
- * 8 9 A B
- * C D E F
- */
-static int adjacency[16][16] = {
-/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
- { 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* 0 */
- { 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* 1 */
- { 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, /* 2 */
- { 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, /* 3 */
- { 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 }, /* 4 */
- { 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0 }, /* 5 */
- { 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 }, /* 6 */
- { 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0 }, /* 7 */
- { 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0 }, /* 8 */
- { 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0 }, /* 9 */
- { 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1 }, /* A */
- { 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1 }, /* B */
- { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0 }, /* C */
- { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0 }, /* D */
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1 }, /* E */
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0 } /* F */
-};
-
-static int letter_map[26][16];
-
-char board[17];
+static int **adjacency, **letter_map;
+
+char *board;
int wordpath[MAXWORDLEN + 1];
int wordlen; /* Length of last word returned by nextword() */
int usedbits;
+int ncubes;
+int grid = 4;
-char *pword[MAXPWORDS], pwords[MAXPSPACE], *pwordsp;
-int npwords;
+char **pword, *pwords, *pwordsp;
+int npwords, maxpwords = MAXPWORDS, maxpspace = MAXPSPACE;
-char *mword[MAXMWORDS], mwords[MAXMSPACE], *mwordsp;
-int nmwords;
+char **mword, *mwords, *mwordsp;
+int nmwords, maxmwords = MAXMWORDS, maxmspace = MAXMSPACE;
int ngames = 0;
int tnmwords = 0, tnpwords = 0;
@@ -114,6 +91,7 @@ time_t start_t;
static FILE *dictfp;
int batch;
+int challenge;
int debug;
int minlength;
int reuse;
@@ -123,19 +101,25 @@ int tlimit;
int
main(int argc, char *argv[])
{
- int ch, done, i;
+ int ch, done;
char *bspec, *p, *seed;
batch = debug = reuse = selfuse;
bspec = seed = NULL;
- minlength = 3;
+ minlength = -1;
tlimit = 180; /* 3 minutes is standard */
- while ((ch = getopt(argc, argv, "bds:t:w:")) != -1)
+ while ((ch = getopt(argc, argv, "Bbcds:t:w:")) != -1)
switch(ch) {
+ case 'B':
+ grid = 5;
+ break;
case 'b':
batch = 1;
break;
+ case 'c':
+ challenge = 1;
+ break;
case 'd':
debug = 1;
break;
@@ -172,7 +156,7 @@ main(int argc, char *argv[])
if (argc > 0) {
if (islower(argv[0][0])) {
- if (strlen(argv[0]) != 16) {
+ if (strlen(argv[0]) != ncubes) {
usage();
} else {
/* This board is assumed to be valid... */
@@ -186,15 +170,12 @@ main(int argc, char *argv[])
if (batch && bspec == NULL)
errx(1, "must give both -b and a board setup");
- if (selfuse)
- for (i = 0; i < 16; i++)
- adjacency[i][i] = 1;
-
+ init();
if (batch) {
newgame(bspec);
while ((p = batchword(stdin)) != NULL)
(void) printf("%s\n", p);
- exit (0);
+ exit(0);
}
setup(seed);
prompt("Loading the dictionary...");
@@ -226,7 +207,7 @@ main(int argc, char *argv[])
bspec = NULL; /* reset for subsequent games */
playgame();
prompt("Type <space> to continue, any cap to quit...");
- delay(50); /* wait for user to quit typing */
+ delay(10); /* wait for user to quit typing */
flushin(stdin);
for (;;) {
ch = inputch();
@@ -245,7 +226,7 @@ main(int argc, char *argv[])
}
}
cleanup();
- exit (0);
+ exit(0);
}
/*
@@ -358,16 +339,26 @@ playgame(void)
else {
int len;
+ if (npwords == maxpwords - 1) {
+ maxpwords += MAXPWORDS;
+ pword = recalloc(pword,
+ maxpwords, sizeof(char *));
+ if (pword == NULL) {
+ cleanup();
+ errx(1, strerror(ENOMEM));
+ }
+ }
len = strlen(buf) + 1;
- if (npwords == MAXPWORDS - 1 ||
- pwordsp + len >= &pwords[MAXPSPACE]) {
- warnx("Too many words!");
- cleanup();
- exit(1);
+ if (pwordsp + len >= &pwords[maxpspace]) {
+ maxpspace += MAXPSPACE;
+ pwords = realloc(pwords, maxpspace);
+ if (pwords == NULL) {
+ cleanup();
+ errx(1, strerror(ENOMEM));
+ }
}
pword[npwords++] = pwordsp;
- strlcpy(pwordsp, buf,
- pwords + sizeof pwords - pwordsp);
+ memcpy(pwordsp, buf, len);
pwordsp += len;
addword(buf);
}
@@ -491,9 +482,8 @@ validword(char *word)
j = word[0] - 'a';
if (dictseek(dictfp, dictindex[j].start, SEEK_SET) < 0) {
- (void) fprintf(stderr, "Seek error\n");
cleanup();
- exit(1);
+ errx(1, "seek error in validword()");
}
while ((w = nextword(dictfp)) != NULL) {
@@ -520,7 +510,7 @@ validword(char *word)
void
checkdict(void)
{
- char *p, **pw, *w;
+ char **pw, *w;
int i;
int prevch, previndex, *pi, *qi, st;
@@ -558,9 +548,8 @@ checkdict(void)
if (i != previndex + 1) {
if (dictseek(dictfp,
dictindex[i].start, SEEK_SET) < 0) {
- warnx("seek error in checkdict()");
cleanup();
- exit(1);
+ errx(1, "seek error in checkdict()");
}
continue;
}
@@ -578,15 +567,25 @@ checkdict(void)
pw++;
if (st == 0) /* found it */
continue;
- if (nmwords == MAXMWORDS ||
- mwordsp + wordlen + 1 >= &mwords[MAXMSPACE]) {
- warnx("too many words!");
- cleanup();
- exit(1);
+ if (nmwords == maxmwords - 1) {
+ maxmwords += MAXMWORDS;
+ mword = recalloc(mword, maxmwords, sizeof(char *));
+ if (mword == NULL) {
+ cleanup();
+ errx(1, strerror(ENOMEM));
+ }
+ }
+ if (mwordsp + wordlen + 1 >= &mwords[maxmspace]) {
+ maxmspace += MAXMSPACE;
+ mwords = realloc(mwords, maxmspace);
+ if (mwords == NULL) {
+ cleanup();
+ errx(1, strerror(ENOMEM));
+ }
}
mword[nmwords++] = mwordsp;
- p = w;
- while ((*mwordsp++ = *p++));
+ memcpy(mwordsp, w, wordlen + 1);
+ mwordsp += wordlen + 1;
}
}
@@ -599,40 +598,51 @@ void
newgame(char *b)
{
int i, p, q;
- char *tmp;
+ char *tmp, **cubes;
int *lm[26];
- static char *cubes[16] = {
+ char chal_cube[] = "iklmqu"; /* challenge cube */
+ static char *cubes4[] = {
"ednosw", "aaciot", "acelrs", "ehinps",
"eefhiy", "elpstu", "acdemp", "gilruw",
"egkluy", "ahmors", "abilty", "adenvz",
"bfiorx", "dknotu", "abjmoq", "egintv"
};
+ static char *cubes5[] = {
+ "aaafrs", "aaeeee", "aafirs", "adennn", "aeeeem",
+ "aeegmu", "aegmnn", "afirsy", "bjkqxz", "ccnstw",
+ "ceiilt", "ceilpt", "ceipst", "ddlnor", "dhhlor",
+ "dhhnot", "dhlnor", "eiiitt", "emottt", "ensssu",
+ "fiprsy", "gorrvw", "hiprry", "nootuw", "ooottu"
+ };
+ cubes = grid == 4 ? cubes4 : cubes5;
if (b == NULL) {
- /*
- * Shake the cubes and make the board
- */
- i = 0;
- while (i < 100) {
- p = (int) (random() % 16);
- q = (int) (random() % 16);
- if (p != q) {
- tmp = cubes[p];
- cubes[p] = cubes[q];
- cubes[q] = tmp;
- i++;
- }
- /* else try again */
+ /* Shuffle the cubes using Fisher-Yates (aka Knuth P). */
+ p = ncubes;
+ while (--p) {
+ q = (int)random() % (p + 1);
+ tmp = cubes[p];
+ cubes[p] = cubes[q];
+ cubes[q] = tmp;
}
- for (i = 0; i < 16; i++)
+ /* Build the board by rolling each cube. */
+ for (i = 0; i < ncubes; i++)
board[i] = cubes[i][random() % 6];
- }
- else {
- for (i = 0; i < 16; i++)
+
+ /*
+ * For challenge mode, roll chal_cube and replace a random
+ * cube with its value. Set the high bit to distinguish it.
+ */
+ if (challenge) {
+ i = random() % ncubes;
+ board[i] = SETHI(chal_cube[random() % 6]);
+ }
+ } else {
+ for (i = 0; i < ncubes; i++)
board[i] = b[i];
}
- board[16] = '\0';
+ board[ncubes] = '\0';
/*
* Set up the map from letter to location(s)
@@ -643,10 +653,10 @@ newgame(char *b)
*lm[i] = -1;
}
- for (i = 0; i < 16; i++) {
+ for (i = 0; i < ncubes; i++) {
int j;
- j = (int) (board[i] - 'a');
+ j = (int) (SEVENBIT(board[i]) - 'a');
*lm[j] = i;
*(++lm[j]) = -1;
}
@@ -664,19 +674,103 @@ newgame(char *b)
}
-int
+static int
compar(const void *p, const void *q)
{
return (strcmp(*(char **)p, *(char **)q));
}
+/*
+ * Allocate and initialize datga structures.
+ */
+static void
+init(void)
+{
+ int i;
+
+ ncubes = grid * grid;
+ if (minlength == -1)
+ minlength = grid - 1;
+ init_adjacencies();
+ board = malloc(ncubes + 1);
+ if (board == NULL)
+ err(1, NULL);
+ letter_map = calloc(26, sizeof(int *));
+ if (letter_map == NULL)
+ err(1, NULL);
+ for (i = 0; i < 26; i++) {
+ letter_map[i] = calloc(ncubes, sizeof(int));
+ if (letter_map[i] == NULL)
+ err(1, NULL);
+ }
+ pword = calloc(maxpwords, sizeof(char *));
+ if (pword == NULL)
+ err(1, NULL);
+ pwords = malloc(maxpspace);
+ if (pwords == NULL)
+ err(1, NULL);
+ mword = calloc(maxmwords, sizeof(char *));
+ if (mword == NULL)
+ err(1, NULL);
+ mwords = malloc(maxmspace);
+ if (mwords == NULL)
+ err(1, NULL);
+}
+
+#define SET_ADJ(r) do { \
+ if (col > 0) \
+ adj[r - 1] = 1; \
+ adj[r] = 1; \
+ if (col + 1 < grid) \
+ adj[r + 1] = 1; \
+} while(0)
+
+/*
+ * Compute adjacency matrix for the grid
+ */
+static void
+init_adjacencies(void)
+{
+ int cube, row, col, *adj;
+
+ adjacency = calloc(ncubes, sizeof(int *));
+ if (adjacency == NULL)
+ err(1, NULL);
+
+ /*
+ * Fill in adjacencies. This is an ncubes x ncubes matrix where
+ * the position X,Y is set to 1 if cubes X and Y are adjacent.
+ */
+ for (cube = 0; cube < ncubes; cube++) {
+ adj = adjacency[cube] = calloc(ncubes, sizeof(int));
+ if (adj == NULL)
+ err(1, NULL);
+
+ row = cube / grid;
+ col = cube % grid;
+
+ /* this row */
+ SET_ADJ(cube);
+ if (!selfuse)
+ adj[cube] = 0;
+
+ /* prev row */
+ if (row > 0)
+ SET_ADJ(cube - grid);
+
+ /* next row */
+ if (row + 1 < grid)
+ SET_ADJ(cube + grid);
+ }
+}
+
void
usage(void)
{
extern char *__progname;
(void) fprintf(stderr, "usage: "
- "%s [-bd] [-s seed] [-t time] [-w length] [+[+]] [boardspec]\n",
+ "%s [-Bbcd] [-s seed] [-t time] [-w length] [+[+]] [boardspec]\n",
__progname);
exit(1);
}
diff --git a/games/boggle/boggle/bog.h b/games/boggle/boggle/bog.h
index 46a3883342d..c01e7318cf3 100644
--- a/games/boggle/boggle/bog.h
+++ b/games/boggle/boggle/bog.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bog.h,v 1.3 2003/06/03 03:01:39 millert Exp $ */
+/* $OpenBSD: bog.h,v 1.4 2008/03/20 12:02:27 millert Exp $ */
/* $NetBSD: bog.h,v 1.2 1995/03/21 12:14:32 cgd Exp $ */
/*-
@@ -50,29 +50,15 @@
*/
#define MAXWORDLEN 40 /* Maximum word length */
#define MAXPWORDS 200 /* Maximum number of player's words */
-#define MAXMWORDS 200 /* Maximum number of machine's words */
+#define MAXMWORDS 400 /* Maximum number of machine's words */
#define MAXPSPACE 2000 /* Space for player's words */
#define MAXMSPACE 4000 /* Space for machines's words */
#define MAXCOLS 20
-/*
- * The following determine the screen layout
- */
-#define PROMPT_COL 20
-#define PROMPT_LINE 2
-
-#define BOARD_COL 0
-#define BOARD_LINE 0
-
-#define SCORE_COL 20
-#define SCORE_LINE 0
-
-#define LIST_COL 0
-#define LIST_LINE 10
-
-#define TIMER_COL 20
-#define TIMER_LINE 2
+#define SEVENBIT(c) ((c) & 0x7f)
+#define HISET(c) ((c) & 0x80)
+#define SETHI(c) ((c) | 0x80)
/*
* Internal dictionary index
diff --git a/games/boggle/boggle/boggle.6 b/games/boggle/boggle/boggle.6
index 611549c4df2..6fd9de1fc51 100644
--- a/games/boggle/boggle/boggle.6
+++ b/games/boggle/boggle/boggle.6
@@ -1,4 +1,4 @@
-.\" $OpenBSD: boggle.6,v 1.15 2007/05/31 19:19:17 jmc Exp $
+.\" $OpenBSD: boggle.6,v 1.16 2008/03/20 12:02:27 millert Exp $
.\" $NetBSD: boggle.6,v 1.2 1995/03/21 12:14:35 cgd Exp $
.\"
.\" Copyright (c) 1997, Jason Downs. All rights reserved.
@@ -56,7 +56,7 @@
.\"
.\" @(#)boggle.6 8.1 (Berkeley) 6/11/93
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: March 20 2008 $
.Dt BOGGLE 6
.Os
.Sh NAME
@@ -64,7 +64,7 @@
.Nd word search game
.Sh SYNOPSIS
.Nm boggle
-.Op Fl bd
+.Op Fl Bbcd
.Op Fl s Ar seed
.Op Fl t Ar time
.Op Fl w Ar length
@@ -87,6 +87,14 @@ Words consist solely of lower case letters and must be at least 3 letters long.
.Pp
Command line flags can be given to change the rules of the game:
.Bl -tag -width boardspec
+.It Fl B
+Use an alternate five by five arrangement of Boggle cubes.
+In this mode the default minimum word length is 4 letters.
+This arrangement has been marketed over the years under the names
+.Em Big Boggle ,
+.Em Super Boggle
+and
+.Em Boggle Deluxe .
.It Fl b
Run
.Nm
@@ -97,6 +105,13 @@ must also be given.
The dictionary is read from stdin and a list of words appearing in
.Ar boardspec
is printed to stdout.
+.It Fl c
+Add a so-called
+.Em challenge cube
+to the board, which contains less commonly used letters.
+The challenge cube will be displayed in boldface on the board.
+Depending on the terminal capabilities, it may be displayed in
+underline or a different color (such as red).
.It Fl d
Enable debugging output.
.It Fl s Ar seed
diff --git a/games/boggle/boggle/mach.c b/games/boggle/boggle/mach.c
index dd4f59e75a8..29540db96e0 100644
--- a/games/boggle/boggle/mach.c
+++ b/games/boggle/boggle/mach.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mach.c,v 1.8 2004/07/10 07:26:22 deraadt Exp $ */
+/* $OpenBSD: mach.c,v 1.9 2008/03/20 12:02:27 millert Exp $ */
/* $NetBSD: mach.c,v 1.5 1995/04/28 22:28:48 mycroft Exp $ */
/*-
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)mach.c 8.1 (Berkeley) 6/11/93";
#else
-static char rcsid[] = "$OpenBSD: mach.c,v 1.8 2004/07/10 07:26:22 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: mach.c,v 1.9 2008/03/20 12:02:27 millert Exp $";
#endif
#endif /* not lint */
@@ -50,6 +50,7 @@ static char rcsid[] = "$OpenBSD: mach.c,v 1.8 2004/07/10 07:26:22 deraadt Exp $"
#include <ctype.h>
#include <curses.h>
+#include <err.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
@@ -63,15 +64,33 @@ static char rcsid[] = "$OpenBSD: mach.c,v 1.8 2004/07/10 07:26:22 deraadt Exp $"
static int ccol, crow, maxw;
static int colstarts[MAXCOLS], ncolstarts;
-static int lastline;
-int ncols, nlines;
+static char *separator;
+int ncols, nlines, lastline;
-extern char *pword[], *mword[];
-extern int ngames, nmwords, npwords, tnmwords, tnpwords;
+/*
+ * The following determine the screen layout
+ */
+int PROMPT_COL = 20;
+int PROMPT_LINE = 3;
+
+int BOARD_COL = 0;
+int BOARD_LINE = 0;
+
+int SCORE_COL = 20;
+int SCORE_LINE = 0;
+
+int LIST_COL = 0;
+int LIST_LINE = 10;
+
+int TIMER_COL = 20;
+int TIMER_LINE = 2;
+
+extern char **pword, **mword;
+extern int ngames, nmwords, npwords, tnmwords, tnpwords, ncubes, grid;
static void cont_catcher(int);
-static int prwidth(char *[], int);
-static void prword(char *[], int);
+static int prwidth(char **, int);
+static void prword(char **, int);
static void stop_catcher(int);
static void tty_cleanup(void);
static int tty_setup(void);
@@ -85,6 +104,8 @@ static void winch_catcher(int);
int
setup(char *seed)
{
+ char *cp, *ep;
+
if (tty_setup() < 0)
return(-1);
@@ -92,6 +113,26 @@ setup(char *seed)
srandom(atol(seed));
else
srandomdev();
+
+ separator = malloc(4 * grid + 2);
+ if (separator == NULL)
+ err(1, NULL);
+
+ ep = separator + 4 * grid;
+ for (cp = separator; cp < ep;) {
+ *cp++ = '+';
+ *cp++ = '-';
+ *cp++ = '-';
+ *cp++ = '-';
+ }
+ *cp++ = '+';
+ *cp = '\0';
+
+ SCORE_COL += (grid - 4) * 4;
+ TIMER_COL += (grid - 4) * 4;
+ PROMPT_COL += (grid - 4) * 4;
+ LIST_LINE += (grid - 4) * 2;
+
return(0);
}
@@ -133,20 +174,24 @@ results(void)
denom2 = tnpwords + tnmwords;
move(SCORE_LINE, SCORE_COL);
+ printw("Score: %d out of %d\n", npwords, nmwords);
+ move(SCORE_LINE + 1, SCORE_COL);
printw("Percentage: %0.2f%% (%0.2f%% over %d game%s)\n",
denom1 ? (100.0 * npwords) / (double) (npwords + nmwords) : 0.0,
denom2 ? (100.0 * tnpwords) / (double) (tnpwords + tnmwords) : 0.0,
ngames, ngames > 1 ? "s" : "");
+ move(TIMER_LINE, TIMER_COL);
+ wclrtoeol(stdscr);
}
static void
-prword(char *base[], int indx)
+prword(char **base, int indx)
{
printw("%s", base[indx]);
}
static int
-prwidth(char *base[], int indx)
+prwidth(char **base, int indx)
{
return (strlen(base[indx]));
}
@@ -391,9 +436,9 @@ findword(void)
{
int c, col, found, i, r, row;
char buf[MAXWORDLEN + 1];
- extern char board[];
+ extern char *board;
extern int usedbits, wordpath[];
- extern char *mword[], *pword[];
+ extern char **mword, **pword;
extern int nmwords, npwords;
getyx(stdscr, r, c);
@@ -636,21 +681,28 @@ static void
tty_showboard(char *b)
{
int i, line;
+ char ch;
clear();
move(BOARD_LINE, BOARD_COL);
line = BOARD_LINE;
- printw("+---+---+---+---+");
+ printw(separator);
move(++line, BOARD_COL);
- for (i = 0; i < 16; i++) {
- if (b[i] == 'q')
- printw("| Qu");
+ for (i = 0; i < ncubes; i++) {
+ printw("| ");
+ ch = SEVENBIT(b[i]);
+ if (HISET(b[i]))
+ attron(A_BOLD);
+ if (ch == 'q')
+ printw("Qu");
else
- printw("| %c ", toupper(b[i]));
- if ((i + 1) % 4 == 0) {
+ printw("%c ", toupper(ch));
+ if (HISET(b[i]))
+ attroff(A_BOLD);
+ if ((i + 1) % grid == 0) {
printw("|");
move(++line, BOARD_COL);
- printw("+---+---+---+---+");
+ printw(separator);
move(++line, BOARD_COL);
}
}
diff --git a/games/boggle/boggle/prtable.c b/games/boggle/boggle/prtable.c
index a0bcd4279c4..7aed14ade04 100644
--- a/games/boggle/boggle/prtable.c
+++ b/games/boggle/boggle/prtable.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: prtable.c,v 1.9 2004/07/10 07:26:22 deraadt Exp $ */
+/* $OpenBSD: prtable.c,v 1.10 2008/03/20 12:02:27 millert Exp $ */
/* $NetBSD: prtable.c,v 1.2 1995/03/21 12:14:42 cgd Exp $ */
/*-
@@ -41,7 +41,9 @@
#define NCOLS 5
-static int get_maxlen(char *[], int, int (*)(char **, int));
+static int get_maxlen(char **, int, int (*)(char **, int));
+
+extern int lastline, LIST_LINE, LIST_COL;
/*
* Routine to print a table
@@ -59,8 +61,8 @@ static int get_maxlen(char *[], int, int (*)(char **, int));
* an index
*/
void
-prtable(char *base[], int num, int d_cols, int width,
- void (*prentry)(char *[], int), int (*length)(char *[], int))
+prtable(char **base, int num, int d_cols, int width,
+ void (*prentry)(char **, int), int (*length)(char **, int))
{
int c, j;
int a, b, cols, loc, maxlen, nrows, z;
@@ -102,12 +104,20 @@ prtable(char *base[], int num, int d_cols, int width,
}
getyx(stdscr, row, col);
move(row + 1, 0);
+ if (row + 1 == lastline && a != nrows) {
+ attron(A_REVERSE);
+ printw("--More--");
+ attroff(A_REVERSE);
+ while (inputch() != ' ');
+ move(LIST_LINE, LIST_COL);
+ wclrtobot(stdscr);
+ }
}
refresh();
}
static int
-get_maxlen(char *base[], int num, int (*length)(char **, int))
+get_maxlen(char **base, int num, int (*length)(char **, int))
{
int i, len, max;
diff --git a/games/boggle/boggle/timer.c b/games/boggle/boggle/timer.c
index 185ecec1cc3..6b088d55bfd 100644
--- a/games/boggle/boggle/timer.c
+++ b/games/boggle/boggle/timer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: timer.c,v 1.7 2004/07/10 07:26:22 deraadt Exp $ */
+/* $OpenBSD: timer.c,v 1.8 2008/03/20 12:02:27 millert Exp $ */
/* $NetBSD: timer.c,v 1.3 1995/04/24 12:22:45 cgd Exp $ */
/*-
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)timer.c 8.2 (Berkeley) 2/22/94";
#else
-static char rcsid[] = "$OpenBSD: timer.c,v 1.7 2004/07/10 07:26:22 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: timer.c,v 1.8 2008/03/20 12:02:27 millert Exp $";
#endif
#endif /* not lint */
@@ -53,6 +53,8 @@ static char rcsid[] = "$OpenBSD: timer.c,v 1.7 2004/07/10 07:26:22 deraadt Exp $
#include "bog.h"
#include "extern.h"
+extern int TIMER_LINE, TIMER_COL;
+
static int waitch(long);
/*