diff options
Diffstat (limited to 'games/cribbage')
-rw-r--r-- | games/cribbage/crib.c | 47 | ||||
-rw-r--r-- | games/cribbage/cribbage.6 | 91 | ||||
-rw-r--r-- | games/cribbage/cribbage.h | 3 | ||||
-rw-r--r-- | games/cribbage/cribbage.n | 29 | ||||
-rw-r--r-- | games/cribbage/extern.c | 3 | ||||
-rw-r--r-- | games/cribbage/score.c | 6 | ||||
-rw-r--r-- | games/cribbage/support.c | 14 |
7 files changed, 124 insertions, 69 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"); diff --git a/games/cribbage/cribbage.6 b/games/cribbage/cribbage.6 index 80ba1ef6d87..d20a5310d00 100644 --- a/games/cribbage/cribbage.6 +++ b/games/cribbage/cribbage.6 @@ -1,4 +1,4 @@ -.\" $OpenBSD: cribbage.6,v 1.8 1999/12/18 10:19:57 pjanzen Exp $ +.\" $OpenBSD: cribbage.6,v 1.9 2001/08/10 23:50:22 pjanzen Exp $ .\" .\" Copyright (c) 1980, 1993 .\" The Regents of the University of California. All rights reserved. @@ -41,13 +41,13 @@ .Nd the card game cribbage .Sh SYNOPSIS .Nm cribbage -.Op Fl eqr +.Op Fl emqr .Sh DESCRIPTION .Nm plays the card game cribbage, with the program playing one hand -and the user the other. The program will initially ask the user if -the rules of the game are needed \- if so, it will print out -the appropriate section from +and the user the other. +The program will initially ask the user if the rules of the game +are needed \- if so, it will print out the appropriate section from .Em According to Hoyle . .Pp .Nm @@ -55,8 +55,15 @@ options include: .Bl -tag -width indent .It Fl e When the player makes a mistake scoring his hand or crib, provide an -explanation of the correct score. (This is especially useful for -beginning players.) +explanation of the correct score. +.Po +This is especially useful for beginning players. +.Pc +.It Fl m +.Dq Muggins +\- if a player mistakenly scores less than is due, +the opponent may claim the overlooked points. +.Pq Of course, the computer never miscalculates! .It Fl q Print a shorter form of all messages \- this is only recommended for users who have played the game without specifying this option. @@ -66,51 +73,65 @@ cut the deck. .El .Pp .Nm -first asks the player whether he wishes to play a short game ( +first asks the player whether he wishes to play a short game +.Po .Dq once around , -to 61) or a long game ( +to 61 +.Pc +or a long game +.Po .Dq twice around , -to 121). A -response of +to 121 +.Pc . +A response of .Sq Ic s +or +.Sq Ic S will result in a short game; any other response will play a long game. .Pp At the start of the first game, the program asks the player to cut the deck to determine who gets the -first crib. The user should respond with a number between 0 and -51, indicating how many cards down the deck is to be cut. The player -who cuts the lower ranked card gets the first crib. +first crib. +The user should respond with a number between 4 and +48, indicating how many cards down the deck is to be cut. +The player who cuts the lower ranked card gets the first crib. If more than one game is played, the loser of the previous game gets the first crib in the current game. .Pp For each hand, the program first prints the player's hand and whose crib it is, and then asks the player -to discard two cards into the crib. The cards are prompted for -one per line, and are entered as explained below. +to discard two cards into the crib. +The cards are prompted for one per line, and are entered as explained below. .Pp -After discarding, the program cuts the deck (if it is the player's -crib) or asks the player to cut the deck (if it's its crib); in the latter -case, the appropriate response is a number from 0 to 39 indicating +After discarding, the program cuts the deck +.Pq if it is the player's crib +or asks the player to cut the deck +.Pq if it's its crib ; +in the latter +case, the appropriate response is a number from 4 to 36 indicating how far down the remaining 40 cards are to be cut. .Pp -After the deck is cut, play starts with the non-dealer (the person -who doesn't have the crib) leading the first card. -Play continues until all cards are exhausted. The -program keeps track of the scoring of all points and the total of +After the deck is cut, play starts with the non-dealer +.Pq the person who doesn't have the crib +leading the first card. +Play continues until all cards are exhausted. +The program keeps track of the scoring of all points and the total of the cards on the table. .Pp -After play, the hands are scored. The program requests the player to -score his hand (and the crib, if it is his) by printing out the -appropriate cards (and the cut card enclosed in brackets). -Play continues until one player reaches the game limit (61 or 121). +After play, the hands are scored. +The program requests the player to score his hand +.Pq and the crib, if it is his +by printing out the appropriate cards. +Play continues until one player reaches the game limit +.Pq 61 or 121 . .Pp A carriage return when a numeric input is expected is equivalent to typing the lowest legal value; when cutting the deck this -is equivalent to choosing the top card. +is equivalent to cutting after the fourth card. .Pp -Cards are specified as rank followed by suit. The ranks may be specified -as one of: +Cards are specified as rank followed by suit. +The ranks may be specified as one of: .Sq a , .Sq 2 , .Sq 3 , @@ -157,8 +178,9 @@ A card may be specified as: or: .Dq Ao rank Ac of Aq suit . If the single letter rank and suit designations are used, the space -separating the suit and rank may be left out. Also, if only one card -of the desired rank is playable, typing the rank is sufficient. +separating the suit and rank may be left out. +Also, if only one card of the desired rank is playable, +typing the rank is sufficient. For example, if your hand was .Dq 2H, 4D, 5C, 6H, JC, and KD and it was desired to discard the king of diamonds, any of @@ -177,10 +199,11 @@ the following could be typed: .Sh FILES .Bl -tag -width /usr/share/games/cribbage.instr -compact .It Pa /var/games/criblog -log file (if logging is enabled) +log file +.Pq if logging is enabled .It Pa /usr/share/games/cribbage.instr instructions .El .Sh AUTHORS Earl T. Cohen wrote the logic. -Ken Arnold added the screen oriented interface. +Ken Arnold added the screen-oriented interface. diff --git a/games/cribbage/cribbage.h b/games/cribbage/cribbage.h index e94d70faaf7..b8310db4fa4 100644 --- a/games/cribbage/cribbage.h +++ b/games/cribbage/cribbage.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cribbage.h,v 1.2 1999/11/29 06:42:20 millert Exp $ */ +/* $OpenBSD: cribbage.h,v 1.3 2001/08/10 23:50:22 pjanzen Exp $ */ /* $NetBSD: cribbage.h,v 1.3 1995/03/21 15:08:46 cgd Exp $ */ /* @@ -56,6 +56,7 @@ extern int Lastscore[2]; /* previous score for each */ extern bool iwon; /* if comp won last */ extern bool explain; /* player mistakes explained */ +extern bool muggins; /* player mistakes exploited */ extern bool rflag; /* if all cuts random */ extern bool quiet; /* if suppress random mess */ extern bool playing; /* currently playing game */ diff --git a/games/cribbage/cribbage.n b/games/cribbage/cribbage.n index 084e0917bc2..76498c2a94d 100644 --- a/games/cribbage/cribbage.n +++ b/games/cribbage/cribbage.n @@ -10,8 +10,8 @@ six. That is virtually the only change from Suckling's directions. Players: - Two. There are variants for three and four players, described - later. + Two. There are variants for three and four players [not described + here]. Cards: @@ -22,19 +22,18 @@ index value. Cribbage Board: - Indispensable to scoring (unless you have a computer!, ed.) is + Indispensable to scoring [unless you have a computer!, ed.] is the device known as the cribbage board. This is a rectangular panel, long -and narrow, in which are four rows of 30 holes each. (See illustration.) -At one end, or in the center, are two or four additional holes, called -game holes. The board is placed between the two players, and each keeps -his own score on the two rows of holes nearest himself. Each is supplied -with two pegs. Before the first hand, the pegs are placed in the game -holes. On making his first score, the player advances one peg an -appropriate number of holes (one per point) away from the game end of the -board. The second score is recorded by placing the second peg an -appropriate distance ahead of the first. For each subsequent score, the -rear peg is jumped ahead of the other, the distance between the two pegs -always showing the amount of this last score. +and narrow, in which are four rows of 30 holes each. At one end, or in the +center, are two or four additional holes, called game holes. The board is +placed between the two players, and each keeps his own score on the two +rows of holes nearest himself. Each is supplied with two pegs. Before the +first hand, the pegs are placed in the game holes. On making his first +score, the player advances one peg an appropriate number of holes (one per +point) away from the game end of the board. The second score is recorded +by placing the second peg an appropriate distance ahead of the first. For +each subsequent score, the rear peg is jumped ahead of the other, the +distance between the two pegs always showing the amount of this last score. The traditional mode of scoring is down (away from the game end) the outer row, and up the inner row. "Once around" is a game of 61 points. @@ -64,7 +63,7 @@ The Starter: After both hands have laid away, nondealer lifts off a packet from the top of the stock (the rest of the pack). Again, each packet must contain at least four cards. Dealer turns up the top card of the lower -packer, which is then placed on top of the stock when the packets are +packet, which is then placed on top of the stock when the packets are reunited. The card thus turned up is called 1 the starter. If it is a jack, dealer immediately pegs 2, called 2 for his heels. diff --git a/games/cribbage/extern.c b/games/cribbage/extern.c index 36fb6b9f782..cbd2176f491 100644 --- a/games/cribbage/extern.c +++ b/games/cribbage/extern.c @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.c,v 1.3 1999/11/29 06:42:20 millert Exp $ */ +/* $OpenBSD: extern.c,v 1.4 2001/08/10 23:50:22 pjanzen Exp $ */ /* $NetBSD: extern.c,v 1.3 1995/03/21 15:08:50 cgd Exp $ */ /*- @@ -49,6 +49,7 @@ static char rcsid[] = "$NetBSD: extern.c,v 1.3 1995/03/21 15:08:50 cgd Exp $"; bool explain = FALSE; /* player mistakes explained */ bool iwon = FALSE; /* if comp won last game */ +bool muggins = FALSE; /* player mistakes exploited */ bool quiet = FALSE; /* if suppress random mess */ bool rflag = FALSE; /* if all cuts random */ diff --git a/games/cribbage/score.c b/games/cribbage/score.c index 0c9595cf7f6..94423abfac0 100644 --- a/games/cribbage/score.c +++ b/games/cribbage/score.c @@ -1,4 +1,4 @@ -/* $OpenBSD: score.c,v 1.3 1999/11/29 06:42:20 millert Exp $ */ +/* $OpenBSD: score.c,v 1.4 2001/08/10 23:50:22 pjanzen Exp $ */ /* $NetBSD: score.c,v 1.3 1995/03/21 15:08:57 cgd Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: score.c,v 1.3 1999/11/29 06:42:20 millert Exp $"; +static char rcsid[] = "$OpenBSD: score.c,v 1.4 2001/08/10 23:50:22 pjanzen Exp $"; #endif #endif /* not lint */ @@ -128,7 +128,7 @@ scorehand(hand, starter, n, crb, do_explain) k = hand[0].suit; for (i = 0; i < n; i++) { /* check for flush */ flag = (flag && (hand[i].suit == k)); - if (hand[i].rank == JACK) /* check for his nibs */ + if (hand[i].rank == JACK) /* check for his nobs */ if (hand[i].suit == starter.suit) { score++; if (do_explain) diff --git a/games/cribbage/support.c b/games/cribbage/support.c index 4fe305877a1..cebc710659c 100644 --- a/games/cribbage/support.c +++ b/games/cribbage/support.c @@ -1,4 +1,4 @@ -/* $OpenBSD: support.c,v 1.4 1999/11/29 06:42:20 millert Exp $ */ +/* $OpenBSD: support.c,v 1.5 2001/08/10 23:50:22 pjanzen Exp $ */ /* $NetBSD: support.c,v 1.3 1995/03/21 15:08:59 cgd Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)support.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: support.c,v 1.4 1999/11/29 06:42:20 millert Exp $"; +static char rcsid[] = "$OpenBSD: support.c,v 1.5 2001/08/10 23:50:22 pjanzen Exp $"; #endif #endif /* not lint */ @@ -144,12 +144,18 @@ plyrhand(hand, s) if (i != j) { if (i < j) { win = chkscr(&pscore, i); - msg("It's really only %d points; I get %d", i, 2); - if (!win) + if (!win) { + msg("It's really only %d points; I get %d", i, 2); win = chkscr(&cscore, 2); + } else + msg("It's really only %d points.", i); } else { win = chkscr(&pscore, j); msg("You should have taken %d, not %d!", i, j); + if (!win && muggins) { + msg("Muggins! I score %d", i - j); + win = chkscr(&cscore, i - j); + } } if (explain) msg("Explanation: %s", expl); |