summaryrefslogtreecommitdiffstats
path: root/cribbage
diff options
context:
space:
mode:
authorcgd <cgd@NetBSD.org>1995-03-21 15:03:38 +0000
committercgd <cgd@NetBSD.org>1995-03-21 15:03:38 +0000
commit5ff78ede5ea1a80c654d3f0684cd5f36d5253ae1 (patch)
tree81a19a5b24b0353e8cbac8b1f0ad82be1cf16323 /cribbage
parent45171656c266fc63f08d074d856b5ae99ac29211 (diff)
downloadbsdgames-darwin-5ff78ede5ea1a80c654d3f0684cd5f36d5253ae1.tar.gz
bsdgames-darwin-5ff78ede5ea1a80c654d3f0684cd5f36d5253ae1.tar.zst
bsdgames-darwin-5ff78ede5ea1a80c654d3f0684cd5f36d5253ae1.zip
clean up import
Diffstat (limited to 'cribbage')
-rw-r--r--cribbage/Makefile4
-rw-r--r--cribbage/cards.c159
-rw-r--r--cribbage/crib.c722
-rw-r--r--cribbage/cribbage.611
-rw-r--r--cribbage/cribbage.h60
-rw-r--r--cribbage/cribcur.h9
-rw-r--r--cribbage/deck.h9
-rw-r--r--cribbage/extern.c22
-rw-r--r--cribbage/instr.c23
-rw-r--r--cribbage/io.c763
-rw-r--r--cribbage/pathnames.h11
-rw-r--r--cribbage/score.c400
-rw-r--r--cribbage/support.c376
13 files changed, 1339 insertions, 1230 deletions
diff --git a/cribbage/Makefile b/cribbage/Makefile
index c5c7522e..69c60d77 100644
--- a/cribbage/Makefile
+++ b/cribbage/Makefile
@@ -1,5 +1,5 @@
-# from: @(#)Makefile 5.11 (Berkeley) 5/11/90
-# $Id: Makefile,v 1.4 1994/12/22 09:33:52 cgd Exp $
+# $NetBSD: Makefile,v 1.5 1995/03/21 15:08:39 cgd Exp $
+# @(#)Makefile 8.1 (Berkeley) 5/31/93
PROG= cribbage
DPADD= ${LIBCURSES} ${LIBTERM}
diff --git a/cribbage/cards.c b/cribbage/cards.c
index 16927fa9..a81bdf65 100644
--- a/cribbage/cards.c
+++ b/cribbage/cards.c
@@ -1,6 +1,8 @@
-/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+/* $NetBSD: cards.c,v 1.3 1995/03/21 15:08:41 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,131 +34,118 @@
*/
#ifndef lint
-/*static char sccsid[] = "from: @(#)cards.c 5.5 (Berkeley) 2/28/91";*/
-static char rcsid[] = "$Id: cards.c,v 1.2 1993/08/01 18:55:16 mycroft Exp $";
+static char sccsid[] = "@(#)cards.c 8.1 (Berkeley) 5/31/93";
#endif /* not lint */
-#include <stdio.h>
-#include "deck.h"
+#include <curses.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include "deck.h"
+#include "cribbage.h"
/*
- * initialize a deck of cards to contain one of each type
+ * Initialize a deck of cards to contain one of each type.
*/
-
-makedeck( d )
-
- CARD d[];
+void
+makedeck(d)
+ CARD d[];
{
- register int i, j, k;
- long time();
+ register int i, j, k;
- i = time( (long *) 0 );
- i = ( (i&0xff) << 8 ) | ( (i >> 8)&0xff ) | 1;
- srand( i );
+ i = time(NULL);
+ i = ((i & 0xff) << 8) | ((i >> 8) & 0xff) | 1;
+ srand(i);
k = 0;
- for( i = 0; i < RANKS; i++ ) {
- for( j = 0; j < SUITS; j++ ) {
- d[k].suit = j;
- d[k++].rank = i;
- }
- }
+ for (i = 0; i < RANKS; i++)
+ for (j = 0; j < SUITS; j++) {
+ d[k].suit = j;
+ d[k++].rank = i;
+ }
}
-
-
/*
- * given a deck of cards, shuffle it -- i.e. randomize it
- * see Knuth, vol. 2, page 125
+ * Given a deck of cards, shuffle it -- i.e. randomize it
+ * see Knuth, vol. 2, page 125.
*/
-
-shuffle( d )
-
- CARD d[];
+void
+shuffle(d)
+ CARD d[];
{
- register int j, k;
- CARD c;
-
- for( j = CARDS; j > 0; --j ) {
- k = ( rand() >> 4 ) % j; /* random 0 <= k < j */
- c = d[j - 1]; /* exchange (j - 1) and k */
- d[j - 1] = d[k];
- d[k] = c;
+ register int j, k;
+ CARD c;
+
+ for (j = CARDS; j > 0; --j) {
+ k = (rand() >> 4) % j; /* random 0 <= k < j */
+ c = d[j - 1]; /* exchange (j - 1) and k */
+ d[j - 1] = d[k];
+ d[k] = c;
}
}
-
-
/*
* return true if the two cards are equal...
*/
-
-eq( a, b )
-
- CARD a, b;
+int
+eq(a, b)
+ CARD a, b;
{
- return( ( a.rank == b.rank ) && ( a.suit == b.suit ) );
+ return ((a.rank == b.rank) && (a.suit == b.suit));
}
-
-
/*
* isone returns TRUE if a is in the set of cards b
*/
-
-isone( a, b, n )
-
- CARD a, b[];
- int n;
+int
+isone(a, b, n)
+ CARD a, b[];
+ int n;
{
- register int i;
+ register int i;
- for( i = 0; i < n; i++ ) {
- if( eq( a, b[i] ) ) return( TRUE );
- }
- return( FALSE );
+ for (i = 0; i < n; i++)
+ if (eq(a, b[i]))
+ return (TRUE);
+ return (FALSE);
}
-
-
/*
* remove the card a from the deck d of n cards
*/
-
-cremove( a, d, n )
-
- CARD a, d[];
- int n;
+void
+cremove(a, d, n)
+ CARD a, d[];
+ int n;
{
- register int i, j;
+ register int i, j;
- j = 0;
- for( i = 0; i < n; i++ ) {
- if( !eq( a, d[i] ) ) d[j++] = d[i];
- }
- if( j < n ) d[j].suit = d[j].rank = EMPTY;
+ for (i = j = 0; i < n; i++)
+ if (!eq(a, d[i]))
+ d[j++] = d[i];
+ if (j < n)
+ d[j].suit = d[j].rank = EMPTY;
}
-
-
/*
* sorthand:
* Sort a hand of n cards
*/
+void
sorthand(h, n)
-register CARD h[];
-int n;
+ register CARD h[];
+ int n;
{
- register CARD *cp, *endp;
- CARD c;
+ register CARD *cp, *endp;
+ CARD c;
for (endp = &h[n]; h < endp - 1; h++)
- for (cp = h + 1; cp < endp; cp++)
- if ((cp->rank < h->rank) ||
- (cp->rank == h->rank && cp->suit < h->suit)) {
- c = *h;
- *h = *cp;
- *cp = c;
- }
+ for (cp = h + 1; cp < endp; cp++)
+ if ((cp->rank < h->rank) ||
+ (cp->rank == h->rank && cp->suit < h->suit)) {
+ c = *h;
+ *h = *cp;
+ *cp = c;
+ }
}
-
diff --git a/cribbage/crib.c b/cribbage/crib.c
index c357f2da..96bfe568 100644
--- a/cribbage/crib.c
+++ b/cribbage/crib.c
@@ -1,6 +1,8 @@
-/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+/* $NetBSD: crib.c,v 1.5 1995/03/21 15:08:42 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,41 +34,41 @@
*/
#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1980 Regents of the University of California.\n\
- All rights reserved.\n";
+static char copyright[] =
+"@(#) Copyright (c) 1980, 1993\n\
+ The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
-/*static char sccsid[] = "from: @(#)crib.c 5.6 (Berkeley) 2/28/91";*/
-static char rcsid[] = "$Id: crib.c,v 1.4 1995/02/28 18:31:26 jtc Exp $";
+#if 0
+static char sccsid[] = "@(#)crib.c 8.1 (Berkeley) 5/31/93";
+#else
+static char rcsid[] = "$NetBSD: crib.c,v 1.5 1995/03/21 15:08:42 cgd Exp $";
+#endif
#endif /* not lint */
-# include <signal.h>
-# include <curses.h>
-# include <unistd.h>
-# include "deck.h"
-# include "cribbage.h"
-# include "cribcur.h"
-# include "pathnames.h"
+#include <curses.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "deck.h"
+#include "cribbage.h"
+#include "cribcur.h"
+#include "pathnames.h"
+int
main(argc, argv)
-int argc;
-char *argv[];
+ int argc;
+ char *argv[];
{
- extern char *optarg;
- extern int optind;
- register char *p;
+ BOOLEAN playing;
+ FILE *f;
int ch;
- BOOLEAN playing;
- char *s; /* for reading arguments */
- FILE *f;
- FILE *fopen();
- char *getline();
- void rint();
while ((ch = getopt(argc, argv, "eqr")) != EOF)
- switch(ch) {
+ switch (ch) {
case 'e':
explain = TRUE;
break;
@@ -83,9 +85,10 @@ char *argv[];
}
initscr();
- signal(SIGINT, rint);
+ (void)signal(SIGINT, rint);
crmode();
noecho();
+
Playwin = subwin(stdscr, PLAY_Y, PLAY_X, 0, 0);
Tablewin = subwin(stdscr, TABLE_Y, TABLE_X, 0, PLAY_X);
Compwin = subwin(stdscr, COMP_Y, COMP_X, 0, TABLE_X + PLAY_X);
@@ -96,41 +99,41 @@ char *argv[];
clearok(stdscr, FALSE);
if (!quiet) {
- msg("Do you need instructions for cribbage? ");
- if (getuchar() == 'Y') {
- endwin();
- clear();
- mvcur(0, COLS - 1, LINES - 1, 0);
- fflush(stdout);
- instructions();
- crmode();
- noecho();
- clear();
- refresh();
- msg("For the rules of this program, do \"man cribbage\"");
- }
+ msg("Do you need instructions for cribbage? ");
+ if (getuchar() == 'Y') {
+ endwin();
+ clear();
+ mvcur(0, COLS - 1, LINES - 1, 0);
+ fflush(stdout);
+ instructions();
+ crmode();
+ noecho();
+ clear();
+ refresh();
+ msg("For cribbage rules, use \"man cribbage\"");
+ }
}
playing = TRUE;
do {
- wclrtobot(Msgwin);
- msg(quiet ? "L or S? " : "Long (to 121) or Short (to 61)? ");
- if (glimit == SGAME)
- glimit = (getuchar() == 'L' ? LGAME : SGAME);
- else
- glimit = (getuchar() == 'S' ? SGAME : LGAME);
- game();
- msg("Another game? ");
- playing = (getuchar() == 'Y');
+ wclrtobot(Msgwin);
+ msg(quiet ? "L or S? " : "Long (to 121) or Short (to 61)? ");
+ if (glimit == SGAME)
+ glimit = (getuchar() == 'L' ? LGAME : SGAME);
+ else
+ glimit = (getuchar() == 'S' ? SGAME : LGAME);
+ game();
+ msg("Another game? ");
+ playing = (getuchar() == 'Y');
} while (playing);
if (f = fopen(_PATH_LOG, "a")) {
(void)fprintf(f, "%s: won %5.5d, lost %5.5d\n",
- getlogin(), cgames, pgames);
- (void)fclose(f);
+ getlogin(), cgames, pgames);
+ (void) fclose(f);
}
bye();
if (!f) {
- (void)fprintf(stderr, "\ncribbage: can't open %s.\n",
+ (void) fprintf(stderr, "\ncribbage: can't open %s.\n",
_PATH_LOG);
exit(1);
}
@@ -141,34 +144,45 @@ char *argv[];
* makeboard:
* Print out the initial board on the screen
*/
+void
makeboard()
{
- mvaddstr(SCORE_Y + 0, SCORE_X, "+---------------------------------------+");
- mvaddstr(SCORE_Y + 1, SCORE_X, "| Score: 0 YOU |");
- mvaddstr(SCORE_Y + 2, SCORE_X, "| *.....:.....:.....:.....:.....:..... |");
- mvaddstr(SCORE_Y + 3, SCORE_X, "| *.....:.....:.....:.....:.....:..... |");
- mvaddstr(SCORE_Y + 4, SCORE_X, "| |");
- mvaddstr(SCORE_Y + 5, SCORE_X, "| *.....:.....:.....:.....:.....:..... |");
- mvaddstr(SCORE_Y + 6, SCORE_X, "| *.....:.....:.....:.....:.....:..... |");
- mvaddstr(SCORE_Y + 7, SCORE_X, "| Score: 0 ME |");
- mvaddstr(SCORE_Y + 8, SCORE_X, "+---------------------------------------+");
- gamescore();
+ mvaddstr(SCORE_Y + 0, SCORE_X,
+ "+---------------------------------------+");
+ mvaddstr(SCORE_Y + 1, SCORE_X,
+ "| Score: 0 YOU |");
+ mvaddstr(SCORE_Y + 2, SCORE_X,
+ "| *.....:.....:.....:.....:.....:..... |");
+ mvaddstr(SCORE_Y + 3, SCORE_X,
+ "| *.....:.....:.....:.....:.....:..... |");
+ mvaddstr(SCORE_Y + 4, SCORE_X,
+ "| |");
+ mvaddstr(SCORE_Y + 5, SCORE_X,
+ "| *.....:.....:.....:.....:.....:..... |");
+ mvaddstr(SCORE_Y + 6, SCORE_X,
+ "| *.....:.....:.....:.....:.....:..... |");
+ mvaddstr(SCORE_Y + 7, SCORE_X,
+ "| Score: 0 ME |");
+ mvaddstr(SCORE_Y + 8, SCORE_X,
+ "+---------------------------------------+");
+ gamescore();
}
/*
* gamescore:
* Print out the current game score
*/
+void
gamescore()
{
- extern int Lastscore[];
-
- if (pgames || cgames) {
- mvprintw(SCORE_Y + 1, SCORE_X + 28, "Games: %3d", pgames);
- mvprintw(SCORE_Y + 7, SCORE_X + 28, "Games: %3d", cgames);
- }
- Lastscore[0] = -1;
- Lastscore[1] = -1;
+ extern int Lastscore[];
+
+ if (pgames || cgames) {
+ mvprintw(SCORE_Y + 1, SCORE_X + 28, "Games: %3d", pgames);
+ mvprintw(SCORE_Y + 7, SCORE_X + 28, "Games: %3d", cgames);
+ }
+ Lastscore[0] = -1;
+ Lastscore[1] = -1;
}
/*
@@ -176,92 +190,88 @@ gamescore()
* Play one game up to glimit points. Actually, we only ASK the
* player what card to turn. We do a random one, anyway.
*/
+void
game()
{
- register int i, j;
- BOOLEAN flag;
- BOOLEAN compcrib;
- char *getline();
+ register int i, j;
+ BOOLEAN flag;
+ BOOLEAN compcrib;
- makeboard();
- refresh();
makedeck(deck);
shuffle(deck);
if (gamecount == 0) {
- flag = TRUE;
- do {
- if (!rflag) { /* player cuts deck */
- msg(quiet ? "Cut for crib? " :
- "Cut to see whose crib it is -- low card wins? ");
- getline();
- }
- i = (rand() >> 4) % CARDS; /* random cut */
- do { /* comp cuts deck */
- j = (rand() >> 4) % CARDS;
- } while (j == i);
- addmsg(quiet ? "You cut " : "You cut the ");
- msgcard(deck[i], FALSE);
- endmsg();
- addmsg(quiet ? "I cut " : "I cut the ");
- msgcard(deck[j], FALSE);
- endmsg();
- flag = (deck[i].rank == deck[j].rank);
- if (flag) {
- msg(quiet ? "We tied..." :
- "We tied and have to try again...");
- shuffle(deck);
- continue;
- }
- else
- compcrib = (deck[i].rank > deck[j].rank);
- } while (flag);
- }
- else {
- werase(Tablewin);
- wrefresh(Tablewin);
- werase(Compwin);
- wrefresh(Compwin);
- msg("Loser (%s) gets first crib", (iwon ? "you" : "me"));
- compcrib = !iwon;
+ flag = TRUE;
+ do {
+ if (!rflag) { /* player cuts deck */
+ msg(quiet ? "Cut for crib? " :
+ "Cut to see whose crib it is -- low card wins? ");
+ getline();
+ }
+ i = (rand() >> 4) % CARDS; /* random cut */
+ do { /* comp cuts deck */
+ j = (rand() >> 4) % CARDS;
+ } while (j == i);
+ addmsg(quiet ? "You cut " : "You cut the ");
+ msgcard(deck[i], FALSE);
+ endmsg();
+ addmsg(quiet ? "I cut " : "I cut the ");
+ msgcard(deck[j], FALSE);
+ endmsg();
+ flag = (deck[i].rank == deck[j].rank);
+ if (flag) {
+ msg(quiet ? "We tied..." :
+ "We tied and have to try again...");
+ shuffle(deck);
+ continue;
+ } else
+ compcrib = (deck[i].rank > deck[j].rank);
+ } while (flag);
+ clear();
+ makeboard();
+ refresh();
+ } else {
+ werase(Tablewin);
+ wrefresh(Tablewin);
+ werase(Compwin);
+ wrefresh(Compwin);
+ msg("Loser (%s) gets first crib", (iwon ? "you" : "me"));
+ compcrib = !iwon;
}
pscore = cscore = 0;
flag = TRUE;
do {
- shuffle(deck);
- flag = !playhand(compcrib);
- compcrib = !compcrib;
+ shuffle(deck);
+ flag = !playhand(compcrib);
+ compcrib = !compcrib;
} while (flag);
++gamecount;
if (cscore < pscore) {
- if (glimit - cscore > 60) {
- msg("YOU DOUBLE SKUNKED ME!");
- pgames += 4;
- }
- else if (glimit - cscore > 30) {
- msg("YOU SKUNKED ME!");
- pgames += 2;
- }
- else {
- msg("YOU WON!");
- ++pgames;
- }
- iwon = FALSE;
- }
- else {
- if (glimit - pscore > 60) {
- msg("I DOUBLE SKUNKED YOU!");
- cgames += 4;
- }
- else if (glimit - pscore > 30) {
- msg("I SKUNKED YOU!");
- cgames += 2;
- }
- else {
- msg("I WON!");
- ++cgames;
- }
- iwon = TRUE;
+ if (glimit - cscore > 60) {
+ msg("YOU DOUBLE SKUNKED ME!");
+ pgames += 4;
+ } else
+ if (glimit - cscore > 30) {
+ msg("YOU SKUNKED ME!");
+ pgames += 2;
+ } else {
+ msg("YOU WON!");
+ ++pgames;
+ }
+ iwon = FALSE;
+ } else {
+ if (glimit - pscore > 60) {
+ msg("I DOUBLE SKUNKED YOU!");
+ cgames += 4;
+ } else
+ if (glimit - pscore > 30) {
+ msg("I SKUNKED YOU!");
+ cgames += 2;
+ } else {
+ msg("I WON!");
+ ++cgames;
+ }
+ iwon = TRUE;
}
gamescore();
}
@@ -270,11 +280,11 @@ game()
* playhand:
* Do up one hand of the game
*/
+int
playhand(mycrib)
-BOOLEAN mycrib;
+ BOOLEAN mycrib;
{
- register int deckpos;
- extern char Msgbuf[];
+ register int deckpos;
werase(Compwin);
@@ -286,38 +296,35 @@ BOOLEAN mycrib;
prhand(phand, FULLHAND, Playwin, FALSE);
discard(mycrib);
if (cut(mycrib, deckpos))
- return TRUE;
+ return TRUE;
if (peg(mycrib))
- return TRUE;
+ return TRUE;
werase(Tablewin);
wrefresh(Tablewin);
if (score(mycrib))
- return TRUE;
+ return TRUE;
return FALSE;
}
-
-
/*
* deal cards to both players from deck
*/
-
-deal( mycrib )
+int
+deal(mycrib)
+ BOOLEAN mycrib;
{
- register int i, j;
-
- j = 0;
- for( i = 0; i < FULLHAND; i++ ) {
- if( mycrib ) {
- phand[i] = deck[j++];
- chand[i] = deck[j++];
- }
- else {
- chand[i] = deck[j++];
- phand[i] = deck[j++];
- }
+ register int i, j;
+
+ for (i = j = 0; i < FULLHAND; i++) {
+ if (mycrib) {
+ phand[i] = deck[j++];
+ chand[i] = deck[j++];
+ } else {
+ chand[i] = deck[j++];
+ phand[i] = deck[j++];
+ }
}
- return( j );
+ return (j);
}
/*
@@ -325,20 +332,22 @@ deal( mycrib )
* Handle players discarding into the crib...
* Note: we call cdiscard() after prining first message so player doesn't wait
*/
+void
discard(mycrib)
-BOOLEAN mycrib;
+ BOOLEAN mycrib;
{
- register char *prompt;
- CARD crd;
+ register char *prompt;
+ CARD crd;
prcrib(mycrib, TRUE);
prompt = (quiet ? "Discard --> " : "Discard a card --> ");
- cdiscard(mycrib); /* puts best discard at end */
+ cdiscard(mycrib); /* puts best discard at end */
crd = phand[infrom(phand, FULLHAND, prompt)];
cremove(crd, phand, FULLHAND);
prhand(phand, FULLHAND, Playwin, FALSE);
crib[0] = crd;
-/* next four lines same as last four except for cdiscard() */
+
+ /* Next four lines same as last four except for cdiscard(). */
crd = phand[infrom(phand, FULLHAND - 1, prompt)];
cremove(crd, phand, FULLHAND - 1);
prhand(phand, FULLHAND, Playwin, FALSE);
@@ -353,232 +362,237 @@ BOOLEAN mycrib;
* Cut the deck and set turnover. Actually, we only ASK the
* player what card to turn. We do a random one, anyway.
*/
+int
cut(mycrib, pos)
-BOOLEAN mycrib;
-int pos;
+ BOOLEAN mycrib;
+ int pos;
{
- register int i, cardx;
- BOOLEAN win = FALSE;
- char *getline();
+ register int i;
+ BOOLEAN win;
+ 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();
- }
- i = (rand() >> 4) % (CARDS - pos);
- turnover = deck[i + pos];
- addmsg(quiet ? "You cut " : "You cut the ");
- msgcard(turnover, FALSE);
- endmsg();
- if (turnover.rank == JACK) {
- msg("I get two for his heels");
- win = chkscr(&cscore,2 );
- }
- }
- else {
- i = (rand() >> 4) % (CARDS - pos) + pos;
- turnover = deck[i];
- addmsg(quiet ? "I cut " : "I cut the ");
- msgcard(turnover, FALSE);
- endmsg();
- if (turnover.rank == JACK) {
- msg("You get two for his heels");
- win = chkscr(&pscore, 2);
- }
+ if (!rflag) { /* random cut */
+ msg(quiet ? "Cut the deck? " :
+ "How many cards down do you wish to cut the deck? ");
+ getline();
+ }
+ i = (rand() >> 4) % (CARDS - pos);
+ turnover = deck[i + pos];
+ addmsg(quiet ? "You cut " : "You cut the ");
+ msgcard(turnover, FALSE);
+ endmsg();
+ if (turnover.rank == JACK) {
+ msg("I get two for his heels");
+ win = chkscr(&cscore, 2);
+ }
+ } else {
+ i = (rand() >> 4) % (CARDS - pos) + pos;
+ turnover = deck[i];
+ addmsg(quiet ? "I cut " : "I cut the ");
+ msgcard(turnover, FALSE);
+ endmsg();
+ if (turnover.rank == JACK) {
+ msg("You get two for his heels");
+ win = chkscr(&pscore, 2);
+ }
}
makeknown(&turnover, 1);
prcrib(mycrib, FALSE);
- return win;
+ return (win);
}
/*
* prcrib:
* Print out the turnover card with crib indicator
*/
+void
prcrib(mycrib, blank)
-BOOLEAN mycrib, blank;
+ BOOLEAN mycrib, blank;
{
- register int y, cardx;
+ register int y, cardx;
if (mycrib)
- cardx = CRIB_X;
+ cardx = CRIB_X;
else
- cardx = 0;
+ cardx = 0;
mvaddstr(CRIB_Y, cardx + 1, "CRIB");
prcard(stdscr, CRIB_Y + 1, cardx, turnover, blank);
if (mycrib)
- cardx = 0;
+ cardx = 0;
else
- cardx = CRIB_X;
+ cardx = CRIB_X;
for (y = CRIB_Y; y <= CRIB_Y + 5; y++)
- mvaddstr(y, cardx, " ");
+ mvaddstr(y, cardx, " ");
}
/*
* peg:
* Handle all the pegging...
*/
+static CARD Table[14];
+static int Tcnt;
-static CARD Table[14];
-
-static int Tcnt;
-
+int
peg(mycrib)
-BOOLEAN mycrib;
+ BOOLEAN mycrib;
{
- static CARD ch[CINHAND], ph[CINHAND];
- CARD crd;
- register int i, j, k;
- register int l;
- register int cnum, pnum, sum;
- register BOOLEAN myturn, mego, ugo, last, played;
+ static CARD ch[CINHAND], ph[CINHAND];
+ register int i, j, k;
+ register int l;
+ register int cnum, pnum, sum;
+ register BOOLEAN myturn, mego, ugo, last, played;
+ CARD crd;
cnum = pnum = CINHAND;
- for (i = 0; i < CINHAND; i++) { /* make copies of hands */
- ch[i] = chand[i];
- ph[i] = phand[i];
+ for (i = 0; i < CINHAND; i++) { /* make copies of hands */
+ ch[i] = chand[i];
+ ph[i] = phand[i];
}
- Tcnt = 0; /* index to table of cards played */
- sum = 0; /* sum of cards played */
+ Tcnt = 0; /* index to table of cards played */
+ sum = 0; /* sum of cards played */
mego = ugo = FALSE;
myturn = !mycrib;
for (;;) {
- last = TRUE; /* enable last flag */
- prhand(ph, pnum, Playwin, FALSE);
- prhand(ch, cnum, Compwin, TRUE);
- prtable(sum);
- if (myturn) { /* my tyrn to play */
- if (!anymove(ch, cnum, sum)) { /* if no card to play */
- if (!mego && cnum) { /* go for comp? */
- msg("GO");
- mego = TRUE;
- }
- if (anymove(ph, pnum, sum)) /* can player move? */
- myturn = !myturn;
- else { /* give him his point */
- msg(quiet ? "You get one" : "You get one point");
- if (chkscr(&pscore, 1))
- return TRUE;
- sum = 0;
- mego = ugo = FALSE;
- Tcnt = 0;
- }
- }
- else {
- played = TRUE;
- j = -1;
- k = 0;
- for (i = 0; i < cnum; i++) { /* maximize score */
- l = pegscore(ch[i], Table, Tcnt, sum);
- if (l > k) {
- k = l;
- j = i;
+ last = TRUE; /* enable last flag */
+ prhand(ph, pnum, Playwin, FALSE);
+ prhand(ch, cnum, Compwin, TRUE);
+ prtable(sum);
+ if (myturn) { /* my tyrn to play */
+ if (!anymove(ch, cnum, sum)) { /* if no card to play */
+ if (!mego && cnum) { /* go for comp? */
+ msg("GO");
+ mego = TRUE;
+ }
+ /* can player move? */
+ if (anymove(ph, pnum, sum))
+ myturn = !myturn;
+ else { /* give him his point */
+ msg(quiet ? "You get one" :
+ "You get one point");
+ if (chkscr(&pscore, 1))
+ return TRUE;
+ sum = 0;
+ mego = ugo = FALSE;
+ Tcnt = 0;
+ }
+ } else {
+ played = TRUE;
+ j = -1;
+ k = 0;
+ /* maximize score */
+ for (i = 0; i < cnum; i++) {
+ l = pegscore(ch[i], Table, Tcnt, sum);
+ if (l > k) {
+ k = l;
+ j = i;
+ }
+ }
+ if (j < 0) /* if nothing scores */
+ j = cchose(ch, cnum, sum);
+ crd = ch[j];
+ cremove(crd, ch, cnum--);
+ sum += VAL(crd.rank);
+ Table[Tcnt++] = crd;
+ if (k > 0) {
+ addmsg(quiet ? "I get %d playing " :
+ "I get %d points playing ", k);
+ msgcard(crd, FALSE);
+ endmsg();
+ if (chkscr(&cscore, k))
+ return TRUE;
+ }
+ myturn = !myturn;
+ }
+ } else {
+ if (!anymove(ph, pnum, sum)) { /* can player move? */
+ if (!ugo && pnum) { /* go for player */
+ msg("You have a GO");
+ ugo = TRUE;
+ }
+ /* can computer play? */
+ if (anymove(ch, cnum, sum))
+ myturn = !myturn;
+ else {
+ msg(quiet ? "I get one" :
+ "I get one point");
+ do_wait();
+ if (chkscr(&cscore, 1))
+ return TRUE;
+ sum = 0;
+ mego = ugo = FALSE;
+ Tcnt = 0;
+ }
+ } else { /* player plays */
+ played = FALSE;
+ if (pnum == 1) {
+ crd = ph[0];
+ msg("You play your last card");
+ } else
+ for (;;) {
+ prhand(ph,
+ pnum, Playwin, FALSE);
+ crd = ph[infrom(ph,
+ pnum, "Your play: ")];
+ if (sum + VAL(crd.rank) <= 31)
+ break;
+ else
+ msg("Total > 31 -- try again");
+ }
+ makeknown(&crd, 1);
+ cremove(crd, ph, pnum--);
+ i = pegscore(crd, Table, Tcnt, sum);
+ sum += VAL(crd.rank);
+ Table[Tcnt++] = crd;
+ if (i > 0) {
+ msg(quiet ? "You got %d" :
+ "You got %d points", i);
+ if (chkscr(&pscore, i))
+ return TRUE;
+ }
+ myturn = !myturn;
}
- }
- if (j < 0) /* if nothing scores */
- j = cchose(ch, cnum, sum);
- crd = ch[j];
- cremove(crd, ch, cnum--);
- sum += VAL(crd.rank);
- Table[Tcnt++] = crd;
- if (k > 0) {
- addmsg(quiet ? "I get %d playing " :
- "I get %d points playing ", k);
- msgcard(crd, FALSE);
- endmsg();
- if (chkscr(&cscore, k))
- return TRUE;
- }
- myturn = !myturn;
}
- }
- else {
- if (!anymove(ph, pnum, sum)) { /* can player move? */
- if (!ugo && pnum) { /* go for player */
- msg("You have a GO");
- ugo = TRUE;
- }
- if (anymove(ch, cnum, sum)) /* can computer play? */
- myturn = !myturn;
- else {
- msg(quiet ? "I get one" : "I get one point");
- do_wait();
- if (chkscr(&cscore, 1))
- return TRUE;
+ if (sum >= 31) {
+ if (!myturn)
+ do_wait();
sum = 0;
mego = ugo = FALSE;
Tcnt = 0;
- }
- }
- else { /* player plays */
- played = FALSE;
- if (pnum == 1) {
- crd = ph[0];
- msg("You play your last card");
- }
- else
- for (;;) {
- prhand(ph, pnum, Playwin, FALSE);
- crd = ph[infrom(ph, pnum, "Your play: ")];
- if (sum + VAL(crd.rank) <= 31)
- break;
- else
- msg("Total > 31 -- try again");
- }
- makeknown(&crd, 1);
- cremove(crd, ph, pnum--);
- i = pegscore(crd, Table, Tcnt, sum);
- sum += VAL(crd.rank);
- Table[Tcnt++] = crd;
- if (i > 0) {
- msg(quiet ? "You got %d" : "You got %d points", i);
- if (chkscr(&pscore, i))
- return TRUE;
- }
- myturn = !myturn;
+ last = FALSE; /* disable last flag */
}
- }
- if (sum >= 31) {
- if (!myturn)
- do_wait();
- sum = 0;
- mego = ugo = FALSE;
- Tcnt = 0;
- last = FALSE; /* disable last flag */
- }
- if (!pnum && !cnum)
- break; /* both done */
+ if (!pnum && !cnum)
+ break; /* both done */
}
prhand(ph, pnum, Playwin, FALSE);
prhand(ch, cnum, Compwin, TRUE);
prtable(sum);
if (last)
- if (played) {
- msg(quiet ? "I get one for last" : "I get one point for last");
- do_wait();
- if (chkscr(&cscore, 1))
- return TRUE;
- }
- else {
- msg(quiet ? "You get one for last" :
+ if (played) {
+ msg(quiet ? "I get one for last" :
+ "I get one point for last");
+ do_wait();
+ if (chkscr(&cscore, 1))
+ return TRUE;
+ } else {
+ msg(quiet ? "You get one for last" :
"You get one point for last");
- if (chkscr(&pscore, 1))
- return TRUE;
- }
- return FALSE;
+ if (chkscr(&pscore, 1))
+ return TRUE;
+ }
+ return (FALSE);
}
/*
* prtable:
* Print out the table with the current score
*/
+void
prtable(score)
-int score;
+ int score;
{
prhand(Table, Tcnt, Tablewin, FALSE);
mvwprintw(Tablewin, (Tcnt + 2) * 2, Tcnt + 1, "%2d", score);
@@ -589,26 +603,26 @@ int score;
* score:
* Handle the scoring of the hands
*/
+int
score(mycrib)
-BOOLEAN mycrib;
+ BOOLEAN mycrib;
{
sorthand(crib, CINHAND);
if (mycrib) {
- if (plyrhand(phand, "hand"))
- return TRUE;
- if (comphand(chand, "hand"))
- return TRUE;
- do_wait();
- if (comphand(crib, "crib"))
- return TRUE;
- }
- else {
- if (comphand(chand, "hand"))
- return TRUE;
- if (plyrhand(phand, "hand"))
- return TRUE;
- if (plyrhand(crib, "crib"))
- return TRUE;
+ if (plyrhand(phand, "hand"))
+ return (TRUE);
+ if (comphand(chand, "hand"))
+ return (TRUE);
+ do_wait();
+ if (comphand(crib, "crib"))
+ return (TRUE);
+ } else {
+ if (comphand(chand, "hand"))
+ return (TRUE);
+ if (plyrhand(phand, "hand"))
+ return (TRUE);
+ if (plyrhand(crib, "crib"))
+ return (TRUE);
}
- return FALSE;
+ return (FALSE);
}
diff --git a/cribbage/cribbage.6 b/cribbage/cribbage.6
index 64694fae..f7be11c1 100644
--- a/cribbage/cribbage.6
+++ b/cribbage/cribbage.6
@@ -1,5 +1,7 @@
-.\" Copyright (c) 1980 Regents of the University of California.
-.\" All rights reserved.
+.\" $NetBSD: cribbage.6,v 1.4 1995/03/21 15:08:45 cgd Exp $
+.\"
+.\" Copyright (c) 1980, 1993
+.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@@ -29,10 +31,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" from: @(#)cribbage.6 6.5 (Berkeley) 6/23/90
-.\" $Id: cribbage.6,v 1.3 1993/08/05 04:02:18 jtc Exp $
+.\" @(#)cribbage.6 8.1 (Berkeley) 5/31/93
.\"
-.Dd June 23, 1990
+.Dd May 31, 1993
.Dt CRIBBAGE 6
.Os
.Sh NAME
diff --git a/cribbage/cribbage.h b/cribbage/cribbage.h
index ffd6bd7d..4ddec968 100644
--- a/cribbage/cribbage.h
+++ b/cribbage/cribbage.h
@@ -1,6 +1,8 @@
+/* $NetBSD: cribbage.h,v 1.3 1995/03/21 15:08:46 cgd Exp $ */
+
/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,8 +32,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * from: @(#)cribbage.h 5.4 (Berkeley) 6/1/90
- * $Id: cribbage.h,v 1.2 1993/08/01 18:55:21 mycroft Exp $
+ * @(#)cribbage.h 8.1 (Berkeley) 5/31/93
*/
extern CARD deck[ CARDS ]; /* a deck */
@@ -60,3 +61,54 @@ extern BOOLEAN playing; /* currently playing game */
extern char expl[]; /* string for explanation */
+void addmsg __P((const char *, ...));
+int adjust __P((CARD [], CARD));
+int anymove __P((CARD [], int, int));
+int anysumto __P((CARD [], int, int, int));
+void bye __P((void));
+int cchose __P((CARD [], int, int));
+void cdiscard __P((BOOLEAN));
+int chkscr __P((int *, int));
+int comphand __P((CARD [], char *));
+void cremove __P((CARD, CARD [], int));
+int cut __P((BOOLEAN, int));
+int deal __P((int));
+void discard __P((BOOLEAN));
+void do_wait __P((void));
+void endmsg __P((void));
+int eq __P((CARD, CARD));
+int fifteens __P((CARD [], int));
+void game __P((void));
+void gamescore __P((void));
+char *getline __P((void));
+int getuchar __P((void));
+int incard __P((CARD *));
+int infrom __P((CARD [], int, char *));
+void instructions __P((void));
+int isone __P((CARD, CARD [], int));
+void makeboard __P((void));
+void makedeck __P((CARD []));
+void makeknown __P((CARD [], int));
+void msg __P((const char *, ...));
+int msgcard __P((CARD, BOOLEAN));
+int msgcrd __P((CARD, BOOLEAN, char *, BOOLEAN));
+int number __P((int, int, char *));
+int numofval __P((CARD [], int, int));
+int pairuns __P((CARD [], int));
+int peg __P((BOOLEAN));
+int pegscore __P((CARD, CARD [], int, int));
+int playhand __P((BOOLEAN));
+int plyrhand __P((CARD [], char *));
+void prcard __P((WINDOW *, int, int, CARD, BOOLEAN));
+void prcrib __P((BOOLEAN, BOOLEAN));
+void prhand __P((CARD [], int, WINDOW *, BOOLEAN));
+void printcard __P((WINDOW *, int, CARD, BOOLEAN));
+void prpeg __P((int, int, BOOLEAN));
+void prtable __P((int));
+int readchar __P((void));
+void rint __P((int));
+int score __P((BOOLEAN));
+int scorehand __P((CARD [], CARD, int, BOOLEAN, BOOLEAN));
+void shuffle __P((CARD []));
+void sorthand __P((CARD [], int));
+void wait_for __P((int));
diff --git a/cribbage/cribcur.h b/cribbage/cribcur.h
index ed099f66..b209f546 100644
--- a/cribbage/cribcur.h
+++ b/cribbage/cribcur.h
@@ -1,6 +1,8 @@
+/* $NetBSD: cribcur.h,v 1.3 1995/03/21 15:08:48 cgd Exp $ */
+
/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,8 +32,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * from: @(#)cribcur.h 5.4 (Berkeley) 6/1/90
- * $Id: cribcur.h,v 1.2 1993/08/01 18:55:20 mycroft Exp $
+ * @(#)cribcur.h 8.1 (Berkeley) 5/31/93
*/
# define PLAY_Y 15 /* size of player's hand window */
diff --git a/cribbage/deck.h b/cribbage/deck.h
index 6d78c818..796175e0 100644
--- a/cribbage/deck.h
+++ b/cribbage/deck.h
@@ -1,6 +1,8 @@
+/* $NetBSD: deck.h,v 1.3 1995/03/21 15:08:49 cgd Exp $ */
+
/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,8 +32,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * from: @(#)deck.h 5.4 (Berkeley) 6/1/90
- * $Id: deck.h,v 1.2 1993/08/01 18:55:18 mycroft Exp $
+ * @(#)deck.h 8.1 (Berkeley) 5/31/93
*/
/*
diff --git a/cribbage/extern.c b/cribbage/extern.c
index f5bf0a84..1b7c4125 100644
--- a/cribbage/extern.c
+++ b/cribbage/extern.c
@@ -1,6 +1,8 @@
-/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+/* $NetBSD: extern.c,v 1.3 1995/03/21 15:08:50 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,13 +34,17 @@
*/
#ifndef lint
-/*static char sccsid[] = "from: @(#)extern.c 5.4 (Berkeley) 6/1/90";*/
-static char rcsid[] = "$Id: extern.c,v 1.2 1993/08/01 18:55:14 mycroft Exp $";
+#if 0
+static char sccsid[] = "@(#)extern.c 8.1 (Berkeley) 5/31/93";
+#else
+static char rcsid[] = "$NetBSD: extern.c,v 1.3 1995/03/21 15:08:50 cgd Exp $";
+#endif
#endif /* not lint */
-# include <curses.h>
-# include "deck.h"
-# include "cribbage.h"
+#include <curses.h>
+
+#include "deck.h"
+#include "cribbage.h"
bool explain = FALSE; /* player mistakes explained */
bool iwon = FALSE; /* if comp won last game */
diff --git a/cribbage/instr.c b/cribbage/instr.c
index 181cc2f6..b4ecda0d 100644
--- a/cribbage/instr.c
+++ b/cribbage/instr.c
@@ -1,6 +1,8 @@
+/* $NetBSD: instr.c,v 1.3 1995/03/21 15:08:52 cgd Exp $ */
+
/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,20 +34,29 @@
*/
#ifndef lint
-/*static char sccsid[] = "from: @(#)instr.c 5.2 (Berkeley) 2/28/91";*/
-static char rcsid[] = "$Id: instr.c,v 1.2 1993/08/01 18:55:13 mycroft Exp $";
+#if 0
+static char sccsid[] = "@(#)instr.c 8.1 (Berkeley) 5/31/93";
+#else
+static char rcsid[] = "$NetBSD: instr.c,v 1.3 1995/03/21 15:08:52 cgd Exp $";
+#endif
#endif /* not lint */
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/errno.h>
#include <sys/stat.h>
-#include <unistd.h>
+
+#include <curses.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+
+#include "deck.h"
+#include "cribbage.h"
#include "pathnames.h"
+void
instructions()
{
extern int errno;
@@ -59,7 +70,7 @@ instructions()
strerror(errno));
exit(1);
}
- switch(pid = vfork()) {
+ switch (pid = vfork()) {
case -1:
(void)fprintf(stderr, "cribbage: %s.\n", strerror(errno));
exit(1);
diff --git a/cribbage/io.c b/cribbage/io.c
index ab1c538d..bdc2d35c 100644
--- a/cribbage/io.c
+++ b/cribbage/io.c
@@ -1,6 +1,8 @@
-/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+/* $NetBSD: io.c,v 1.7 1995/03/21 15:08:53 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,181 +34,103 @@
*/
#ifndef lint
-/*static char sccsid[] = "from: @(#)io.c 5.8 (Berkeley) 2/28/91";*/
-static char rcsid[] = "$Id: io.c,v 1.6 1993/12/08 07:50:47 mycroft Exp $";
+#if 0
+static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 5/31/93";
+#else
+static char rcsid[] = "$NetBSD: io.c,v 1.7 1995/03/21 15:08:53 cgd Exp $";
+#endif
#endif /* not lint */
-# include <curses.h>
-# include <termios.h>
-# include <ctype.h>
-# include <signal.h>
-# include <stdarg.h>
-# include "deck.h"
-# include "cribbage.h"
-# include "cribcur.h"
-
-# define LINESIZE 128
-
-# ifdef CTRL
-# undef CTRL
-# endif
-# define CTRL(X) ('X' - 'A' + 1)
-
-# ifdef notdef /* defined in curses.h */
-# define erasechar() _tty.sg_erase
-# define killchar() _tty.sg_kill
-# endif
-
-char linebuf[ LINESIZE ];
-
-char *rankname[ RANKS ] = { "ACE", "TWO", "THREE", "FOUR",
- "FIVE", "SIX", "SEVEN", "EIGHT",
- "NINE", "TEN", "JACK", "QUEEN",
- "KING" };
-
-char *rankchar[ RANKS ] = { "A", "2", "3", "4", "5", "6", "7",
- "8", "9", "T", "J", "Q", "K" };
-
-char *suitname[ SUITS ] = { "SPADES", "HEARTS", "DIAMONDS",
- "CLUBS" };
-
-char *suitchar[ SUITS ] = { "S", "H", "D", "C" };
-
-
-
-/*
- * msg:
- * Display a message at the top of the screen.
- */
-char Msgbuf[BUFSIZ] = { '\0' };
-
-int Mpos = 0;
+#include <ctype.h>
+#include <curses.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
-static int Newpos = 0;
+#include "deck.h"
+#include "cribbage.h"
+#include "cribcur.h"
-msg(char *fmt, ...)
-{
- va_list ap;
+#define LINESIZE 128
- va_start(ap, fmt);
- (void)vsprintf(&Msgbuf[Newpos], fmt, ap);
- endmsg();
-}
+#ifdef CTRL
+#undef CTRL
+#endif
+#define CTRL(X) (X - 'A' + 1)
-/*
- * addmsg:
- * Add things to the current message
- */
-addmsg(char *fmt, ...)
-{
- va_list ap;
+char linebuf[LINESIZE];
- va_start(ap, fmt);
- (void)vsprintf(&Msgbuf[Newpos], fmt, ap);
-}
+char *rankname[RANKS] = {
+ "ACE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN",
+ "EIGHT", "NINE", "TEN", "JACK", "QUEEN", "KING"
+};
-/*
- * endmsg:
- * Display a new msg.
- */
+char *rankchar[RANKS] = {
+ "A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K"
+};
-int Lineno = 0;
+char *suitname[SUITS] = {"SPADES", "HEARTS", "DIAMONDS", "CLUBS"};
-endmsg()
-{
- register int len;
- register char *mp, *omp;
- static int lastline = 0;
-
- /*
- * All messages should start with uppercase
- */
- mvaddch(lastline + Y_MSG_START, SCORE_X, ' ');
- if (islower(Msgbuf[0]) && Msgbuf[1] != ')')
- Msgbuf[0] = toupper(Msgbuf[0]);
- mp = Msgbuf;
- len = strlen(mp);
- if (len / MSG_X + Lineno >= MSG_Y) {
- while (Lineno < MSG_Y) {
- wmove(Msgwin, Lineno++, 0);
- wclrtoeol(Msgwin);
- }
- Lineno = 0;
- }
- mvaddch(Lineno + Y_MSG_START, SCORE_X, '*');
- lastline = Lineno;
- do {
- mvwaddstr(Msgwin, Lineno, 0, mp);
- if ((len = strlen(mp)) > MSG_X) {
- omp = mp;
- for (mp = &mp[MSG_X-1]; *mp != ' '; mp--)
- continue;
- while (*mp == ' ')
- mp--;
- mp++;
- wmove(Msgwin, Lineno, mp - omp);
- wclrtoeol(Msgwin);
- }
- if (++Lineno >= MSG_Y)
- Lineno = 0;
- } while (len > MSG_X);
- wclrtoeol(Msgwin);
- Mpos = len;
- Newpos = 0;
- wrefresh(Msgwin);
- refresh();
- wrefresh(Msgwin);
-}
+char *suitchar[SUITS] = {"S", "H", "D", "C"};
/*
* msgcard:
* Call msgcrd in one of two forms
*/
+int
msgcard(c, brief)
-CARD c;
-BOOLEAN brief;
+ CARD c;
+ BOOLEAN brief;
{
if (brief)
- return msgcrd(c, TRUE, (char *) NULL, TRUE);
+ return (msgcrd(c, TRUE, NULL, TRUE));
else
- return msgcrd(c, FALSE, " of ", FALSE);
+ return (msgcrd(c, FALSE, " of ", FALSE));
}
-
-
/*
* msgcrd:
* Print the value of a card in ascii
*/
+int
msgcrd(c, brfrank, mid, brfsuit)
-CARD c;
-char *mid;
-BOOLEAN brfrank, brfsuit;
+ CARD c;
+ BOOLEAN brfrank, brfsuit;
+ char *mid;
{
if (c.rank == EMPTY || c.suit == EMPTY)
- return FALSE;
+ return (FALSE);
if (brfrank)
- addmsg("%1.1s", rankchar[c.rank]);
+ addmsg("%1.1s", rankchar[c.rank]);
else
- addmsg(rankname[c.rank]);
+ addmsg(rankname[c.rank]);
if (mid != NULL)
- addmsg(mid);
+ addmsg(mid);
if (brfsuit)
- addmsg("%1.1s", suitchar[c.suit]);
+ addmsg("%1.1s", suitchar[c.suit]);
else
- addmsg(suitname[c.suit]);
- return TRUE;
+ addmsg(suitname[c.suit]);
+ return (TRUE);
}
/*
* printcard:
* Print out a card.
*/
+void
printcard(win, cardno, c, blank)
-WINDOW *win;
-int cardno;
-CARD c;
-BOOLEAN blank;
+ WINDOW *win;
+ int cardno;
+ CARD c;
+ BOOLEAN blank;
{
prcard(win, cardno * 2, cardno, c, blank);
}
@@ -215,14 +139,16 @@ BOOLEAN blank;
* prcard:
* Print out a card on the window at the specified location
*/
+void
prcard(win, y, x, c, blank)
-WINDOW *win;
-int y, x;
-CARD c;
-BOOLEAN blank;
+ WINDOW *win;
+ int y, x;
+ CARD c;
+ BOOLEAN blank;
{
if (c.rank == EMPTY)
- return;
+ return;
+
mvwaddstr(win, y + 0, x, "+-----+");
mvwaddstr(win, y + 1, x, "| |");
mvwaddstr(win, y + 2, x, "| |");
@@ -240,171 +166,177 @@ BOOLEAN blank;
* prhand:
* Print a hand of n cards
*/
+void
prhand(h, n, win, blank)
-CARD h[];
-int n;
-WINDOW *win;
-BOOLEAN blank;
+ CARD h[];
+ int n;
+ WINDOW *win;
+ BOOLEAN blank;
{
- register int i;
+ register int i;
werase(win);
for (i = 0; i < n; i++)
- printcard(win, i, *h++, blank);
+ printcard(win, i, *h++, blank);
wrefresh(win);
}
-
-
/*
* infrom:
* reads a card, supposedly in hand, accepting unambigous brief
* input, returns the index of the card found...
*/
+int
infrom(hand, n, prompt)
-CARD hand[];
-int n;
-char *prompt;
+ CARD hand[];
+ int n;
+ char *prompt;
{
- register int i, j;
- CARD crd;
+ register int i, j;
+ CARD crd;
if (n < 1) {
- printf("\nINFROM: %d = n < 1!!\n", n);
- exit(74);
+ printf("\nINFROM: %d = n < 1!!\n", n);
+ exit(74);
}
for (;;) {
- msg(prompt);
- if (incard(&crd)) { /* if card is full card */
- if (!isone(crd, hand, n))
- msg("That's not in your hand");
- else {
- for (i = 0; i < n; i++)
- if (hand[i].rank == crd.rank &&
- hand[i].suit == crd.suit)
- break;
- if (i >= n) {
+ msg(prompt);
+ if (incard(&crd)) { /* if card is full card */
+ if (!isone(crd, hand, n))
+ msg("That's not in your hand");
+ else {
+ for (i = 0; i < n; i++)
+ if (hand[i].rank == crd.rank &&
+ hand[i].suit == crd.suit)
+ break;
+ if (i >= n) {
printf("\nINFROM: isone or something messed up\n");
- exit(77);
- }
- return i;
- }
- }
- else /* if not full card... */
- if (crd.rank != EMPTY) {
- for (i = 0; i < n; i++)
- if (hand[i].rank == crd.rank)
- break;
- if (i >= n)
- msg("No such rank in your hand");
- else {
- for (j = i + 1; j < n; j++)
- if (hand[j].rank == crd.rank)
- break;
- if (j < n)
- msg("Ambiguous rank");
- else
- return i;
- }
- }
- else
- msg("Sorry, I missed that");
+ exit(77);
+ }
+ return (i);
+ }
+ } else /* if not full card... */
+ if (crd.rank != EMPTY) {
+ for (i = 0; i < n; i++)
+ if (hand[i].rank == crd.rank)
+ break;
+ if (i >= n)
+ msg("No such rank in your hand");
+ else {
+ for (j = i + 1; j < n; j++)
+ if (hand[j].rank == crd.rank)
+ break;
+ if (j < n)
+ msg("Ambiguous rank");
+ else
+ return (i);
+ }
+ } else
+ msg("Sorry, I missed that");
}
/* NOTREACHED */
}
-
-
/*
* incard:
* Inputs a card in any format. It reads a line ending with a CR
* and then parses it.
*/
+int
incard(crd)
-CARD *crd;
+ CARD *crd;
{
- char *getline();
- register int i;
- int rnk, sut;
- char *line, *p, *p1;
- BOOLEAN retval;
+ register int i;
+ int rnk, sut;
+ char *line, *p, *p1;
+ BOOLEAN retval;
retval = FALSE;
rnk = sut = EMPTY;
if (!(line = getline()))
goto gotit;
p = p1 = line;
- while( *p1 != ' ' && *p1 != NULL ) ++p1;
+ while (*p1 != ' ' && *p1 != NULL)
+ ++p1;
*p1++ = NULL;
- if( *p == NULL ) goto gotit;
- /* IMPORTANT: no real card has 2 char first name */
- if( strlen(p) == 2 ) { /* check for short form */
- rnk = EMPTY;
- for( i = 0; i < RANKS; i++ ) {
- if( *p == *rankchar[i] ) {
- rnk = i;
- break;
+ if (*p == NULL)
+ goto gotit;
+
+ /* IMPORTANT: no real card has 2 char first name */
+ if (strlen(p) == 2) { /* check for short form */
+ rnk = EMPTY;
+ for (i = 0; i < RANKS; i++) {
+ if (*p == *rankchar[i]) {
+ rnk = i;
+ break;
+ }
}
- }
- if( rnk == EMPTY ) goto gotit; /* it's nothing... */
- ++p; /* advance to next char */
- sut = EMPTY;
- for( i = 0; i < SUITS; i++ ) {
- if( *p == *suitchar[i] ) {
- sut = i;
- break;
+ if (rnk == EMPTY)
+ goto gotit; /* it's nothing... */
+ ++p; /* advance to next char */
+ sut = EMPTY;
+ for (i = 0; i < SUITS; i++) {
+ if (*p == *suitchar[i]) {
+ sut = i;
+ break;
+ }
}
- }
- if( sut != EMPTY ) retval = TRUE;
- goto gotit;
+ if (sut != EMPTY)
+ retval = TRUE;
+ goto gotit;
}
rnk = EMPTY;
- for( i = 0; i < RANKS; i++ ) {
- if( !strcmp( p, rankname[i] ) || !strcmp( p, rankchar[i] ) ) {
- rnk = i;
- break;
- }
+ for (i = 0; i < RANKS; i++) {
+ if (!strcmp(p, rankname[i]) || !strcmp(p, rankchar[i])) {
+ rnk = i;
+ break;
+ }
}
- if( rnk == EMPTY ) goto gotit;
+ if (rnk == EMPTY)
+ goto gotit;
p = p1;
- while( *p1 != ' ' && *p1 != NULL ) ++p1;
+ while (*p1 != ' ' && *p1 != NULL)
+ ++p1;
*p1++ = NULL;
- if( *p == NULL ) goto gotit;
- if( !strcmp( "OF", p ) ) {
- p = p1;
- while( *p1 != ' ' && *p1 != NULL ) ++p1;
- *p1++ = NULL;
- if( *p == NULL ) goto gotit;
+ if (*p == NULL)
+ goto gotit;
+ if (!strcmp("OF", p)) {
+ p = p1;
+ while (*p1 != ' ' && *p1 != NULL)
+ ++p1;
+ *p1++ = NULL;
+ if (*p == NULL)
+ goto gotit;
}
sut = EMPTY;
- for( i = 0; i < SUITS; i++ ) {
- if( !strcmp( p, suitname[i] ) || !strcmp( p, suitchar[i] ) ) {
- sut = i;
- break;
- }
+ for (i = 0; i < SUITS; i++) {
+ if (!strcmp(p, suitname[i]) || !strcmp(p, suitchar[i])) {
+ sut = i;
+ break;
+ }
}
- if( sut != EMPTY ) retval = TRUE;
+ if (sut != EMPTY)
+ retval = TRUE;
gotit:
(*crd).rank = rnk;
(*crd).suit = sut;
- return( retval );
+ return (retval);
}
-
-
/*
* getuchar:
* Reads and converts to upper case
*/
+int
getuchar()
{
- register int c;
+ register int c;
c = readchar();
if (islower(c))
- c = toupper(c);
+ c = toupper(c);
waddch(Msgwin, c);
- return c;
+ return (c);
}
/*
@@ -412,129 +344,213 @@ getuchar()
* Reads in a decimal number and makes sure it is between "lo" and
* "hi" inclusive.
*/
+int
number(lo, hi, prompt)
-int lo, hi;
-char *prompt;
+ int lo, hi;
+ char *prompt;
{
- char *getline();
- register char *p;
- register int sum;
-
- sum = 0;
- for (;;) {
- msg(prompt);
- if(!(p = getline()) || *p == NULL) {
- msg(quiet ? "Not a number" : "That doesn't look like a number");
- continue;
- }
- sum = 0;
-
- if (!isdigit(*p))
- sum = lo - 1;
- else
- while (isdigit(*p)) {
- sum = 10 * sum + (*p - '0');
- ++p;
+ register char *p;
+ register int sum;
+
+ for (sum = 0;;) {
+ msg(prompt);
+ if (!(p = getline()) || *p == NULL) {
+ msg(quiet ? "Not a number" :
+ "That doesn't look like a number");
+ continue;
}
+ sum = 0;
- if (*p != ' ' && *p != '\t' && *p != NULL)
- sum = lo - 1;
- if (sum >= lo && sum <= hi)
- return sum;
- if (sum == lo - 1)
- msg("that doesn't look like a number, try again --> ");
- else
+ if (!isdigit(*p))
+ sum = lo - 1;
+ else
+ while (isdigit(*p)) {
+ sum = 10 * sum + (*p - '0');
+ ++p;
+ }
+
+ if (*p != ' ' && *p != '\t' && *p != NULL)
+ sum = lo - 1;
+ if (sum >= lo && sum <= hi)
+ break;
+ if (sum == lo - 1)
+ msg("that doesn't look like a number, try again --> ");
+ else
msg("%d is not between %d and %d inclusive, try again --> ",
- sum, lo, hi);
+ sum, lo, hi);
}
+ return (sum);
}
-#ifdef notdef
/*
- * doadd:
- * Perform an add onto the message buffer
+ * msg:
+ * Display a message at the top of the screen.
*/
-doadd(fmt, args)
-char *fmt;
-int *args;
+char Msgbuf[BUFSIZ] = {'\0'};
+int Mpos = 0;
+static int Newpos = 0;
+
+void
+#if __STDC__
+msg(const char *fmt, ...)
+#else
+msg(fmt, va_alist)
+ char *fmt;
+ va_dcl
+#endif
{
- static FILE junk;
-
- /*
- * Do the printf into Msgbuf
- */
- junk._flag = _IOWRT + _IOSTRG;
- junk._ptr = &Msgbuf[Newpos];
- junk._cnt = 32767;
- _doprnt(fmt, args, &junk);
- putc('\0', &junk);
- Newpos = strlen(Msgbuf);
+ va_list ap;
+
+#if __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ (void)vsprintf(&Msgbuf[Newpos], fmt, ap);
+ va_end(ap);
+ endmsg();
}
+
+/*
+ * addmsg:
+ * Add things to the current message
+ */
+void
+#if __STDC__
+addmsg(const char *fmt, ...)
+#else
+addmsg(fmt, va_alist)
+ char *fmt;
+ va_dcl
#endif
+{
+ va_list ap;
+
+#if __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ (void)vsprintf(&Msgbuf[Newpos], fmt, ap);
+ va_end(ap);
+}
+
+/*
+ * endmsg:
+ * Display a new msg.
+ */
+int Lineno = 0;
+
+void
+endmsg()
+{
+ static int lastline = 0;
+ register int len;
+ register char *mp, *omp;
+
+ /* All messages should start with uppercase */
+ mvaddch(lastline + Y_MSG_START, SCORE_X, ' ');
+ if (islower(Msgbuf[0]) && Msgbuf[1] != ')')
+ Msgbuf[0] = toupper(Msgbuf[0]);
+ mp = Msgbuf;
+ len = strlen(mp);
+ if (len / MSG_X + Lineno >= MSG_Y) {
+ while (Lineno < MSG_Y) {
+ wmove(Msgwin, Lineno++, 0);
+ wclrtoeol(Msgwin);
+ }
+ Lineno = 0;
+ }
+ mvaddch(Lineno + Y_MSG_START, SCORE_X, '*');
+ lastline = Lineno;
+ do {
+ mvwaddstr(Msgwin, Lineno, 0, mp);
+ if ((len = strlen(mp)) > MSG_X) {
+ omp = mp;
+ for (mp = &mp[MSG_X - 1]; *mp != ' '; mp--)
+ continue;
+ while (*mp == ' ')
+ mp--;
+ mp++;
+ wmove(Msgwin, Lineno, mp - omp);
+ wclrtoeol(Msgwin);
+ }
+ if (++Lineno >= MSG_Y)
+ Lineno = 0;
+ } while (len > MSG_X);
+ wclrtoeol(Msgwin);
+ Mpos = len;
+ Newpos = 0;
+ wrefresh(Msgwin);
+ refresh();
+ wrefresh(Msgwin);
+}
/*
* do_wait:
* Wait for the user to type ' ' before doing anything else
*/
+void
do_wait()
{
- register int line;
- static char prompt[] = { '-', '-', 'M', 'o', 'r', 'e', '-', '-', '\0' };
+ static char prompt[] = {'-', '-', 'M', 'o', 'r', 'e', '-', '-', '\0'};
- if (Mpos + sizeof prompt < MSG_X)
- wmove(Msgwin, Lineno > 0 ? Lineno - 1 : MSG_Y - 1, Mpos);
- else {
- mvwaddch(Msgwin, Lineno, 0, ' ');
- wclrtoeol(Msgwin);
- if (++Lineno >= MSG_Y)
- Lineno = 0;
- }
- waddstr(Msgwin, prompt);
- wrefresh(Msgwin);
- wait_for(' ');
+ if (Mpos + sizeof prompt < MSG_X)
+ wmove(Msgwin, Lineno > 0 ? Lineno - 1 : MSG_Y - 1, Mpos);
+ else {
+ mvwaddch(Msgwin, Lineno, 0, ' ');
+ wclrtoeol(Msgwin);
+ if (++Lineno >= MSG_Y)
+ Lineno = 0;
+ }
+ waddstr(Msgwin, prompt);
+ wrefresh(Msgwin);
+ wait_for(' ');
}
/*
* wait_for
* Sit around until the guy types the right key
*/
+void
wait_for(ch)
-register char ch;
+ register int ch;
{
- register char c;
-
- if (ch == '\n')
- while ((c = readchar()) != '\n')
- continue;
- else
- while (readchar() != ch)
- continue;
+ register char c;
+
+ if (ch == '\n')
+ while ((c = readchar()) != '\n')
+ continue;
+ else
+ while (readchar() != ch)
+ continue;
}
/*
* readchar:
* Reads and returns a character, checking for gross input errors
*/
+int
readchar()
{
- register int cnt, y, x;
- auto char c;
+ register int cnt;
+ char c;
over:
- cnt = 0;
- while (read(0, &c, 1) <= 0)
- if (cnt++ > 100) { /* if we are getting infinite EOFs */
- bye(); /* quit the game */
- exit(1);
+ cnt = 0;
+ while (read(STDIN_FILENO, &c, sizeof(char)) <= 0)
+ if (cnt++ > 100) { /* if we are getting infinite EOFs */
+ bye(); /* quit the game */
+ exit(1);
+ }
+ if (c == CTRL('L')) {
+ wrefresh(curscr);
+ goto over;
}
- if (c == CTRL(L)) {
- wrefresh(curscr);
- goto over;
- }
- if (c == '\r')
- return '\n';
- else
- return c;
+ if (c == '\r')
+ return ('\n');
+ else
+ return (c);
}
/*
@@ -545,53 +561,55 @@ over:
char *
getline()
{
- register char *sp;
- register int c, oy, ox;
- register WINDOW *oscr;
-
- oscr = stdscr;
- stdscr = Msgwin;
- getyx(stdscr, oy, ox);
- refresh();
- /*
- * loop reading in the string, and put it in a temporary buffer
- */
- for (sp = linebuf; (c = readchar()) != '\n'; clrtoeol(), refresh()) {
- if (c == -1)
- continue;
- else if (c == erasechar()) { /* process erase character */
- if (sp > linebuf) {
- register int i;
-
- sp--;
- for (i = strlen(unctrl(*sp)); i; i--)
- addch('\b');
- }
- continue;
- }
- else if (c == killchar()) { /* process kill character */
- sp = linebuf;
- move(oy, ox);
- continue;
- }
- else if (sp == linebuf && c == ' ')
- continue;
- if (sp >= &linebuf[LINESIZE-1] || !(isprint(c) || c == ' '))
- putchar(CTRL(G));
- else {
- if (islower(c))
- c = toupper(c);
- *sp++ = c;
- addstr(unctrl(c));
- Mpos++;
+ register char *sp;
+ register int c, oy, ox;
+ register WINDOW *oscr;
+
+ oscr = stdscr;
+ stdscr = Msgwin;
+ getyx(stdscr, oy, ox);
+ refresh();
+ /* loop reading in the string, and put it in a temporary buffer */
+ for (sp = linebuf; (c = readchar()) != '\n'; clrtoeol(), refresh()) {
+ if (c == -1)
+ continue;
+ else
+ if (c == erasechar()) { /* process erase character */
+ if (sp > linebuf) {
+ register int i;
+
+ sp--;
+ for (i = strlen(unctrl(*sp)); i; i--)
+ addch('\b');
+ }
+ continue;
+ } else
+ if (c == killchar()) { /* process kill
+ * character */
+ sp = linebuf;
+ move(oy, ox);
+ continue;
+ } else
+ if (sp == linebuf && c == ' ')
+ continue;
+ if (sp >= &linebuf[LINESIZE - 1] || !(isprint(c) || c == ' '))
+ putchar(CTRL('G'));
+ else {
+ if (islower(c))
+ c = toupper(c);
+ *sp++ = c;
+ addstr(unctrl(c));
+ Mpos++;
+ }
}
- }
- *sp = '\0';
- stdscr = oscr;
- return linebuf;
+ *sp = '\0';
+ stdscr = oscr;
+ return (linebuf);
}
-rint()
+void
+rint(signo)
+ int signo;
{
bye();
exit(1);
@@ -601,6 +619,7 @@ rint()
* bye:
* Leave the program, cleaning things up as we go.
*/
+void
bye()
{
signal(SIGINT, SIG_IGN);
diff --git a/cribbage/pathnames.h b/cribbage/pathnames.h
index 6c26900b..70f9f183 100644
--- a/cribbage/pathnames.h
+++ b/cribbage/pathnames.h
@@ -1,6 +1,8 @@
+/* $NetBSD: pathnames.h,v 1.3 1995/03/21 15:08:56 cgd Exp $ */
+
/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,10 +32,9 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * from: @(#)pathnames.h 5.1 (Berkeley) 5/1/90
- * $Id: pathnames.h,v 1.2 1993/08/01 18:55:17 mycroft Exp $
+ * @(#)pathnames.h 8.1 (Berkeley) 5/31/93
*/
+#define _PATH_INSTR "/usr/share/games/cribbage.instr"
#define _PATH_LOG "/var/games/criblog"
#define _PATH_MORE "/usr/bin/more"
-#define _PATH_INSTR "/usr/share/games/cribbage.instr"
diff --git a/cribbage/score.c b/cribbage/score.c
index d3fddd9a..93f8c075 100644
--- a/cribbage/score.c
+++ b/cribbage/score.c
@@ -1,6 +1,8 @@
-/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+/* $NetBSD: score.c,v 1.3 1995/03/21 15:08:57 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,14 +34,20 @@
*/
#ifndef lint
-/*static char sccsid[] = "from: @(#)score.c 5.5 (Berkeley) 6/1/90";*/
-static char rcsid[] = "$Id: score.c,v 1.2 1993/08/01 18:55:11 mycroft Exp $";
+#if 0
+static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93";
+#else
+static char rcsid[] = "$NetBSD: score.c,v 1.3 1995/03/21 15:08:57 cgd Exp $";
+#endif
#endif /* not lint */
-#include <stdio.h>
-#include "deck.h"
-#include "cribbage.h"
+#include <curses.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "deck.h"
+#include "cribbage.h"
/*
* the following arrays give the sum of the scores of the (50 2)*48 = 58800
@@ -47,8 +55,7 @@ static char rcsid[] = "$Id: score.c,v 1.2 1993/08/01 18:55:11 mycroft Exp $";
* array. the two arrays are for the case where the suits are equal and
* not equal respectively
*/
-
-long crbescr[ 169 ] = {
+long crbescr[169] = {
-10000, 271827, 278883, 332319, 347769, 261129, 250653, 253203, 248259,
243435, 256275, 237435, 231051, -10000, -10000, 412815, 295707, 349497,
267519, 262521, 259695, 254019, 250047, 262887, 244047, 237663, -10000,
@@ -67,9 +74,10 @@ long crbescr[ 169 ] = {
-10000, -10000, -10000, -10000, -10000, -10000, 304287, 262971, -10000,
-10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000,
-10000, -10000, 244131, -10000, -10000, -10000, -10000, -10000, -10000,
- -10000, -10000, -10000, -10000, -10000, -10000, -10000 };
+ -10000, -10000, -10000, -10000, -10000, -10000, -10000
+};
-long crbnescr[ 169 ] = {
+long crbnescr[169] = {
325272, 260772, 267828, 321264, 336714, 250074, 239598, 242148, 237204,
232380, 246348, 226380, 219996, -10000, 342528, 401760, 284652, 338442,
256464, 251466, 248640, 242964, 238992, 252960, 232992, 226608, -10000,
@@ -88,147 +96,142 @@ long crbnescr[ 169 ] = {
-10000, -10000, -10000, -10000, -10000, 348600, 294360, 253044, -10000,
-10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000, -10000,
-10000, 308664, 233076, -10000, -10000, -10000, -10000, -10000, -10000,
- -10000, -10000, -10000, -10000, -10000, -10000, 295896 };
-
-
-static int ichoose2[ 5 ] = { 0, 0, 2, 6, 12 };
-static int pairpoints, runpoints; /* globals from pairuns */
+ -10000, -10000, -10000, -10000, -10000, -10000, 295896
+};
+static int ichoose2[5] = { 0, 0, 2, 6, 12 };
+static int pairpoints, runpoints; /* Globals from pairuns. */
/*
* scorehand:
* Score the given hand of n cards and the starter card.
* n must be <= 4
*/
+int
scorehand(hand, starter, n, crb, do_explain)
-register CARD hand[];
-CARD starter;
-int n;
-BOOLEAN crb; /* true if scoring crib */
-BOOLEAN do_explain; /* true if must explain this hand */
+ register CARD hand[];
+ CARD starter;
+ int n;
+ BOOLEAN crb; /* true if scoring crib */
+ BOOLEAN do_explain; /* true if must explain this hand */
{
- CARD h[(CINHAND + 1)];
- register int i, k;
- register int score;
- register BOOLEAN flag;
- char buf[32];
+ register int i, k;
+ register int score;
+ register BOOLEAN flag;
+ CARD h[(CINHAND + 1)];
+ char buf[32];
expl[0] = NULL; /* initialize explanation */
score = 0;
flag = TRUE;
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].suit == starter.suit) {
- score++;
- if (do_explain)
- strcat(expl, "His Nobs");
- }
- h[i] = hand[i];
+ 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].suit == starter.suit) {
+ score++;
+ if (do_explain)
+ strcat(expl, "His Nobs");
+ }
+ h[i] = hand[i];
}
if (flag && n >= CINHAND) {
- if (do_explain && expl[0] != NULL)
- strcat(expl, ", ");
- if (starter.suit == k) {
- score += 5;
- if (do_explain)
- strcat(expl, "Five-flush");
- }
- else if (!crb) {
- score += 4;
if (do_explain && expl[0] != NULL)
- strcat(expl, ", Four-flush");
- else
- strcpy(expl, "Four-flush");
- }
+ strcat(expl, ", ");
+ if (starter.suit == k) {
+ score += 5;
+ if (do_explain)
+ strcat(expl, "Five-flush");
+ } else
+ if (!crb) {
+ score += 4;
+ if (do_explain && expl[0] != NULL)
+ strcat(expl, ", Four-flush");
+ else
+ strcpy(expl, "Four-flush");
+ }
}
-
if (do_explain && expl[0] != NULL)
- strcat(expl, ", ");
+ strcat(expl, ", ");
h[n] = starter;
- sorthand(h, n + 1); /* sort by rank */
+ sorthand(h, n + 1); /* sort by rank */
i = 2 * fifteens(h, n + 1);
score += i;
if (do_explain)
- if (i > 0) {
- (void)sprintf(buf, "%d points in fifteens", i);
- strcat(expl, buf);
- }
- else
- strcat(expl, "No fifteens");
+ if (i > 0) {
+ (void) sprintf(buf, "%d points in fifteens", i);
+ strcat(expl, buf);
+ } else
+ strcat(expl, "No fifteens");
i = pairuns(h, n + 1);
score += i;
if (do_explain)
- if (i > 0) {
- (void)sprintf(buf, ", %d points in pairs, %d in runs",
- pairpoints, runpoints);
- strcat(expl, buf);
- }
- else
- strcat(expl, ", No pairs/runs");
- return score;
+ if (i > 0) {
+ (void) sprintf(buf, ", %d points in pairs, %d in runs",
+ pairpoints, runpoints);
+ strcat(expl, buf);
+ } else
+ strcat(expl, ", No pairs/runs");
+ return (score);
}
/*
* fifteens:
* Return number of fifteens in hand of n cards
*/
+int
fifteens(hand, n)
-register CARD hand[];
-int n;
+ register CARD hand[];
+ int n;
{
- register int *sp, *np;
- register int i;
- register CARD *endp;
- static int sums[15], nsums[15];
+ register int *sp, *np;
+ register int i;
+ register CARD *endp;
+ static int sums[15], nsums[15];
np = nsums;
sp = sums;
i = 16;
while (--i) {
- *np++ = 0;
- *sp++ = 0;
+ *np++ = 0;
+ *sp++ = 0;
}
for (endp = &hand[n]; hand < endp; hand++) {
- i = hand->rank + 1;
- if (i > 10)
- i = 10;
- np = &nsums[i];
- np[-1]++; /* one way to make this */
- sp = sums;
- while (i < 15) {
- *np++ += *sp++;
- i++;
- }
- sp = sums;
- np = nsums;
- i = 16;
- while (--i)
- *sp++ = *np++;
+ i = hand->rank + 1;
+ if (i > 10)
+ i = 10;
+ np = &nsums[i];
+ np[-1]++; /* one way to make this */
+ sp = sums;
+ while (i < 15) {
+ *np++ += *sp++;
+ i++;
+ }
+ sp = sums;
+ np = nsums;
+ i = 16;
+ while (--i)
+ *sp++ = *np++;
}
return sums[14];
}
-
-
/*
* pairuns returns the number of points in the n card sorted hand
* due to pairs and runs
* this routine only works if n is strictly less than 6
* sets the globals pairpoints and runpoints appropriately
*/
-
-pairuns( h, n )
-
- CARD h[];
- int n;
+int
+pairuns(h, n)
+ CARD h[];
+ int n;
{
- register int i;
- int runlength, runmult, lastmult, curmult;
- int mult1, mult2, pair1, pair2;
- BOOLEAN run;
+ register int i;
+ int runlength, runmult, lastmult, curmult;
+ int mult1, mult2, pair1, pair2;
+ BOOLEAN run;
run = TRUE;
runlength = 1;
@@ -237,129 +240,134 @@ pairuns( h, n )
mult2 = 1;
pair2 = -1;
curmult = runmult = 1;
- for( i = 1; i < n; i++ ) {
- lastmult = curmult;
- if( h[i].rank == h[i - 1].rank ) {
- if( pair1 < 0 ) {
- pair1 = h[i].rank;
- mult1 = curmult = 2;
- }
- else {
- if( h[i].rank == pair1 ) {
- curmult = ++mult1;
- }
- else {
- if( pair2 < 0 ) {
- pair2 = h[i].rank;
- mult2 = curmult = 2;
+ for (i = 1; i < n; i++) {
+ lastmult = curmult;
+ if (h[i].rank == h[i - 1].rank) {
+ if (pair1 < 0) {
+ pair1 = h[i].rank;
+ mult1 = curmult = 2;
+ } else {
+ if (h[i].rank == pair1) {
+ curmult = ++mult1;
+ } else {
+ if (pair2 < 0) {
+ pair2 = h[i].rank;
+ mult2 = curmult = 2;
+ } else {
+ curmult = ++mult2;
+ }
+ }
}
- else {
- curmult = ++mult2;
+ if (i == (n - 1) && run) {
+ runmult *= curmult;
}
- }
- }
- if( i == (n - 1) && run ) {
- runmult *= curmult;
- }
- }
- else {
- curmult = 1;
- if( h[i].rank == h[i - 1].rank + 1 ) {
- if( run ) {
- ++runlength;
- }
- else {
- if( runlength < 3 ) { /* only if old short */
- run = TRUE;
- runlength = 2;
- runmult = 1;
+ } else {
+ curmult = 1;
+ if (h[i].rank == h[i - 1].rank + 1) {
+ if (run) {
+ ++runlength;
+ } else {
+ /* only if old short */
+ if (runlength < 3) {
+ run = TRUE;
+ runlength = 2;
+ runmult = 1;
+ }
+ }
+ runmult *= lastmult;
+ } else {
+ /* if just ended */
+ if (run)
+ runmult *= lastmult;
+ run = FALSE;
}
- }
- runmult *= lastmult;
- }
- else {
- if( run ) runmult *= lastmult; /* if just ended */
- run = FALSE;
}
- }
}
- pairpoints = ichoose2[ mult1 ] + ichoose2[ mult2 ];
- runpoints = ( runlength >= 3 ? runlength*runmult : 0 );
- return( pairpoints + runpoints );
+ pairpoints = ichoose2[mult1] + ichoose2[mult2];
+ runpoints = (runlength >= 3 ? runlength * runmult : 0);
+ return (pairpoints + runpoints);
}
-
-
/*
* pegscore tells how many points crd would get if played after
* the n cards in tbl during pegging
*/
-
-pegscore( crd, tbl, n, sum )
-
- CARD crd, tbl[];
- int n;
- int sum;
+int
+pegscore(crd, tbl, n, sum)
+ CARD crd, tbl[];
+ int n, sum;
{
- BOOLEAN got[ RANKS ];
- register int i, j, scr;
- int k, lo, hi;
-
- sum += VAL( crd.rank );
- if( sum > 31 ) return( -1 );
- if( sum == 31 || sum == 15 ) scr = 2;
- else scr = 0;
- if( !n ) return( scr );
+ BOOLEAN got[RANKS];
+ register int i, j, scr;
+ int k, lo, hi;
+
+ sum += VAL(crd.rank);
+ if (sum > 31)
+ return (-1);
+ if (sum == 31 || sum == 15)
+ scr = 2;
+ else
+ scr = 0;
+ if (!n)
+ return (scr);
j = 1;
- while( ( crd.rank == tbl[n - j].rank ) && ( n - j >= 0 ) ) ++j;
- if( j > 1 ) return( scr + ichoose2[j] );
- if( n < 2 ) return( scr );
+ while ((crd.rank == tbl[n - j].rank) && (n - j >= 0))
+ ++j;
+ if (j > 1)
+ return (scr + ichoose2[j]);
+ if (n < 2)
+ return (scr);
lo = hi = crd.rank;
- for( i = 0; i < RANKS; i++ ) got[i] = FALSE;
- got[ crd.rank ] = TRUE;
+ for (i = 0; i < RANKS; i++)
+ got[i] = FALSE;
+ got[crd.rank] = TRUE;
k = -1;
- for( i = n - 1; i >= 0; --i ) {
- if( got[ tbl[i].rank ] ) break;
- got[ tbl[i].rank ] = TRUE;
- if( tbl[i].rank < lo ) lo = tbl[i].rank;
- if( tbl[i].rank > hi ) hi = tbl[i].rank;
- for( j = lo; j <= hi; j++ ) if( !got[j] ) break;
- if( j > hi ) k = hi - lo + 1;
+ for (i = n - 1; i >= 0; --i) {
+ if (got[tbl[i].rank])
+ break;
+ got[tbl[i].rank] = TRUE;
+ if (tbl[i].rank < lo)
+ lo = tbl[i].rank;
+ if (tbl[i].rank > hi)
+ hi = tbl[i].rank;
+ for (j = lo; j <= hi; j++)
+ if (!got[j])
+ break;
+ if (j > hi)
+ k = hi - lo + 1;
}
- if( k >= 3 ) return( scr + k );
- else return( scr );
+ if (k >= 3)
+ return (scr + k);
+ else
+ return (scr);
}
-
-
/*
* adjust takes a two card hand that will be put in the crib
* and returns an adjusted normalized score for the number of
* points such a crib will get.
*/
-
-adjust( cb, tnv )
-
- CARD cb[], tnv;
+int
+adjust(cb, tnv)
+ CARD cb[], tnv;
{
- int i, c0, c1;
- long scr;
+ long scr;
+ int i, c0, c1;
c0 = cb[0].rank;
c1 = cb[1].rank;
- if( c0 > c1 ) {
- i = c0;
- c0 = c1;
- c1 = i;
+ if (c0 > c1) {
+ i = c0;
+ c0 = c1;
+ c1 = i;
}
- if( cb[0].suit != cb[1].suit ) scr = crbnescr[ RANKS*c0 + c1 ];
- else scr = crbescr[ RANKS*c0 + c1 ];
- if( scr <= 0 ) {
- printf( "\nADJUST: internal error %d %d\n", c0, c1 );
- exit( 93 );
+ if (cb[0].suit != cb[1].suit)
+ scr = crbnescr[RANKS * c0 + c1];
+ else
+ scr = crbescr[RANKS * c0 + c1];
+ if (scr <= 0) {
+ printf("\nADJUST: internal error %d %d\n", c0, c1);
+ exit(93);
}
- return( (scr + 29400)/58800 );
+ return ((scr + 29400) / 58800);
}
-
-
-
diff --git a/cribbage/support.c b/cribbage/support.c
index 86ac6a52..a2064a21 100644
--- a/cribbage/support.c
+++ b/cribbage/support.c
@@ -1,6 +1,8 @@
-/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+/* $NetBSD: support.c,v 1.3 1995/03/21 15:08:59 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,134 +34,145 @@
*/
#ifndef lint
-/*static char sccsid[] = "from: @(#)support.c 5.6 (Berkeley) 2/28/91";*/
-static char rcsid[] = "$Id: support.c,v 1.2 1993/08/01 18:55:09 mycroft Exp $";
+#if 0
+static char sccsid[] = "@(#)support.c 8.1 (Berkeley) 5/31/93";
+#else
+static char rcsid[] = "$NetBSD: support.c,v 1.3 1995/03/21 15:08:59 cgd Exp $";
+#endif
#endif /* not lint */
-#include <curses.h>
-#include "deck.h"
-#include "cribbage.h"
-#include "cribcur.h"
+#include <curses.h>
+#include <string.h>
+#include "deck.h"
+#include "cribbage.h"
+#include "cribcur.h"
-#define NTV 10 /* number scores to test */
+#define NTV 10 /* number scores to test */
/* score to test reachability of, and order to test them in */
-int tv[ NTV ] = { 8, 7, 9, 6, 11, 12, 13, 14, 10, 5 };
-
+int tv[NTV] = {8, 7, 9, 6, 11, 12, 13, 14, 10, 5};
/*
* computer chooses what to play in pegging...
* only called if no playable card will score points
*/
-
-cchose( h, n, s )
-
- CARD h[];
- int n;
- int s;
+int
+cchose(h, n, s)
+ CARD h[];
+ int n, s;
{
- register int i, j, l;
-
- if( n <= 1 ) return( 0 );
- if( s < 4 ) { /* try for good value */
- if( ( j = anysumto(h, n, s, 4) ) >= 0 ) return( j );
- if( ( j = anysumto(h, n, s, 3) ) >= 0 && s == 0 )
- return( j );
+ register int i, j, l;
+
+ if (n <= 1)
+ return (0);
+ if (s < 4) { /* try for good value */
+ if ((j = anysumto(h, n, s, 4)) >= 0)
+ return (j);
+ if ((j = anysumto(h, n, s, 3)) >= 0 && s == 0)
+ return (j);
}
- if( s > 0 && s < 20 ) {
- for( i = 1; i <= 10; i++ ) { /* try for retaliation to 31 */
- if( ( j = anysumto(h, n, s, 21-i) ) >= 0 ) {
- if( ( l = numofval(h, n, i) ) > 0 ) {
- if( l > 1 || VAL( h[j].rank ) != i ) return( j );
- }
+ if (s > 0 && s < 20) {
+ /* try for retaliation to 31 */
+ for (i = 1; i <= 10; i++) {
+ if ((j = anysumto(h, n, s, 21 - i)) >= 0) {
+ if ((l = numofval(h, n, i)) > 0) {
+ if (l > 1 || VAL(h[j].rank) != i)
+ return (j);
+ }
+ }
}
- }
}
- if( s < 15 ) {
- for( i = 0; i < NTV; i++ ) { /* for retaliation after 15 */
- if( ( j = anysumto(h, n, s, tv[i]) ) >= 0 ) {
- if( ( l = numofval(h, n, 15-tv[i]) ) > 0 ) {
- if( l > 1 || VAL( h[j].rank ) != 15-tv[i] ) return( j );
- }
+ if (s < 15) {
+ /* for retaliation after 15 */
+ for (i = 0; i < NTV; i++) {
+ if ((j = anysumto(h, n, s, tv[i])) >= 0) {
+ if ((l = numofval(h, n, 15 - tv[i])) > 0) {
+ if (l > 1 ||
+ VAL(h[j].rank) != 15 - tv[i])
+ return (j);
+ }
+ }
}
- }
}
j = -1;
- for( i = n - 1; i >= 0; --i ) { /* remember: h is sorted */
- l = s + VAL( h[i].rank );
- if( l > 31 ) continue;
- if( l != 5 && l != 10 && l != 21 ) {
- j = i;
- break;
- }
+ /* remember: h is sorted */
+ for (i = n - 1; i >= 0; --i) {
+ l = s + VAL(h[i].rank);
+ if (l > 31)
+ continue;
+ if (l != 5 && l != 10 && l != 21) {
+ j = i;
+ break;
+ }
}
- if( j >= 0 ) return( j );
- for( i = n - 1; i >= 0; --i ) {
- l = s + VAL( h[i].rank );
- if( l > 31 ) continue;
- if( j < 0 ) j = i;
- if( l != 5 && l != 21 ) {
- j = i;
- break;
- }
+ if (j >= 0)
+ return (j);
+ for (i = n - 1; i >= 0; --i) {
+ l = s + VAL(h[i].rank);
+ if (l > 31)
+ continue;
+ if (j < 0)
+ j = i;
+ if (l != 5 && l != 21) {
+ j = i;
+ break;
+ }
}
- return( j );
+ return (j);
}
-
-
/*
* plyrhand:
* Evaluate and score a player hand or crib
*/
+int
plyrhand(hand, s)
-CARD hand[];
-char *s;
+ CARD hand[];
+ char *s;
{
- register int i, j;
- register BOOLEAN win;
- static char prompt[BUFSIZ];
-
- prhand(hand, CINHAND, Playwin, FALSE);
- (void)sprintf(prompt, "Your %s scores ", s);
- i = scorehand(hand, turnover, CINHAND, strcmp(s, "crib") == 0, explain);
- if ((j = number(0, 29, prompt)) == 19)
- j = 0;
- if (i != j) {
- if (i < j) {
- win = chkscr(&pscore, i);
- msg("It's really only %d points; I get %d", i, 2);
- if (!win)
- win = chkscr(&cscore, 2);
- }
- else {
- win = chkscr(&pscore, j);
- msg("You should have taken %d, not %d!", i, j);
- }
- if (explain)
- msg("Explanation: %s", expl);
- do_wait();
- }
- else
- win = chkscr(&pscore, i);
- return win;
+ static char prompt[BUFSIZ];
+ register int i, j;
+ register BOOLEAN win;
+
+ prhand(hand, CINHAND, Playwin, FALSE);
+ (void) sprintf(prompt, "Your %s scores ", s);
+ i = scorehand(hand, turnover, CINHAND, strcmp(s, "crib") == 0, explain);
+ if ((j = number(0, 29, prompt)) == 19)
+ j = 0;
+ if (i != j) {
+ if (i < j) {
+ win = chkscr(&pscore, i);
+ msg("It's really only %d points; I get %d", i, 2);
+ if (!win)
+ win = chkscr(&cscore, 2);
+ } else {
+ win = chkscr(&pscore, j);
+ msg("You should have taken %d, not %d!", i, j);
+ }
+ if (explain)
+ msg("Explanation: %s", expl);
+ do_wait();
+ } else
+ win = chkscr(&pscore, i);
+ return (win);
}
/*
* comphand:
* Handle scoring and displaying the computers hand
*/
+int
comphand(h, s)
-CARD h[];
-char *s;
+ CARD h[];
+ char *s;
{
- register int j;
+ register int j;
j = scorehand(h, turnover, CINHAND, strcmp(s, "crib") == 0, FALSE);
prhand(h, CINHAND, Compwin, FALSE);
msg("My %s scores %d", s, (j == 0 ? 19 : j));
- return chkscr(&cscore, j);
+ return (chkscr(&cscore, j));
}
/*
@@ -167,13 +180,13 @@ char *s;
* Add inc to scr and test for > glimit, printing on the scoring
* board while we're at it.
*/
+int Lastscore[2] = {-1, -1};
-int Lastscore[2] = {-1, -1};
-
+int
chkscr(scr, inc)
-int *scr, inc;
+ int *scr, inc;
{
- BOOLEAN myturn;
+ BOOLEAN myturn;
myturn = (scr == &cscore);
if (inc != 0) {
@@ -191,12 +204,13 @@ int *scr, inc;
* Put out the peg character on the score board and put the
* score up on the board.
*/
+void
prpeg(score, peg, myturn)
-register int score;
-char peg;
-BOOLEAN myturn;
+ register int score;
+ int peg;
+ BOOLEAN myturn;
{
- register int y, x;
+ register int y, x;
if (!myturn)
y = SCORE_Y + 2;
@@ -212,8 +226,7 @@ BOOLEAN myturn;
x = SCORE_X + 2;
y++;
}
- }
- else {
+ } else {
x = (score - 1) % 30;
if (score > 90 || (score > 30 && score <= 60)) {
y++;
@@ -230,129 +243,122 @@ BOOLEAN myturn;
* cdiscard -- the computer figures out what is the best discard for
* the crib and puts the best two cards at the end
*/
-
-cdiscard( mycrib )
-
- BOOLEAN mycrib;
+void
+cdiscard(mycrib)
+ BOOLEAN mycrib;
{
- CARD d[ CARDS ], h[ FULLHAND ], cb[ 2 ];
- register int i, j, k;
- int nc, ns;
- long sums[ 15 ];
- static int undo1[15] = {0,0,0,0,0,1,1,1,1,2,2,2,3,3,4};
- static int undo2[15] = {1,2,3,4,5,2,3,4,5,3,4,5,4,5,5};
-
- makedeck( d );
+ CARD d[CARDS], h[FULLHAND], cb[2];
+ register int i, j, k;
+ int nc, ns;
+ long sums[15];
+ static int undo1[15] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4};
+ static int undo2[15] = {1, 2, 3, 4, 5, 2, 3, 4, 5, 3, 4, 5, 4, 5, 5};
+
+ makedeck(d);
nc = CARDS;
- for( i = 0; i < knownum; i++ ) { /* get all other cards */
- cremove( known[i], d, nc-- );
+ for (i = 0; i < knownum; i++) { /* get all other cards */
+ cremove(known[i], d, nc--);
}
- for( i = 0; i < 15; i++ ) sums[i] = 0L;
+ for (i = 0; i < 15; i++)
+ sums[i] = 0L;
ns = 0;
- for( i = 0; i < (FULLHAND - 1); i++ ) {
- cb[0] = chand[i];
- for( j = i + 1; j < FULLHAND; j++ ) {
- cb[1] = chand[j];
- for( k = 0; k < FULLHAND; k++ ) h[k] = chand[k];
- cremove( chand[i], h, FULLHAND );
- cremove( chand[j], h, FULLHAND - 1 );
- for( k = 0; k < nc; k++ ) {
- sums[ns] += scorehand( h, d[k], CINHAND, TRUE, FALSE );
- if( mycrib ) sums[ns] += adjust( cb, d[k] );
- else sums[ns] -= adjust( cb, d[k] );
+ for (i = 0; i < (FULLHAND - 1); i++) {
+ cb[0] = chand[i];
+ for (j = i + 1; j < FULLHAND; j++) {
+ cb[1] = chand[j];
+ for (k = 0; k < FULLHAND; k++)
+ h[k] = chand[k];
+ cremove(chand[i], h, FULLHAND);
+ cremove(chand[j], h, FULLHAND - 1);
+ for (k = 0; k < nc; k++) {
+ sums[ns] +=
+ scorehand(h, d[k], CINHAND, TRUE, FALSE);
+ if (mycrib)
+ sums[ns] += adjust(cb, d[k]);
+ else
+ sums[ns] -= adjust(cb, d[k]);
+ }
+ ++ns;
}
- ++ns;
- }
}
j = 0;
- for( i = 1; i < 15; i++ ) if( sums[i] > sums[j] ) j = i;
- for( k = 0; k < FULLHAND; k++ ) h[k] = chand[k];
- cremove( h[ undo1[j] ], chand, FULLHAND );
- cremove( h[ undo2[j] ], chand, FULLHAND - 1 );
- chand[4] = h[ undo1[j] ];
- chand[5] = h[ undo2[j] ];
+ for (i = 1; i < 15; i++)
+ if (sums[i] > sums[j])
+ j = i;
+ for (k = 0; k < FULLHAND; k++)
+ h[k] = chand[k];
+ cremove(h[undo1[j]], chand, FULLHAND);
+ cremove(h[undo2[j]], chand, FULLHAND - 1);
+ chand[4] = h[undo1[j]];
+ chand[5] = h[undo2[j]];
}
-
-
/*
* returns true if some card in hand can be played without exceeding 31
*/
-
-anymove( hand, n, sum )
-
- CARD hand[];
- int n;
- int sum;
+int
+anymove(hand, n, sum)
+ CARD hand[];
+ int n, sum;
{
- register int i, j;
+ register int i, j;
- if( n < 1 ) return( FALSE );
+ if (n < 1)
+ return (FALSE);
j = hand[0].rank;
- for( i = 1; i < n; i++ ) {
- if( hand[i].rank < j ) j = hand[i].rank;
+ for (i = 1; i < n; i++) {
+ if (hand[i].rank < j)
+ j = hand[i].rank;
}
- return( sum + VAL( j ) <= 31 );
+ return (sum + VAL(j) <= 31);
}
-
-
/*
* anysumto returns the index (0 <= i < n) of the card in hand that brings
* the s up to t, or -1 if there is none
*/
-
-anysumto( hand, n, s, t )
-
- CARD hand[];
- int n;
- int s, t;
+int
+anysumto(hand, n, s, t)
+ CARD hand[];
+ int n, s, t;
{
- register int i;
+ register int i;
- for( i = 0; i < n; i++ ) {
- if( s + VAL( hand[i].rank ) == t ) return( i );
+ for (i = 0; i < n; i++) {
+ if (s + VAL(hand[i].rank) == t)
+ return (i);
}
- return( -1 );
+ return (-1);
}
-
-
-
/*
* return the number of cards in h having the given rank value
*/
-
-numofval( h, n, v )
-
- CARD h[];
- int n;
- int v;
+int
+numofval(h, n, v)
+ CARD h[];
+ int n, v;
{
- register int i, j;
+ register int i, j;
j = 0;
- for( i = 0; i < n; i++ ) {
- if( VAL( h[i].rank ) == v ) ++j;
+ for (i = 0; i < n; i++) {
+ if (VAL(h[i].rank) == v)
+ ++j;
}
- return( j );
+ return (j);
}
-
-
/*
* makeknown remembers all n cards in h for future recall
*/
-
-makeknown( h, n )
-
- CARD h[];
- int n;
+void
+makeknown(h, n)
+ CARD h[];
+ int n;
{
- register int i;
+ register int i;
- for( i = 0; i < n; i++ ) {
- known[ knownum++ ] = h[i];
- }
+ for (i = 0; i < n; i++)
+ known[knownum++] = h[i];
}
-