diff options
Diffstat (limited to 'cribbage')
| -rw-r--r-- | cribbage/cards.c | 6 | ||||
| -rw-r--r-- | cribbage/crib.c | 38 | ||||
| -rw-r--r-- | cribbage/cribbage.h | 24 | ||||
| -rw-r--r-- | cribbage/io.c | 38 | ||||
| -rw-r--r-- | cribbage/score.c | 15 | ||||
| -rw-r--r-- | cribbage/support.c | 16 |
6 files changed, 71 insertions, 66 deletions
diff --git a/cribbage/cards.c b/cribbage/cards.c index dba3bc7b..9d5d0750 100644 --- a/cribbage/cards.c +++ b/cribbage/cards.c @@ -1,4 +1,4 @@ -/* $NetBSD: cards.c,v 1.8 2005/07/02 08:32:32 jmc Exp $ */ +/* $NetBSD: cards.c,v 1.9 2009/08/12 05:48:04 dholland 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.8 2005/07/02 08:32:32 jmc Exp $"); +__RCSID("$NetBSD: cards.c,v 1.9 2009/08/12 05:48:04 dholland Exp $"); #endif #endif /* not lint */ @@ -87,7 +87,7 @@ shuffle(CARD d[]) /* * return true if the two cards are equal... */ -int +static int eq(CARD a, CARD b) { return ((a.rank == b.rank) && (a.suit == b.suit)); diff --git a/cribbage/crib.c b/cribbage/crib.c index 75d5d77d..aef76a8a 100644 --- a/cribbage/crib.c +++ b/cribbage/crib.c @@ -1,4 +1,4 @@ -/* $NetBSD: crib.c,v 1.23 2009/07/13 19:05:40 roy Exp $ */ +/* $NetBSD: crib.c,v 1.24 2009/08/12 05:48:04 dholland Exp $ */ /*- * Copyright (c) 1980, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\ #if 0 static char sccsid[] = "@(#)crib.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: crib.c,v 1.23 2009/07/13 19:05:40 roy Exp $"); +__RCSID("$NetBSD: crib.c,v 1.24 2009/08/12 05:48:04 dholland Exp $"); #endif #endif /* not lint */ @@ -56,6 +56,18 @@ __RCSID("$NetBSD: crib.c,v 1.23 2009/07/13 19:05:40 roy Exp $"); #include "cribcur.h" #include "pathnames.h" +static void makeboard(void); +static void gamescore(void); +static void game(void); +static int playhand(BOOLEAN); +static int deal(BOOLEAN); +static void discard(BOOLEAN); +static int cut(BOOLEAN, int); +static void prcrib(BOOLEAN, BOOLEAN); +static int peg(BOOLEAN); +static void prtable(int); +static int score(BOOLEAN); + int main(int argc, char *argv[]) { @@ -158,7 +170,7 @@ main(int argc, char *argv[]) * makeboard: * Print out the initial board on the screen */ -void +static void makeboard(void) { mvaddstr(SCORE_Y + 0, SCORE_X, @@ -186,7 +198,7 @@ makeboard(void) * gamescore: * Print out the current game score */ -void +static void gamescore(void) { if (pgames || cgames) { @@ -202,7 +214,7 @@ gamescore(void) * Play one game up to glimit points. Actually, we only ASK the * player what card to turn. We do a random one, anyway. */ -void +static void game(void) { int i, j; @@ -296,7 +308,7 @@ game(void) * playhand: * Do up one hand of the game */ -int +static int playhand(BOOLEAN mycrib) { int deckpos; @@ -327,7 +339,7 @@ playhand(BOOLEAN mycrib) /* * deal cards to both players from deck */ -int +static int deal(BOOLEAN mycrib) { int i, j; @@ -349,7 +361,7 @@ deal(BOOLEAN mycrib) * Handle players discarding into the crib... * Note: we call cdiscard() after prining first message so player doesn't wait */ -void +static void discard(BOOLEAN mycrib) { const char *prompt; @@ -378,7 +390,7 @@ discard(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 +static int cut(BOOLEAN mycrib, int pos) { int i; @@ -420,7 +432,7 @@ cut(BOOLEAN mycrib, int pos) * prcrib: * Print out the turnover card with crib indicator */ -void +static void prcrib(BOOLEAN mycrib, BOOLEAN blank) { int y, cardx; @@ -450,7 +462,7 @@ prcrib(BOOLEAN mycrib, BOOLEAN blank) static CARD Table[14]; static int Tcnt; -int +static int peg(BOOLEAN mycrib) { static CARD ch[CINHAND], ph[CINHAND]; @@ -609,7 +621,7 @@ peg(BOOLEAN mycrib) * prtable: * Print out the table with the current score */ -void +static void prtable(int curscore) { prhand(Table, Tcnt, Tablewin, FALSE); @@ -621,7 +633,7 @@ prtable(int curscore) * score: * Handle the scoring of the hands */ -int +static int score(BOOLEAN mycrib) { sorthand(crib, CINHAND); diff --git a/cribbage/cribbage.h b/cribbage/cribbage.h index cfe2a7fb..5df12b14 100644 --- a/cribbage/cribbage.h +++ b/cribbage/cribbage.h @@ -1,4 +1,4 @@ -/* $NetBSD: cribbage.h,v 1.14 2009/07/13 19:05:40 roy Exp $ */ +/* $NetBSD: cribbage.h,v 1.15 2009/08/12 05:48:04 dholland Exp $ */ /* * Copyright (c) 1980, 1993 @@ -60,52 +60,30 @@ void addmsg(const char *, ...) __attribute__((__format__(__printf__, 1, 2))); int adjust(const CARD [], CARD); int anymove(const CARD [], int, int); -int anysumto(const CARD [], int, int, int); void bye(void); int cchose(const CARD [], int, int); void cdiscard(BOOLEAN); int chkscr(int *, int); int comphand(const CARD [], const char *); void cremove(CARD, CARD [], int); -int cut(BOOLEAN, int); -int deal(BOOLEAN); -void discard(BOOLEAN); void do_wait(void); void endmsg(void); -int eq(CARD, CARD); -int fifteens(const CARD [], int); -void game(void); -void gamescore(void); char *get_line(void); int getuchar(void); -int incard(CARD *); int infrom(const CARD [], int, const char *); void instructions(void); int is_one(CARD, const CARD [], int); -void makeboard(void); void makedeck(CARD []); void makeknown(const CARD [], int); void msg(const char *, ...) __attribute__((__format__(__printf__, 1, 2))); int msgcard(CARD, BOOLEAN); -int msgcrd(CARD, BOOLEAN, const char *, BOOLEAN); int number(int, int, const char *); -int numofval(const CARD [], int, int); -int pairuns(const CARD [], int); -int peg(BOOLEAN); int pegscore(CARD, const CARD [], int, int); -int playhand(BOOLEAN); int plyrhand(const CARD [], const char *); void prcard(WINDOW *, int, int, CARD, BOOLEAN); -void prcrib(BOOLEAN, BOOLEAN); void prhand(const CARD [], int, WINDOW *, BOOLEAN); -void printcard(WINDOW *, int, CARD, BOOLEAN); -void prpeg(int, int, BOOLEAN); -void prtable(int); -int readchar(void); void receive_intr(int) __attribute__((__noreturn__)); -int score(BOOLEAN); int scorehand(const CARD [], CARD, int, BOOLEAN, BOOLEAN); void shuffle(CARD []); void sorthand(CARD [], int); -void wait_for(int); diff --git a/cribbage/io.c b/cribbage/io.c index 8bf6ee62..5a5fec61 100644 --- a/cribbage/io.c +++ b/cribbage/io.c @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.23 2009/07/13 19:05:40 roy Exp $ */ +/* $NetBSD: io.c,v 1.24 2009/08/12 05:48:04 dholland 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.23 2009/07/13 19:05:40 roy Exp $"); +__RCSID("$NetBSD: io.c,v 1.24 2009/08/12 05:48:04 dholland Exp $"); #endif #endif /* not lint */ @@ -58,20 +58,28 @@ __RCSID("$NetBSD: io.c,v 1.23 2009/07/13 19:05:40 roy Exp $"); #endif #define CTRL(X) (X - 'A' + 1) -char linebuf[LINESIZE]; +static int msgcrd(CARD, BOOLEAN, const char *, BOOLEAN); +static void printcard(WINDOW *, int, CARD, BOOLEAN); +static int incard(CARD *); +static void wait_for(int); +static int readchar(void); -const char *const rankname[RANKS] = { +static char linebuf[LINESIZE]; + +static const char *const rankname[RANKS] = { "ACE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "JACK", "QUEEN", "KING" }; -const char *const rankchar[RANKS] = { +static const char *const rankchar[RANKS] = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K" }; -const char *const suitname[SUITS] = {"SPADES", "HEARTS", "DIAMONDS", "CLUBS"}; +static const char *const suitname[SUITS] = { + "SPADES", "HEARTS", "DIAMONDS", "CLUBS" +}; -const char *const suitchar[SUITS] = {"S", "H", "D", "C"}; +static const char *const suitchar[SUITS] = {"S", "H", "D", "C"}; /* * msgcard: @@ -92,7 +100,7 @@ msgcard(c, brief) * msgcrd: * Print the value of a card in ascii */ -int +static int msgcrd(CARD c, BOOLEAN brfrank, const char *mid, BOOLEAN brfsuit) { if (c.rank == EMPTY || c.suit == EMPTY) @@ -114,7 +122,7 @@ msgcrd(CARD c, BOOLEAN brfrank, const char *mid, BOOLEAN brfsuit) * printcard: * Print out a card. */ -void +static void printcard(WINDOW *win, int cardno, CARD c, BOOLEAN blank) { prcard(win, cardno * 2, cardno, c, blank); @@ -216,7 +224,7 @@ infrom(const CARD hand[], int n, const char *prompt) * Inputs a card in any format. It reads a line ending with a CR * and then parses it. */ -int +static int incard(CARD *crd) { int i; @@ -357,8 +365,8 @@ number(int lo, int hi, const char *prompt) * msg: * Display a message at the top of the screen. */ -char Msgbuf[BUFSIZ] = {'\0'}; -int Mpos = 0; +static char Msgbuf[BUFSIZ] = {'\0'}; +static int Mpos = 0; static int Newpos = 0; void @@ -392,7 +400,7 @@ addmsg(const char *fmt, ...) * endmsg: * Display a new msg. */ -int Lineno = 0; +static int Lineno = 0; void endmsg(void) @@ -465,7 +473,7 @@ do_wait(void) * wait_for * Sit around until the guy types the right key */ -void +static void wait_for(int ch) { int c; @@ -482,7 +490,7 @@ wait_for(int ch) * readchar: * Reads and returns a character, checking for gross input errors */ -int +static int readchar(void) { int cnt; diff --git a/cribbage/score.c b/cribbage/score.c index 932d757d..2228c7f3 100644 --- a/cribbage/score.c +++ b/cribbage/score.c @@ -1,4 +1,4 @@ -/* $NetBSD: score.c,v 1.14 2009/06/04 04:48:04 dholland Exp $ */ +/* $NetBSD: score.c,v 1.15 2009/08/12 05:48:04 dholland 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.14 2009/06/04 04:48:04 dholland Exp $"); +__RCSID("$NetBSD: score.c,v 1.15 2009/08/12 05:48:04 dholland Exp $"); #endif #endif /* not lint */ @@ -46,13 +46,16 @@ __RCSID("$NetBSD: score.c,v 1.14 2009/06/04 04:48:04 dholland Exp $"); #include "deck.h" #include "cribbage.h" +static int fifteens(const CARD [], int); +static int pairuns(const CARD [], int); + /* * the following arrays give the sum of the scores of the (50 2)*48 = 58800 * hands obtainable for the crib given the two cards whose ranks index the * array. the two arrays are for the case where the suits are equal and * not equal respectively */ -const long crbescr[169] = { +static const 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, @@ -74,7 +77,7 @@ const long crbescr[169] = { -10000, -10000, -10000, -10000, -10000, -10000, -10000 }; -const long crbnescr[169] = { +static const 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, @@ -177,7 +180,7 @@ scorehand(const CARD hand[], CARD starter, int n, BOOLEAN crb, * fifteens: * Return number of fifteens in hand of n cards */ -int +static int fifteens(const CARD hand[], int n) { int *sp, *np; @@ -218,7 +221,7 @@ fifteens(const CARD hand[], int n) * this routine only works if n is strictly less than 6 * sets the globals pairpoints and runpoints appropriately */ -int +static int pairuns(const CARD h[], int n) { int i; diff --git a/cribbage/support.c b/cribbage/support.c index e711d8b6..a576aee0 100644 --- a/cribbage/support.c +++ b/cribbage/support.c @@ -1,4 +1,4 @@ -/* $NetBSD: support.c,v 1.13 2009/06/04 04:48:04 dholland Exp $ */ +/* $NetBSD: support.c,v 1.14 2009/08/12 05:48:04 dholland 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.13 2009/06/04 04:48:04 dholland Exp $"); +__RCSID("$NetBSD: support.c,v 1.14 2009/08/12 05:48:04 dholland Exp $"); #endif #endif /* not lint */ @@ -49,7 +49,11 @@ __RCSID("$NetBSD: support.c,v 1.13 2009/06/04 04:48:04 dholland Exp $"); #define NTV 10 /* number scores to test */ /* score to test reachability of, and order to test them in */ -const int tv[NTV] = {8, 7, 9, 6, 11, 12, 13, 14, 10, 5}; +static const int tv[NTV] = {8, 7, 9, 6, 11, 12, 13, 14, 10, 5}; + +static int anysumto(const CARD[], int, int, int); +static void prpeg(int, int, BOOLEAN); +static int numofval(const CARD[], int, int); /* * computer chooses what to play in pegging... @@ -199,7 +203,7 @@ chkscr(int *scr, int inc) * Put out the peg character on the score board and put the * score up on the board. */ -void +static void prpeg(int curscore, int pegc, BOOLEAN myturn) { int y, x; @@ -306,7 +310,7 @@ anymove(const CARD hand[], int n, int sum) * 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 */ -int +static int anysumto(const CARD hand[], int n, int s, int t) { int i; @@ -321,7 +325,7 @@ anysumto(const CARD hand[], int n, int s, int t) /* * return the number of cards in h having the given rank value */ -int +static int numofval(const CARD h[], int n, int v) { int i, j; |
