summaryrefslogtreecommitdiff
path: root/games/cribbage/crib.c
diff options
context:
space:
mode:
authorPaul Janzen <pjanzen@cvs.openbsd.org>2001-08-10 23:50:23 +0000
committerPaul Janzen <pjanzen@cvs.openbsd.org>2001-08-10 23:50:23 +0000
commit061fdc3f48491abc4b4f22bb6107678c71170609 (patch)
tree9656542c7e3320eb49c8daab78b02c32788ce8e6 /games/cribbage/crib.c
parentbf242e276aac1e0bd76102f66c47f225bc1b4319 (diff)
-m option for muggins
better user input parsing man page tidying and syncing of rules to Hoyle's typo and context correction in "Hoyle's" transcription
Diffstat (limited to 'games/cribbage/crib.c')
-rw-r--r--games/cribbage/crib.c47
1 files changed, 36 insertions, 11 deletions
diff --git a/games/cribbage/crib.c b/games/cribbage/crib.c
index a5ec3d0976c..c4197d9ce79 100644
--- a/games/cribbage/crib.c
+++ b/games/cribbage/crib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crib.c,v 1.7 1999/11/29 06:42:20 millert Exp $ */
+/* $OpenBSD: crib.c,v 1.8 2001/08/10 23:50:22 pjanzen Exp $ */
/* $NetBSD: crib.c,v 1.7 1997/07/10 06:47:29 mikel Exp $ */
/*-
@@ -44,7 +44,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)crib.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: crib.c,v 1.7 1999/11/29 06:42:20 millert Exp $";
+static char rcsid[] = "$OpenBSD: crib.c,v 1.8 2001/08/10 23:50:22 pjanzen Exp $";
#endif
#endif /* not lint */
@@ -78,11 +78,14 @@ main(argc, argv)
setgid(getgid());
#endif
- while ((ch = getopt(argc, argv, "eqr")) != -1)
+ while ((ch = getopt(argc, argv, "emqr")) != -1)
switch (ch) {
case 'e':
explain = TRUE;
break;
+ case 'm':
+ muggins = TRUE;
+ break;
case 'q':
quiet = TRUE;
break;
@@ -91,7 +94,7 @@ main(argc, argv)
break;
case '?':
default:
- (void) fprintf(stderr, "usage: cribbage [-eqr]\n");
+ (void) fprintf(stderr, "usage: cribbage [-emqr]\n");
exit(1);
}
@@ -218,9 +221,20 @@ game()
flag = TRUE;
do {
if (!rflag) { /* player cuts deck */
- msg(quiet ? "Cut for crib? " :
- "Cut to see whose crib it is -- low card wins? ");
- getline();
+ char *foo;
+
+ /* This is silly, but we should parse user input
+ * even if we're not actually going to use it.
+ */
+ do {
+ msg(quiet ? "Cut for crib? " :
+ "Cut to see whose crib it is -- low card wins? ");
+ foo = getline();
+ if (*foo != '\0' && ((i = atoi(foo)) < 4 || i > 48))
+ msg("Invalid cut");
+ else
+ *foo = '\0';
+ } while (*foo != '\0');
}
i = (rand() >> 4) % CARDS; /* random cut */
do { /* comp cuts deck */
@@ -394,9 +408,20 @@ cut(mycrib, pos)
win = FALSE;
if (mycrib) {
if (!rflag) { /* random cut */
- msg(quiet ? "Cut the deck? " :
- "How many cards down do you wish to cut the deck? ");
- getline();
+ char *foo;
+
+ /* This is silly, but we should parse user input,
+ * even if we're not actually going to use it.
+ */
+ do {
+ msg(quiet ? "Cut the deck? " :
+ "How many cards down do you wish to cut the deck? ");
+ foo = getline();
+ if (*foo != '\0' && ((i = atoi(foo)) < 4 || i > 36))
+ msg("Invalid cut");
+ else
+ *foo = '\0';
+ } while (*foo != '\0');
}
i = (rand() >> 4) % (CARDS - pos);
turnover = deck[i + pos];
@@ -484,7 +509,7 @@ peg(mycrib)
prhand(ph, pnum, Playwin, FALSE);
prhand(ch, cnum, Compwin, TRUE);
prtable(sum);
- if (myturn) { /* my tyrn to play */
+ if (myturn) {
if (!anymove(ch, cnum, sum)) { /* if no card to play */
if (!mego && cnum) { /* go for comp? */
msg("GO");