diff options
-rw-r--r-- | cribbage/cards.c | 26 | ||||
-rw-r--r-- | cribbage/crib.c | 43 | ||||
-rw-r--r-- | cribbage/cribbage.h | 5 | ||||
-rw-r--r-- | cribbage/deck.h | 12 | ||||
-rw-r--r-- | cribbage/instr.c | 6 | ||||
-rw-r--r-- | cribbage/io.c | 57 | ||||
-rw-r--r-- | cribbage/score.c | 45 | ||||
-rw-r--r-- | cribbage/support.c | 59 |
8 files changed, 87 insertions, 166 deletions
diff --git a/cribbage/cards.c b/cribbage/cards.c index 50e2f481..dba3bc7b 100644 --- a/cribbage/cards.c +++ b/cribbage/cards.c @@ -1,4 +1,4 @@ -/* $NetBSD: cards.c,v 1.7 2003/08/07 09:37:08 agc Exp $ */ +/* $NetBSD: cards.c,v 1.8 2005/07/02 08:32:32 jmc Exp $ */ /*- * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)cards.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: cards.c,v 1.7 2003/08/07 09:37:08 agc Exp $"); +__RCSID("$NetBSD: cards.c,v 1.8 2005/07/02 08:32:32 jmc Exp $"); #endif #endif /* not lint */ @@ -51,8 +51,7 @@ __RCSID("$NetBSD: cards.c,v 1.7 2003/08/07 09:37:08 agc Exp $"); * Initialize a deck of cards to contain one of each type. */ void -makedeck(d) - CARD d[]; +makedeck(CARD d[]) { int i, j, k; @@ -72,8 +71,7 @@ makedeck(d) * see Knuth, vol. 2, page 125. */ void -shuffle(d) - CARD d[]; +shuffle(CARD d[]) { int j, k; CARD c; @@ -90,8 +88,7 @@ shuffle(d) * return true if the two cards are equal... */ int -eq(a, b) - CARD a, b; +eq(CARD a, CARD b) { return ((a.rank == b.rank) && (a.suit == b.suit)); } @@ -100,10 +97,7 @@ eq(a, b) * is_one returns TRUE if a is in the set of cards b */ int -is_one(a, b, n) - CARD a; - const CARD b[]; - int n; +is_one(CARD a, const CARD b[], int n) { int i; @@ -117,9 +111,7 @@ is_one(a, b, n) * remove the card a from the deck d of n cards */ void -cremove(a, d, n) - CARD a, d[]; - int n; +cremove(CARD a, CARD d[], int n) { int i, j; @@ -135,9 +127,7 @@ cremove(a, d, n) * Sort a hand of n cards */ void -sorthand(h, n) - CARD h[]; - int n; +sorthand(CARD h[], int n) { CARD *cp, *endp; CARD c; diff --git a/cribbage/crib.c b/cribbage/crib.c index ffbca60d..a60832ae 100644 --- a/cribbage/crib.c +++ b/cribbage/crib.c @@ -1,4 +1,4 @@ -/* $NetBSD: crib.c,v 1.19 2004/01/27 20:30:29 jsm Exp $ */ +/* $NetBSD: crib.c,v 1.20 2005/07/02 08:32:32 jmc Exp $ */ /*- * Copyright (c) 1980, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\ #if 0 static char sccsid[] = "@(#)crib.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: crib.c,v 1.19 2004/01/27 20:30:29 jsm Exp $"); +__RCSID("$NetBSD: crib.c,v 1.20 2005/07/02 08:32:32 jmc Exp $"); #endif #endif /* not lint */ @@ -56,12 +56,8 @@ __RCSID("$NetBSD: crib.c,v 1.19 2004/01/27 20:30:29 jsm Exp $"); #include "cribcur.h" #include "pathnames.h" -int main(int, char *[]); - int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { BOOLEAN playing; FILE *f; @@ -162,7 +158,7 @@ main(argc, argv) * Print out the initial board on the screen */ void -makeboard() +makeboard(void) { mvaddstr(SCORE_Y + 0, SCORE_X, "+---------------------------------------+"); @@ -190,7 +186,7 @@ makeboard() * Print out the current game score */ void -gamescore() +gamescore(void) { if (pgames || cgames) { mvprintw(SCORE_Y + 1, SCORE_X + 28, "Games: %3d", pgames); @@ -206,7 +202,7 @@ gamescore() * player what card to turn. We do a random one, anyway. */ void -game() +game(void) { int i, j; BOOLEAN flag; @@ -300,8 +296,7 @@ game() * Do up one hand of the game */ int -playhand(mycrib) - BOOLEAN mycrib; +playhand(BOOLEAN mycrib) { int deckpos; @@ -332,8 +327,7 @@ playhand(mycrib) * deal cards to both players from deck */ int -deal(mycrib) - BOOLEAN mycrib; +deal(BOOLEAN mycrib) { int i, j; @@ -355,8 +349,7 @@ deal(mycrib) * Note: we call cdiscard() after prining first message so player doesn't wait */ void -discard(mycrib) - BOOLEAN mycrib; +discard(BOOLEAN mycrib) { const char *prompt; CARD crd; @@ -385,9 +378,7 @@ discard(mycrib) * player what card to turn. We do a random one, anyway. */ int -cut(mycrib, pos) - BOOLEAN mycrib; - int pos; +cut(BOOLEAN mycrib, int pos) { int i; BOOLEAN win; @@ -429,8 +420,7 @@ cut(mycrib, pos) * Print out the turnover card with crib indicator */ void -prcrib(mycrib, blank) - BOOLEAN mycrib, blank; +prcrib(BOOLEAN mycrib, BOOLEAN blank) { int y, cardx; @@ -460,8 +450,7 @@ static CARD Table[14]; static int Tcnt; int -peg(mycrib) - BOOLEAN mycrib; +peg(BOOLEAN mycrib) { static CARD ch[CINHAND], ph[CINHAND]; int i, j, k; @@ -620,11 +609,10 @@ peg(mycrib) * Print out the table with the current score */ void -prtable(score) - int score; +prtable(int curscore) { prhand(Table, Tcnt, Tablewin, FALSE); - mvwprintw(Tablewin, (Tcnt + 2) * 2, Tcnt + 1, "%2d", score); + mvwprintw(Tablewin, (Tcnt + 2) * 2, Tcnt + 1, "%2d", curscore); wrefresh(Tablewin); } @@ -633,8 +621,7 @@ prtable(score) * Handle the scoring of the hands */ int -score(mycrib) - BOOLEAN mycrib; +score(BOOLEAN mycrib) { sorthand(crib, CINHAND); if (mycrib) { diff --git a/cribbage/cribbage.h b/cribbage/cribbage.h index ce2eecb0..0cd1e792 100644 --- a/cribbage/cribbage.h +++ b/cribbage/cribbage.h @@ -1,4 +1,4 @@ -/* $NetBSD: cribbage.h,v 1.12 2004/02/08 22:23:50 jsm Exp $ */ +/* $NetBSD: cribbage.h,v 1.13 2005/07/02 08:32:32 jmc Exp $ */ /* * Copyright (c) 1980, 1993 @@ -53,7 +53,6 @@ extern BOOLEAN iwon; /* if comp won last */ extern BOOLEAN explain; /* player mistakes explained */ extern BOOLEAN rflag; /* if all cuts random */ extern BOOLEAN quiet; /* if suppress random mess */ -extern BOOLEAN playing; /* currently playing game */ extern char explan[]; /* string for explanation */ @@ -69,7 +68,7 @@ int chkscr(int *, int); int comphand(const CARD [], const char *); void cremove(CARD, CARD [], int); int cut(BOOLEAN, int); -int deal(int); +int deal(BOOLEAN); void discard(BOOLEAN); void do_wait(void); void endmsg(void); diff --git a/cribbage/deck.h b/cribbage/deck.h index cccc7ab6..166fbc31 100644 --- a/cribbage/deck.h +++ b/cribbage/deck.h @@ -1,4 +1,4 @@ -/* $NetBSD: deck.h,v 1.4 2003/08/07 09:37:10 agc Exp $ */ +/* $NetBSD: deck.h,v 1.5 2005/07/02 08:32:32 jmc Exp $ */ /* * Copyright (c) 1980, 1993 @@ -74,10 +74,10 @@ # define FALSE 0 #endif -typedef struct { - int rank; - int suit; - } CARD; +typedef struct { + int rank; + int suit; +} CARD; -typedef char BOOLEAN; +typedef char BOOLEAN; diff --git a/cribbage/instr.c b/cribbage/instr.c index f4d9d800..aab196ed 100644 --- a/cribbage/instr.c +++ b/cribbage/instr.c @@ -1,4 +1,4 @@ -/* $NetBSD: instr.c,v 1.11 2005/02/15 12:56:20 jsm Exp $ */ +/* $NetBSD: instr.c,v 1.12 2005/07/02 08:32:32 jmc Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)instr.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: instr.c,v 1.11 2005/02/15 12:56:20 jsm Exp $"); +__RCSID("$NetBSD: instr.c,v 1.12 2005/07/02 08:32:32 jmc Exp $"); #endif #endif /* not lint */ @@ -56,7 +56,7 @@ __RCSID("$NetBSD: instr.c,v 1.11 2005/02/15 12:56:20 jsm Exp $"); #include "pathnames.h" void -instructions() +instructions(void) { int pstat; int fd; diff --git a/cribbage/io.c b/cribbage/io.c index 60e83d19..12e23b35 100644 --- a/cribbage/io.c +++ b/cribbage/io.c @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.19 2005/04/19 20:12:07 rillig Exp $ */ +/* $NetBSD: io.c,v 1.20 2005/07/02 08:32:32 jmc Exp $ */ /*- * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: io.c,v 1.19 2005/04/19 20:12:07 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.20 2005/07/02 08:32:32 jmc Exp $"); #endif #endif /* not lint */ @@ -93,10 +93,7 @@ msgcard(c, brief) * Print the value of a card in ascii */ int -msgcrd(c, brfrank, mid, brfsuit) - CARD c; - BOOLEAN brfrank, brfsuit; - const char *mid; +msgcrd(CARD c, BOOLEAN brfrank, const char *mid, BOOLEAN brfsuit) { if (c.rank == EMPTY || c.suit == EMPTY) return (FALSE); @@ -118,11 +115,7 @@ msgcrd(c, brfrank, mid, brfsuit) * Print out a card. */ void -printcard(win, cardno, c, blank) - WINDOW *win; - int cardno; - CARD c; - BOOLEAN blank; +printcard(WINDOW *win, int cardno, CARD c, BOOLEAN blank) { prcard(win, cardno * 2, cardno, c, blank); } @@ -132,11 +125,7 @@ printcard(win, cardno, c, blank) * 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; +prcard(WINDOW *win, int y, int x, CARD c, BOOLEAN blank) { if (c.rank == EMPTY) return; @@ -159,11 +148,7 @@ prcard(win, y, x, c, blank) * Print a hand of n cards */ void -prhand(h, n, win, blank) - const CARD h[]; - int n; - WINDOW *win; - BOOLEAN blank; +prhand(const CARD h[], int n, WINDOW *win, BOOLEAN blank) { int i; @@ -179,10 +164,7 @@ prhand(h, n, win, blank) * input, returns the index of the card found... */ int -infrom(hand, n, prompt) - const CARD hand[]; - int n; - const char *prompt; +infrom(const CARD hand[], int n, const char *prompt) { int i, j; CARD crd; @@ -235,8 +217,7 @@ infrom(hand, n, prompt) * and then parses it. */ int -incard(crd) - CARD *crd; +incard(CARD *crd) { int i; int rnk, sut; @@ -320,7 +301,7 @@ gotit: * Reads and converts to upper case */ int -getuchar() +getuchar(void) { int c; @@ -337,9 +318,7 @@ getuchar() * "hi" inclusive. */ int -number(lo, hi, prompt) - int lo, hi; - const char *prompt; +number(int lo, int hi, const char *prompt) { char *p; int sum; @@ -416,7 +395,7 @@ addmsg(const char *fmt, ...) int Lineno = 0; void -endmsg() +endmsg(void) { static int lastline = 0; int len; @@ -465,7 +444,7 @@ endmsg() * Wait for the user to type ' ' before doing anything else */ void -do_wait() +do_wait(void) { static const char prompt[] = {'-', '-', 'M', 'o', 'r', 'e', '-', '-', '\0'}; @@ -487,8 +466,7 @@ do_wait() * Sit around until the guy types the right key */ void -wait_for(ch) - int ch; +wait_for(int ch) { int c; @@ -505,7 +483,7 @@ wait_for(ch) * Reads and returns a character, checking for gross input errors */ int -readchar() +readchar(void) { int cnt; unsigned char c; @@ -533,7 +511,7 @@ over: * compressed to one space; a space is inserted before a ',' */ char * -getline() +getline(void) { char *sp; int c, oy, ox; @@ -579,8 +557,7 @@ getline() } void -receive_intr(signo) - int signo __attribute__((__unused__)); +receive_intr(int signo __attribute__((__unused__))) { bye(); exit(1); @@ -591,7 +568,7 @@ receive_intr(signo) * Leave the program, cleaning things up as we go. */ void -bye() +bye(void) { signal(SIGINT, SIG_IGN); mvcur(0, COLS - 1, LINES - 1, 0); diff --git a/cribbage/score.c b/cribbage/score.c index 2241bd6b..bb9de637 100644 --- a/cribbage/score.c +++ b/cribbage/score.c @@ -1,4 +1,4 @@ -/* $NetBSD: score.c,v 1.10 2003/08/07 09:37:10 agc Exp $ */ +/* $NetBSD: score.c,v 1.11 2005/07/02 08:32:32 jmc Exp $ */ /*- * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: score.c,v 1.10 2003/08/07 09:37:10 agc Exp $"); +__RCSID("$NetBSD: score.c,v 1.11 2005/07/02 08:32:32 jmc Exp $"); #endif #endif /* not lint */ @@ -105,28 +105,24 @@ static int pairpoints, runpoints; /* Globals from pairuns. */ * n must be <= 4 */ int -scorehand(hand, starter, n, crb, do_explain) - const CARD hand[]; - CARD starter; - int n; - BOOLEAN crb; /* true if scoring crib */ - BOOLEAN do_explain; /* true if must explain this hand */ +scorehand(const CARD hand[], CARD starter, int n, BOOLEAN crb, + BOOLEAN do_explain) { int i, k; - int score; + int hscore; BOOLEAN flag; CARD h[(CINHAND + 1)]; char buf[32]; explan[0] = '\0'; /* initialize explanation */ - score = 0; + hscore = 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++; + hscore++; if (do_explain) strcat(explan, "His Nobs"); } @@ -137,12 +133,12 @@ scorehand(hand, starter, n, crb, do_explain) if (do_explain && explan[0] != '\0') strcat(explan, ", "); if (starter.suit == k) { - score += 5; + hscore += 5; if (do_explain) strcat(explan, "Five-flush"); } else if (!crb) { - score += 4; + hscore += 4; if (do_explain && explan[0] != '\0') strcat(explan, ", Four-flush"); else @@ -154,7 +150,7 @@ scorehand(hand, starter, n, crb, do_explain) h[n] = starter; sorthand(h, n + 1); /* sort by rank */ i = 2 * fifteens(h, n + 1); - score += i; + hscore += i; if (do_explain) { if (i > 0) { (void) sprintf(buf, "%d points in fifteens", i); @@ -163,7 +159,7 @@ scorehand(hand, starter, n, crb, do_explain) strcat(explan, "No fifteens"); } i = pairuns(h, n + 1); - score += i; + hscore += i; if (do_explain) { if (i > 0) { (void) sprintf(buf, ", %d points in pairs, %d in runs", @@ -172,7 +168,7 @@ scorehand(hand, starter, n, crb, do_explain) } else strcat(explan, ", No pairs/runs"); } - return (score); + return (hscore); } /* @@ -180,9 +176,7 @@ scorehand(hand, starter, n, crb, do_explain) * Return number of fifteens in hand of n cards */ int -fifteens(hand, n) - const CARD hand[]; - int n; +fifteens(const CARD hand[], int n) { int *sp, *np; int i; @@ -223,9 +217,7 @@ fifteens(hand, n) * sets the globals pairpoints and runpoints appropriately */ int -pairuns(h, n) - const CARD h[]; - int n; +pairuns(const CARD h[], int n) { int i; int runlength, runmult, lastmult, curmult; @@ -292,10 +284,7 @@ pairuns(h, n) * the n cards in tbl during pegging */ int -pegscore(crd, tbl, n, sum) - CARD crd; - const CARD tbl[]; - int n, sum; +pegscore(CARD crd, const CARD tbl[], int n, int sum) { BOOLEAN got[RANKS]; int i, j, scr; @@ -348,9 +337,7 @@ pegscore(crd, tbl, n, sum) * points such a crib will get. */ int -adjust(cb, tnv) - const CARD cb[]; - CARD tnv __attribute__((__unused__)); +adjust(const CARD cb[], CARD tnv __attribute((__unused__))) { long scr; int i, c0, c1; diff --git a/cribbage/support.c b/cribbage/support.c index 0952b912..6cc20ac1 100644 --- a/cribbage/support.c +++ b/cribbage/support.c @@ -1,4 +1,4 @@ -/* $NetBSD: support.c,v 1.7 2003/08/07 09:37:11 agc Exp $ */ +/* $NetBSD: support.c,v 1.8 2005/07/02 08:32:32 jmc Exp $ */ /*- * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)support.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: support.c,v 1.7 2003/08/07 09:37:11 agc Exp $"); +__RCSID("$NetBSD: support.c,v 1.8 2005/07/02 08:32:32 jmc Exp $"); #endif #endif /* not lint */ @@ -55,9 +55,7 @@ const int tv[NTV] = {8, 7, 9, 6, 11, 12, 13, 14, 10, 5}; * only called if no playable card will score points */ int -cchose(h, n, s) - const CARD h[]; - int n, s; +cchose(const CARD h[], int n, int s) { int i, j, l; @@ -124,9 +122,7 @@ cchose(h, n, s) * Evaluate and score a player hand or crib */ int -plyrhand(hand, s) - const CARD hand[]; - const char *s; +plyrhand(const CARD hand[], const char *s) { static char prompt[BUFSIZ]; int i, j; @@ -160,9 +156,7 @@ plyrhand(hand, s) * Handle scoring and displaying the computers hand */ int -comphand(h, s) - const CARD h[]; - const char *s; +comphand(const CARD h[], const char *s) { int j; @@ -180,8 +174,7 @@ comphand(h, s) int Lastscore[2] = {-1, -1}; int -chkscr(scr, inc) - int *scr, inc; +chkscr(int *scr, int inc) { BOOLEAN myturn; @@ -202,10 +195,7 @@ chkscr(scr, inc) * score up on the board. */ void -prpeg(score, peg, myturn) - int score; - int peg; - BOOLEAN myturn; +prpeg(int curscore, int pegc, BOOLEAN myturn) { int y, x; @@ -214,26 +204,26 @@ prpeg(score, peg, myturn) else y = SCORE_Y + 5; - if (score <= 0 || score >= glimit) { - if (peg == '.') - peg = ' '; - if (score == 0) + if (curscore <= 0 || curscore >= glimit) { + if (pegc == '.') + pegc = ' '; + if (curscore == 0) x = SCORE_X + 2; else { x = SCORE_X + 2; y++; } } else { - x = (score - 1) % 30; - if (score > 90 || (score > 30 && score <= 60)) { + x = (curscore - 1) % 30; + if (curscore > 90 || (curscore > 30 && curscore <= 60)) { y++; x = 29 - x; } x += x / 5; x += SCORE_X + 3; } - mvaddch(y, x, peg); - mvprintw(SCORE_Y + (myturn ? 7 : 1), SCORE_X + 10, "%3d", score); + mvaddch(y, x, pegc); + mvprintw(SCORE_Y + (myturn ? 7 : 1), SCORE_X + 10, "%3d", curscore); } /* @@ -241,8 +231,7 @@ prpeg(score, peg, myturn) * the crib and puts the best two cards at the end */ void -cdiscard(mycrib) - BOOLEAN mycrib; +cdiscard(BOOLEAN mycrib) { CARD d[CARDS], h[FULLHAND], cb[2]; int i, j, k; @@ -294,9 +283,7 @@ cdiscard(mycrib) * returns true if some card in hand can be played without exceeding 31 */ int -anymove(hand, n, sum) - const CARD hand[]; - int n, sum; +anymove(const CARD hand[], int n, int sum) { int i, j; @@ -315,9 +302,7 @@ anymove(hand, n, sum) * the s up to t, or -1 if there is none */ int -anysumto(hand, n, s, t) - const CARD hand[]; - int n, s, t; +anysumto(const CARD hand[], int n, int s, int t) { int i; @@ -332,9 +317,7 @@ anysumto(hand, n, s, t) * return the number of cards in h having the given rank value */ int -numofval(h, n, v) - const CARD h[]; - int n, v; +numofval(const CARD h[], int n, int v) { int i, j; @@ -350,9 +333,7 @@ numofval(h, n, v) * makeknown remembers all n cards in h for future recall */ void -makeknown(h, n) - const CARD h[]; - int n; +makeknown(const CARD h[], int n) { int i; |