BSD 4_3_Net_2 release
[unix-history] / usr / src / games / fish / fish.c
index 88416b8..0147ff2 100644 (file)
-/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Muffy Barkocy.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
 char copyright[] =
  */
 
 #ifndef lint
 char copyright[] =
-"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
  All rights reserved.\n";
  All rights reserved.\n";
-#endif not lint
+#endif /* not lint */
 
 #ifndef lint
 
 #ifndef lint
-static char sccsid[] = "@(#)fish.c     5.2 (Berkeley) 11/30/89";
-#endif not lint
-
-# include <stdio.h>
-
-/*     Through, `my' refers to the program, `your' to the player */
-
-# define CTYPE 13
-# define CTSIZ (CTYPE+1)
-# define DECK 52
-# define NOMORE 0
-# define DOUBTIT (-1);
-
-typedef char HAND[CTSIZ];
-
-/* data structures */
-
-short debug;
-
-HAND myhand;
-HAND yourhand;
-char deck[DECK];
-short nextcd;
-int proflag;
-
-/* utility and output programs */
-
-shuffle(){
-       /* shuffle the deck, and reset nextcd */
-       /* uses the random number generator `rand' in the C library */
-       /* assumes that `srand' has already been called */
-
-       register i;
-
-       for( i=0; i<DECK; ++i ) deck[i] = (i%13)+1;  /* seed the deck */
-
-       for( i=DECK; i>0; --i ){ /* select the next card at random */
-               deck[i-1] = choose( deck, i );
+static char sccsid[] = "@(#)fish.c     5.4 (Berkeley) 1/18/91";
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <sys/errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "pathnames.h"
+
+#define        RANKS           13
+#define        HANDSIZE        7
+#define        CARDS           4
+
+#define        USER            1
+#define        COMPUTER        0
+#define        OTHER(a)        (1 - (a))
+
+char *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[RANKS];
+int userasked[RANKS], userhand[RANKS];
+
+main(argc, argv)
+       int argc;
+       char **argv;
+{
+       int ch, move;
+
+       while ((ch = getopt(argc, argv, "p")) != EOF)
+               switch(ch) {
+               case 'p':
+                       promode = 1;
+                       break;
+               case '?':
+               default:
+                       (void)fprintf(stderr, "usage: fish [-p]\n");
+                       exit(1);
                }
 
                }
 
-       nextcd = 0;
-       }
-
-choose( a, n ) char a[]; {
-       /* pick and return one at random from the n choices in a */
-       /* The last one is moved to replace the one chosen */
-       register j, t;
-
-       if( n <= 0 ) error( "null choice" );
+       srandom(time((time_t *)NULL));
+       instructions();
+       init();
 
 
-       j = rand() % n;
-       t = a[j];
-       a[j] = a[n-1];
-       return(t);
+       if (nrandom(2) == 1) {
+               printplayer(COMPUTER);
+               (void)printf("get to start.\n");
+               goto istart;
        }
        }
-
-draw() {
-       if( nextcd >= DECK ) return( NOMORE );
-       return( deck[nextcd++] );
-       }
-
-error( s ) char *s; {
-       fprintf( stderr, "error: " );
-       fprintf( stderr, s );
-       exit( 1 );
-       }
-
-empty( h ) HAND h; {
-       register i;
-
-       for( i=1; i<=CTYPE; ++i ){
-               if( h[i] != 0 && h[i] != 4 ) return( 0 );
-               }
-       return( i );
-       }
-
-mark( hand, cd ) HAND hand; {
-       if( cd != NOMORE ){
-               ++hand[cd];
-               if( hand[cd] > 4 ){
-                       error( "mark overflow" );
-                       }
+       printplayer(USER);
+       (void)printf("get to start.\n");
+       
+       for (;;) {
+               move = usermove();
+               if (!comphand[move]) {
+                       if (gofish(move, USER, userhand))
+                               continue;
+               } else {
+                       goodmove(USER, move, userhand, comphand);
+                       continue;
                }
                }
-       return( cd );
-       }
 
 
-deal( hand, n ) HAND hand; {
-       while( n-- ){
-               if( mark( hand, draw() ) == NOMORE ) error( "deck exhausted" );
+istart:                for (;;) {
+                       move = compmove();
+                       if (!userhand[move]) {
+                               if (!gofish(move, COMPUTER, comphand))
+                                       break;
+                       } else
+                               goodmove(COMPUTER, move, comphand, userhand);
                }
        }
                }
        }
-
-char *cname[] = {
-       "NOMORE!!!",
-       "A",
-       "2",
-       "3",
-       "4",
-       "5",
-       "6",
-       "7",
-       "8",
-       "9",
-       "10",
-       "J",
-       "Q",
-       "K",
-       };
-
-stats(){
-       register i, ct, b;
-
-       if( proflag ) printf( "Pro level\n" );
-       b = ct = 0;
-
-       for( i=1; i<=CTYPE; ++i ){
-               if( myhand[i] == 4 ) ++b;
-               else ct += myhand[i];
+       /* NOTREACHED */
+}
+
+usermove()
+{
+       register int n;
+       register char **p;
+       char buf[256];
+
+       (void)printf("\nYour hand is:");
+       printhand(userhand);
+
+       for (;;) {
+               (void)printf("You ask me for: ");
+               (void)fflush(stdout);
+               if (fgets(buf, BUFSIZ, stdin) == NULL)
+                       exit(0);
+               if (buf[0] == '\0')
+                       continue;
+               if (buf[0] == '\n') {
+                       (void)printf("%d cards in my hand, %d in the pool.\n",
+                           countcards(comphand), countcards(deck));
+                       (void)printf("My books:");
+                       (void)countbooks(comphand);
+                       continue;
                }
                }
-
-       if( b ){
-               printf( "My books: " );
-               for( i=1; i<=CTYPE; ++i ){
-                       if( myhand[i] == 4 ) printf( "%s ", cname[i] );
-                       }
-               printf( "\n" );
+               buf[strlen(buf) - 1] = '\0';
+               if (!strcasecmp(buf, "p") && !promode) {
+                       promode = 1;
+                       (void)printf("Entering pro mode.\n");
+                       continue;
                }
                }
-
-       printf( "%d cards in my hand, %d in the pool\n", ct, DECK-nextcd );
-       printf( "You ask me for: " );
-       }
-
-phand( h ) HAND h; {
-       register i, j;
-
-       j = 0;
-
-       for( i = 1; i<= CTYPE; ++i ){
-               if( h[i] == 4 ) {
-                       ++j;
+               if (!strcasecmp(buf, "quit"))
+                       exit(0);
+               for (p = cards; *p; ++p)
+                       if (!strcasecmp(*p, buf))
+                               break;
+               if (!*p) {
+                       (void)printf("I don't understand!\n");
                        continue;
                        continue;
-                       }
-               if( h[i] ){
-                       register k;
-                       k = h[i];
-                       while( k-- ) printf( "%s ", cname[i] );
-                       }
                }
                }
-
-       if( j ){
-               printf( "+ Books of " );
-               for( i=1; i<=CTYPE; ++i ){
-                       if( h[i] == 4 ) printf( "%s ", cname[i] );
-                       }
+               n = p - cards;
+               if (userhand[n]) {
+                       userasked[n] = 1;
+                       return(n);
                }
                }
-
-       printf( "\n" );
+               if (nrandom(3) == 1)
+                       (void)printf("You don't have any of those!\n");
+               else
+                       (void)printf("You don't have any %s's!\n", cards[n]);
+               if (nrandom(4) == 1)
+                       (void)printf("No cheating!\n");
+               (void)printf("Guess again.\n");
        }
        }
+       /* NOTREACHED */
+}
+
+compmove()
+{
+       static int lmove;
+
+       if (promode)
+               lmove = promove();
+       else {
+               do {
+                       lmove = (lmove + 1) % RANKS;
+               } while (!comphand[lmove] || comphand[lmove] == CARDS);
+       }
+       asked[lmove] = 1;
 
 
-main( argc, argv ) char * argv[]; { 
-       /* initialize shuffling, ask for instructions, play game, die */
-       register c;
-
-       if( argc > 1 && argv[1][0] == '-' ){
-               while( argv[1][0] == '-' ) { ++argv[1]; ++debug; }
-               argv++;
-               argc--;
-               }
+       (void)printf("I ask you for: %s.\n", cards[lmove]);
+       return(lmove);
+}
 
 
-       srand( getpid() );
+promove()
+{
+       register int i, max;
 
 
-       printf( "instructions?\n" );
-       if( (c=getchar()) != '\n' ){
-               if( c != 'n' ) instruct();
-               while( getchar() != '\n' );
+       for (i = 0; i < RANKS; ++i)
+               if (userasked[i] &&
+                   comphand[i] > 0 && comphand[i] < CARDS) {
+                       userasked[i] = 0;
+                       return(i);
                }
                }
-
-       game();
+       if (nrandom(3) == 1) {
+               for (i = 0;; ++i)
+                       if (comphand[i] && comphand[i] != CARDS) {
+                               max = i;
+                               break;
+                       }
+               while (++i < RANKS) 
+                       if (comphand[i] != CARDS &&
+                           comphand[i] > comphand[max])
+                               max = i;
+               return(max);
+       } 
+       if (nrandom(1024) == 0723) {
+               for (i = 0; i < RANKS; ++i)
+                       if (userhand[i] && comphand[i])
+                               return(i);
        }
        }
-
-/*     print instructions */
-
-char *inst[] = {
-       "`Go Fish' is a childrens' card game.  The Object is to",
-       "accumulate `books' of 4 cards with the same face value.  The",
-       "players alternate turns; each turn begins with one player",
-       "selecting a card from his hand, and asking the other player for",
-       "all cards of that face value.  If the other player has one or",
-       "more cards of that face value in his hand, he gives them to the",
-       "first player, and the first player makes another request.",
-       "Eventually, the first player asks for a card which is not in",
-       "the second player's hand: he replies `GO FISH!' The first",
-       "player then draws a card from the `pool' of undealt cards.  If",
-       "this is the card he had last requested, he draws again.  When a",
-       "book is made, either through drawing or requesting, the cards",
-       "are laid down and no further action takes place with that face",
-       "value.  To play the computer, simply make guesses by typing a,",
-       "2, 3, 4, 5, 6, 7, 8, 9, 10, j, q, or k when asked.  Hitting",
-       "return gives you information about the size of my hand and the",
-       "pool, and tells you about my books.  Saying `p' as a first",
-       "guess puts you into `pro' level; The default is pretty dumb!",
-       "Good Luck!\n",
-       "",
-       };
-
-instruct(){
-       register char **cpp;
-
-       printf( "\n" );
-
-       for( cpp = inst; **cpp != '\0'; ++cpp ){
-               printf( "%s\n", *cpp );
-               }
+       for (;;) {
+               for (i = 0; i < RANKS; ++i)
+                       if (comphand[i] && comphand[i] != CARDS &&
+                           !asked[i])
+                               return(i);
+               for (i = 0; i < RANKS; ++i)
+                       asked[i] = 0;
        }
        }
-
-game(){
-
-       shuffle();
-
-       deal( myhand, 7 );
-       deal( yourhand, 7 );
-
-       for(;;){
-
-               register g;
-
-
-               /* you make repeated guesses */
-
-               for(;;) {
-                       printf( "your hand is: " );
-                       phand( yourhand );
-                       printf( "you ask me for: " );
-                       if( !move( yourhand, myhand, g=guess(), 0 ) ) break;
-                       printf( "Guess again\n" );
-                       }
-
-               /* I make repeated guesses */
-
-               for(;;) {
-                       if( (g=myguess()) != NOMORE ){
-                               printf( "I ask you for: %s\n", cname[g] );
-                               }
-                       if( !move( myhand, yourhand, g, 1 ) ) break;
-                       printf( "I get another guess\n" );
-                       }
-               }
+       /* NOTREACHED */
+}
+
+drawcard(player, hand)
+       int player;
+       int *hand;
+{
+       int card;
+
+       while (deck[card = nrandom(RANKS)] == 0);
+       ++hand[card];
+       --deck[card];
+       if (player == USER || hand[card] == CARDS) {
+               printplayer(player);
+               (void)printf("drew %s", cards[card]);
+               if (hand[card] == CARDS) {
+                       (void)printf(" and made a book of %s's!\n",
+                            cards[card]);
+                       chkwinner(player, hand);
+               } else
+                       (void)printf(".\n");
        }
        }
-
-/*     reflect the effect of a move on the hands */
-
-move( hs, ht, g, v ) HAND hs, ht; {
-       /* hand hs has made a guess, g, directed towards ht */
-       /* v on indicates that the guess was made by the machine */
-       register d;
-       char *sp, *tp;
-
-       sp = tp = "I";
-       if( v ) tp = "You";
-       else sp = "You";
-
-       if( g == NOMORE ){
-               d = draw();
-               if( d == NOMORE ) score();
-               else {
-
-                       printf( "Empty Hand\n" );
-                       if( !v ) printf( "You draw %s\n", cname[d] );
-                       mark( hs, d );
-                       }
-               return( 0 );
-               }
-
-       if( !v ) heguessed( g );
-
-       if( hs[g] == 0 ){
-               if( v ) error( "Rotten Guess" );
-               printf( "You don't have any %s's\n", cname[g] );
-               return(1);
-               }
-
-       if( ht[g] ){ /* successful guess */
-               printf( "%s have %d %s%s\n", tp, ht[g], cname[g], ht[g]>1?"'s":"" );
-               hs[g] += ht[g];
-               ht[g] = 0;
-               if( hs[g] == 4 ) madebook(g);
+       return(card);
+}
+
+gofish(askedfor, player, hand)
+       int askedfor, player;
+       int *hand;
+{
+       printplayer(OTHER(player));
+       (void)printf("say \"GO FISH!\"\n");
+       if (askedfor == drawcard(player, hand)) {
+               printplayer(player);
+               (void)printf("drew the guess!\n");
+               printplayer(player);
+               (void)printf("get to ask again!\n");
                return(1);
                return(1);
-               }
-
-       /* GO FISH! */
-
-       printf( "%s say \"GO FISH!\"\n", tp );
-
-       newdraw:
-       d = draw();
-       if( d == NOMORE ) {
-               printf( "No more cards\n" );
-               return(0);
-               }
-       mark( hs, d );
-       if( !v ) printf( "You draw %s\n", cname[d] );
-       if( hs[d] == 4 ) madebook(d);
-       if( d == g ){
-               printf( "%s drew the guess, so draw again\n", sp );
-               if( !v ) hedrew( d );
-               goto newdraw;
-               }
-       return( 0 );
        }
        }
-
-madebook( x ){
-       printf( "Made a book of %s's\n", cname[x] );
+       return(0);
+}
+
+goodmove(player, move, hand, opphand)
+       int player, move;
+       int *hand, *opphand;
+{
+       printplayer(OTHER(player));
+       (void)printf("have %d %s%s.\n",
+           opphand[move], cards[move], opphand[move] == 1 ? "": "'s");
+
+       hand[move] += opphand[move];
+       opphand[move] = 0;
+
+       if (hand[move] == CARDS) {
+               printplayer(player);
+               (void)printf("made a book of %s's!\n", cards[move]);
+               chkwinner(player, hand);
        }
 
        }
 
-score(){
-       register my, your, i;
-
-       my = your = 0;
-
-       printf( "The game is over.\nMy books: " );
-
-       for( i=1; i<=CTYPE;++i ){
-               if( myhand[i] == 4 ){
-                       ++my;
-                       printf( "%s ", cname[i] );
-                       }
-               }
-
-       printf( "\nYour books: " );
-
-       for( i=1; i<=CTYPE;++i ){
-               if( yourhand[i] == 4 ){
-                       ++your;
-                       printf( "%s ", cname[i] );
-                       }
-               }
-
-       printf( "\n\nI have %d, you have %d\n", my, your );
-
-       printf( "\n%s win!!!\n", my>your?"I":"You" );
+       chkwinner(OTHER(player), opphand);
+
+       printplayer(player);
+       (void)printf("get another guess!\n");
+}
+
+chkwinner(player, hand)
+       int player;
+       register int *hand;
+{
+       register int cb, i, ub;
+
+       for (i = 0; i < RANKS; ++i)
+               if (hand[i] > 0 && hand[i] < CARDS)
+                       return;
+       printplayer(player);
+       (void)printf("don't have any more cards!\n");
+       (void)printf("My books:");
+       cb = countbooks(comphand);
+       (void)printf("Your books:");
+       ub = countbooks(userhand);
+       (void)printf("\nI have %d, you have %d.\n", cb, ub);
+       if (ub > cb) {
+               (void)printf("\nYou win!!!\n");
+               if (nrandom(1024) == 0723)
+                       (void)printf("Cheater, cheater, pumpkin eater!\n");
+       } else if (cb > ub) {
+               (void)printf("\nI win!!!\n");
+               if (nrandom(1024) == 0723)
+                       (void)printf("Hah!  Stupid peasant!\n");
+       } else
+               (void)printf("\nTie!\n");
        exit(0);
        exit(0);
+}
+
+printplayer(player)
+       int player;
+{
+       switch (player) {
+       case COMPUTER:
+               (void)printf("I ");
+               break;
+       case USER:
+               (void)printf("You ");
+               break;
        }
        }
-
-# define G(x) { if(go) goto err;  else go = x; }
-
-guess(){
-       /* get the guess from the tty and return it... */
-       register g, go;
-
-       go = 0;
-
-       for(;;) {
-               switch( g = getchar() ){
-
-               case 'p':
-               case 'P':
-                       ++proflag;
-                       continue;
-
-               case '2':
-               case '3':
-               case '4':
-               case '5':
-               case '6':
-               case '7':
-               case '8':
-               case '9':
-                       G(g-'0');
-                       continue;
-
-               case 'a':
-               case 'A':
-                       G(1);
-                       continue;
-
-               case '1':
-                       G(10);
-                       continue;
-
-               case '0':
-                       if( go != 10 ) goto err;
-                       continue;
-
-               case 'J':
-               case 'j':
-                       G(11);
-                       continue;
-
-               case 'Q':
-               case 'q':
-                       G(12);
-                       continue;
-
-               case 'K':
-               case 'k':
-                       G(13);
-                       continue;
-
-               case '\n':
-                       if( empty( yourhand ) ) return( NOMORE );
-                       if( go == 0 ){
-                               stats();
-                               continue;
-                               }
-                       return( go );
-
-               case ' ':
-               case '\t':
-                       continue;
-
-               default:
-                       err:
-                       while( g != '\n' ) g = getchar();
-                       printf( "what?\n" );
-                       continue;
-                       }
-               }
+}
+
+printhand(hand)
+       int *hand;
+{
+       register int book, i, j;
+
+       for (book = i = 0; i < RANKS; i++)
+               if (hand[i] < CARDS)
+                       for (j = hand[i]; --j >= 0;) 
+                               PRC(i);
+               else
+                       ++book;
+       if (book) {
+               (void)printf(" + Book%s of", book > 1 ? "s" : "");
+               for (i = 0; i < RANKS; i++)
+                       if (hand[i] == CARDS)
+                               PRC(i);
        }
        }
-
-/*     the program's strategy appears from here to the end */
-
-char try[100];
-char ntry;
-char haveguessed[CTSIZ];
-
-char hehas[CTSIZ];
-
-hedrew( d ){
-       ++hehas[d];
-       }
-
-heguessed( d ){
-       ++hehas[d];
-       }
-
-myguess(){
-
-       register i, lg, t;
-
-       if( empty( myhand ) ) return( NOMORE );
-
-       /* make a list of those things which i have */
-       /* leave off any which are books */
-       /* if something is found that he has, guess it! */
-
-       ntry = 0;
-       for( i=1; i<=CTYPE; ++i ){
-               if( myhand[i] == 0 || myhand[i] == 4 ) continue;
-               try[ntry++] = i;
-               }
-
-       if( !proflag ) goto random;
-
-       /* get ones he has, if any */
-
-       for( i=0; i<ntry; ++i ){
-               if( hehas[try[i]] ) {
-                       i = try[i];
-                       goto gotguess;
-                       }
-               }
-
-       /* is there one that has never been guessed; if so, guess it */
-       lg = 101;
-       for( i=0; i<ntry; ++i ){
-               if( haveguessed[try[i]] < lg ) lg = haveguessed[try[i]];
+       (void)putchar('\n');
+}
+
+countcards(hand)
+       register int *hand;
+{
+       register int i, count;
+
+       for (count = i = 0; i < RANKS; i++)
+               count += *hand++;
+       return(count);
+}
+
+countbooks(hand)
+       int *hand;
+{
+       int i, count;
+
+       for (count = i = 0; i < RANKS; i++)
+               if (hand[i] == CARDS) {
+                       ++count;
+                       PRC(i);
                }
                }
-       /* remove all those not guessed longest ago */
-
-       t = 0;
-       for( i=0; i<ntry; ++i ){
-               if( haveguessed[try[i]] == lg ) try[t++] = try[i];
-               }
-       ntry = t;
-       if( t <= 0 ) error( "bad guessing loop" );
-
-       random:
-       i = choose( try, ntry );  /* make a random choice */
-
-       gotguess:  /* do bookkeeping */
-
-       hehas[i] = 0;  /* he won't anymore! */
-       for( t=1; t<=CTYPE; ++t ){
-               if( haveguessed[t] ) --haveguessed[t];
-               }
-       haveguessed[i] = 100;  /* will have guessed it */
-       return(i);
-
+       if (!count)
+               (void)printf(" none");
+       (void)putchar('\n');
+       return(count);
+}
+
+init()
+{
+       register int i, rank;
+
+       for (i = 0; i < RANKS; ++i)
+               deck[i] = CARDS;
+       for (i = 0; i < HANDSIZE; ++i) {
+               while (!deck[rank = nrandom(RANKS)]);
+               ++userhand[rank];
+               --deck[rank];
        }
        }
-
+       for (i = 0; i < HANDSIZE; ++i) {
+               while (!deck[rank = nrandom(RANKS)]);
+               ++comphand[rank];
+               --deck[rank];
+       }
+}
+
+nrandom(n)
+       int n;
+{
+       long random();
+
+       return((int)random() % n);
+}
+
+instructions()
+{
+       int input;
+       char buf[1024];
+
+       (void)printf("Would you like instructions (y or n)? ");
+       input = getchar();
+       while (getchar() != '\n');
+       if (input != 'y')
+               return;
+
+       (void)sprintf(buf, "%s %s", _PATH_MORE, _PATH_INSTR);
+       (void)system(buf);
+       (void)printf("Hit return to continue...\n");
+       while ((input = getchar()) != EOF && input != '\n');
+}
+
+usage()
+{
+       (void)fprintf(stderr, "usage: fish [-p]\n");
+       exit(1);
+}