-/* $NetBSD: fish.c,v 1.16 2005/02/15 12:56:20 jsm Exp $ */
+/* $NetBSD: fish.c,v 1.23 2018/03/05 04:59:54 eadler Exp $ */
/*-
* Copyright (c) 1990, 1993
#include <sys/cdefs.h>
#ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1990, 1993\n\
- The Regents of the University of California. All rights reserved.\n");
+__COPYRIGHT("@(#) Copyright (c) 1990, 1993\
+ The Regents of the University of California. All rights reserved.");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)fish.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: fish.c,v 1.16 2005/02/15 12:56:20 jsm Exp $");
+__RCSID("$NetBSD: fish.c,v 1.23 2018/03/05 04:59:54 eadler Exp $");
#endif
#endif /* not lint */
#define COMPUTER 0
#define OTHER(a) (1 - (a))
-const char *const cards[] = {
+static const char *const cards[] = {
"A", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "J", "Q", "K", NULL,
};
#define PRC(card) (void)printf(" %s", cards[card])
-int promode;
-int asked[RANKS], comphand[RANKS], deck[TOTCARDS];
-int userasked[RANKS], userhand[RANKS];
-int curcard = TOTCARDS;
-
-void chkwinner(int, const int *);
-int compmove(void);
-int countbooks(const int *);
-int countcards(const int *);
-int drawcard(int, int *);
-int gofish(int, int, int *);
-void goodmove(int, int, int *, int *);
-void init(void);
-void instructions(void);
-int main(int, char *[]);
-int nrandom(int);
-void printhand(const int *);
-void printplayer(int);
-int promove(void);
-void usage(void) __attribute__((__noreturn__));
-int usermove(void);
+static int promode;
+static int asked[RANKS], comphand[RANKS], deck[TOTCARDS];
+static int userasked[RANKS], userhand[RANKS];
+static int curcard = TOTCARDS;
+
+static void chkwinner(int, const int *);
+static int compmove(void);
+static int countbooks(const int *);
+static int countcards(const int *);
+static int drawcard(int, int *);
+static int gofish(int, int, int *);
+static void goodmove(int, int, int *, int *);
+static void init(void);
+static void instructions(void);
+static int nrandom(int);
+static void printhand(const int *);
+static void printplayer(int);
+static int promove(void);
+static void usage(void) __dead;
+static int usermove(void);
int
-main(argc, argv)
- int argc;
- char **argv;
+main(int argc, char **argv)
{
int ch, move;
usage();
}
- srandom(time((time_t *)NULL));
+ srandom(time(NULL));
instructions();
init();
/* NOTREACHED */
}
-int
-usermove()
+static int
+usermove(void)
{
int n;
const char *const *p;
continue;
}
buf[strlen(buf) - 1] = '\0';
- if (!strcasecmp(buf, "p") && !promode) {
- promode = 1;
- (void)printf("Entering pro mode.\n");
+ if (!strcasecmp(buf, "p")) {
+ if (!promode) {
+ promode = 1;
+ printf("Entering pro mode.\n");
+ }
+ else {
+ printf("Already in pro mode.\n");
+ }
continue;
}
if (!strcasecmp(buf, "quit"))
continue;
}
n = p - cards;
- if (userhand[n]) {
+ if (userhand[n] <= 3) {
userasked[n] = 1;
return(n);
}
+ if (userhand[n] == 4) {
+ printf("You already have all of those.\n");
+ continue;
+ }
+
if (nrandom(3) == 1)
(void)printf("You don't have any of those!\n");
else
/* NOTREACHED */
}
-int
-compmove()
+static int
+compmove(void)
{
static int lmove;
return(lmove);
}
-int
-promove()
+static int
+promove(void)
{
int i, max;
/* NOTREACHED */
}
-int
-drawcard(player, hand)
- int player;
- int *hand;
+static int
+drawcard(int player, int *hand)
{
int card;
return(card);
}
-int
-gofish(askedfor, player, hand)
- int askedfor, player;
- int *hand;
+static int
+gofish(int askedfor, int player, int *hand)
{
printplayer(OTHER(player));
(void)printf("say \"GO FISH!\"\n");
return(0);
}
-void
-goodmove(player, move, hand, opphand)
- int player, move;
- int *hand, *opphand;
+static void
+goodmove(int player, int move, int *hand, int *opphand)
{
printplayer(OTHER(player));
(void)printf("have %d %s%s.\n",
(void)printf("get another guess!\n");
}
-void
-chkwinner(player, hand)
- int player;
- const int *hand;
+static void
+chkwinner(int player, const int *hand)
{
int cb, i, ub;
exit(0);
}
-void
-printplayer(player)
- int player;
+static void
+printplayer(int player)
{
switch (player) {
case COMPUTER:
}
}
-void
-printhand(hand)
- const int *hand;
+static void
+printhand(const int *hand)
{
int book, i, j;
(void)putchar('\n');
}
-int
-countcards(hand)
- const int *hand;
+static int
+countcards(const int *hand)
{
int i, count;
return(count);
}
-int
-countbooks(hand)
- const int *hand;
+static int
+countbooks(const int *hand)
{
int i, count;
return(count);
}
-void
-init()
+static void
+init(void)
{
int i, j, temp;
}
}
-int
-nrandom(n)
- int n;
+static int
+nrandom(int n)
{
return((int)random() % n);
}
-void
-instructions()
+static void
+instructions(void)
{
int input;
pid_t pid;
while ((input = getchar()) != EOF && input != '\n');
}
-void
-usage()
+static void
+usage(void)
{
(void)fprintf(stderr, "usage: fish [-p]\n");
exit(1);