4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / games / cribbage / crib.c
index 4a6834f..fedfdad 100644 (file)
-# include      <curses.h>
-# include      <signal.h>
-# include      "deck.h"
-# include      "cribbage.h"
-# include      "cribcur.h"
+/*-
+ * Copyright (c) 1980, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ */
+
+#ifndef lint
+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[] = "@(#)crib.c     8.1 (Berkeley) %G%";
+#endif /* not lint */
 
 
-# define       LOGFILE         "/usr/games/lib/criblog"
-# define       INSTRCMD        "ul /usr/games/lib/crib.instr | more -f"
+#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)
 main(argc, argv)
-int    argc;
-char   *argv[];
+       int argc;
+       char *argv[];
 {
 {
-       register  char          *p;
-       BOOLEAN                 playing;
-       char                    *s;             /* for reading arguments */
-       char                    bust;           /* flag for arg reader */
-       FILE                    *f;
-       FILE                    *fopen();
-       char                    *getline();
-       int                     bye();
-
-       while (--argc > 0) {
-           if ((*++argv)[0] != '-') {
-               fprintf(stderr, "\n\ncribbage: usage is 'cribbage [-eqr]'\n");
-               exit(1);
-           }
-           bust = FALSE;
-           for (s = argv[0] + 1; *s != NULL; s++) {
-               switch (*s) {
-                   case 'e':
+       BOOLEAN playing;
+       FILE *f;
+       int ch;
+
+       while ((ch = getopt(argc, argv, "eqr")) != EOF)
+               switch (ch) {
+               case 'e':
                        explain = TRUE;
                        break;
                        explain = TRUE;
                        break;
-                   case 'q':
+               case 'q':
                        quiet = TRUE;
                        break;
                        quiet = TRUE;
                        break;
-                   case 'r':
+               case 'r':
                        rflag = TRUE;
                        break;
                        rflag = TRUE;
                        break;
-                   default:
-                       fprintf(stderr, "\n\ncribbage: usage is 'cribbage [-eqr]'\n");
-                       exit(2);
-                       break;
+               case '?':
+               default:
+                       (void) fprintf(stderr, "usage: cribbage [-eqr]\n");
+                       exit(1);
                }
                }
-               if (bust)
-                   break;
-           }
-       }
 
        initscr();
 
        initscr();
-       signal(SIGINT, bye);
+       (void)signal(SIGINT, rint);
        crmode();
        noecho();
        crmode();
        noecho();
-       Playwin = subwin(stdscr, PLAY_Y, PLAY_X, 0, X_SCORE_SZ);
-       Tablewin = subwin(stdscr, TABLE_Y, TABLE_X, 0, PLAY_X + X_SCORE_SZ);
-       Compwin = subwin(stdscr, COMP_Y, COMP_X, 0, TABLE_X + PLAY_X + X_SCORE_SZ);
-       Msgwin = subwin(stdscr, MSG_Y, MSG_X, Y_SCORE_SZ + 1, 0);
+
+       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);
+       Msgwin = subwin(stdscr, MSG_Y, MSG_X, Y_MSG_START, SCORE_X + 1);
        leaveok(Playwin, TRUE);
        leaveok(Tablewin, TRUE);
        leaveok(Compwin, TRUE);
        clearok(stdscr, FALSE);
 
        if (!quiet) {
        leaveok(Playwin, TRUE);
        leaveok(Tablewin, TRUE);
        leaveok(Compwin, TRUE);
        clearok(stdscr, FALSE);
 
        if (!quiet) {
-           msg("Do you need instructions for cribbage? ");
-           if (getuchar() == 'Y') {
-               endwin();
-               fflush(stdout);
-               system(INSTRCMD);
-               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 {
        }
        playing = TRUE;
        do {
-           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);
 
        } while (playing);
 
-       if ((f = fopen(LOGFILE, "a")) != NULL) {
-           fprintf(f, "Won %5.5d, Lost %5.5d\n",  cgames, pgames);
-           fclose(f);
+       if (f = fopen(_PATH_LOG, "a")) {
+               (void)fprintf(f, "%s: won %5.5d, lost %5.5d\n",
+                   getlogin(), cgames, pgames);
+               (void) fclose(f);
        }
        }
-
        bye();
        bye();
-}
-
-/*
- * bye:
- *     Leave the program, cleaning things up as we go.
- */
-bye()
-{
-       signal(SIGINT, SIG_IGN);
-       mvcur(0, COLS - 1, LINES - 1, 0);
-       fflush(stdout);
-       endwin();
-       putchar('\n');
-       exit(1);
+       if (!f) {
+               (void) fprintf(stderr, "\ncribbage: can't open %s.\n",
+                   _PATH_LOG);
+               exit(1);
+       }
+       exit(0);
 }
 
 /*
  * makeboard:
  *     Print out the initial board on the screen
  */
 }
 
 /*
  * makeboard:
  *     Print out the initial board on the screen
  */
+void
 makeboard()
 {
 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
  */
 }
 
 /*
  * gamescore:
  *     Print out the current game score
  */
+void
 gamescore()
 {
 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;
 }
 
 /*
 }
 
 /*
@@ -148,91 +158,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.
  */
  *     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()
 {
 game()
 {
-       register int            i, j;
-       BOOLEAN                 flag;
-       BOOLEAN                 compcrib;
+       register int i, j;
+       BOOLEAN flag;
+       BOOLEAN compcrib;
 
 
-       makeboard();
-       refresh();
        makedeck(deck);
        shuffle(deck);
        if (gamecount == 0) {
        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 {
        }
 
        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) {
        } 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();
 }
        }
        gamescore();
 }
@@ -241,11 +248,11 @@ game()
  * playhand:
  *     Do up one hand of the game
  */
  * playhand:
  *     Do up one hand of the game
  */
+int
 playhand(mycrib)
 playhand(mycrib)
-BOOLEAN                mycrib;
+       BOOLEAN mycrib;
 {
 {
-       register int            deckpos;
-       extern char             Msgbuf[];
+       register int deckpos;
 
        werase(Compwin);
 
 
        werase(Compwin);
 
@@ -257,38 +264,35 @@ BOOLEAN           mycrib;
        prhand(phand, FULLHAND, Playwin, FALSE);
        discard(mycrib);
        if (cut(mycrib, deckpos))
        prhand(phand, FULLHAND, Playwin, FALSE);
        discard(mycrib);
        if (cut(mycrib, deckpos))
-           return TRUE;
+               return TRUE;
        if (peg(mycrib))
        if (peg(mycrib))
-           return TRUE;
+               return TRUE;
        werase(Tablewin);
        wrefresh(Tablewin);
        if (score(mycrib))
        werase(Tablewin);
        wrefresh(Tablewin);
        if (score(mycrib))
-           return TRUE;
+               return TRUE;
        return FALSE;
 }
 
        return FALSE;
 }
 
-
-
 /*
  * deal cards to both players from deck
  */
 /*
  * 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);
 }
 
 /*
 }
 
 /*
@@ -296,22 +300,24 @@ deal( mycrib )
  *     Handle players discarding into the crib...
  * Note: we call cdiscard() after prining first message so player doesn't wait
  */
  *     Handle players discarding into the crib...
  * Note: we call cdiscard() after prining first message so player doesn't wait
  */
+void
 discard(mycrib)
 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 --> ");
 
        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)];
        crd = phand[infrom(phand, FULLHAND, prompt)];
-       remove(crd, phand, FULLHAND);
+       cremove(crd, phand, FULLHAND);
        prhand(phand, FULLHAND, Playwin, FALSE);
        crib[0] = crd;
        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)];
        crd = phand[infrom(phand, FULLHAND - 1, prompt)];
-       remove(crd, phand, FULLHAND - 1);
+       cremove(crd, phand, FULLHAND - 1);
        prhand(phand, FULLHAND, Playwin, FALSE);
        crib[1] = crd;
        crib[2] = chand[4];
        prhand(phand, FULLHAND, Playwin, FALSE);
        crib[1] = crd;
        crib[2] = chand[4];
@@ -324,227 +330,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.
  */
  *     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)
 cut(mycrib, pos)
-BOOLEAN                mycrib;
-int            pos;
+       BOOLEAN mycrib;
+       int  pos;
 {
 {
-       register int            i, cardx;
-       BOOLEAN                 win = FALSE;
+       register int i;
+       BOOLEAN win;
 
 
+       win = FALSE;
        if (mycrib) {
        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);
        }
        makeknown(&turnover, 1);
        prcrib(mycrib, FALSE);
-       return win;
+       return (win);
 }
 
 /*
  * prcrib:
  *     Print out the turnover card with crib indicator
  */
 }
 
 /*
  * prcrib:
  *     Print out the turnover card with crib indicator
  */
+void
 prcrib(mycrib, blank)
 prcrib(mycrib, blank)
-BOOLEAN                mycrib, blank;
+       BOOLEAN mycrib, blank;
 {
 {
-       register int    y, cardx;
+       register int y, cardx;
 
        if (mycrib)
 
        if (mycrib)
-           cardx = CRIB_X;
+               cardx = CRIB_X;
        else
        else
-           cardx = X_SCORE_SZ;
+               cardx = 0;
 
        mvaddstr(CRIB_Y, cardx + 1, "CRIB");
        prcard(stdscr, CRIB_Y + 1, cardx, turnover, blank);
 
        if (mycrib)
 
        mvaddstr(CRIB_Y, cardx + 1, "CRIB");
        prcard(stdscr, CRIB_Y + 1, cardx, turnover, blank);
 
        if (mycrib)
-           cardx = X_SCORE_SZ;
+               cardx = 0;
        else
        else
-           cardx = CRIB_X;
+               cardx = CRIB_X;
 
        for (y = CRIB_Y; y <= CRIB_Y + 5; y++)
 
        for (y = CRIB_Y; y <= CRIB_Y + 5; y++)
-           mvaddstr(y, cardx, "       ");
+               mvaddstr(y, cardx, "       ");
 }
 
 /*
  * peg:
  *     Handle all the pegging...
  */
 }
 
 /*
  * peg:
  *     Handle all the pegging...
  */
+static CARD Table[14];
+static int Tcnt;
 
 
-static CARD            Table[14];
-
-static int             Tcnt;
-
+int
 peg(mycrib)
 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;
 
        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 (;;) {
        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];
-                   remove(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.");
-                       if (chkscr(&cscore, 1))
-                           return TRUE;
+               if (sum >= 31) {
+                       if (!myturn)
+                               do_wait();
                        sum = 0;
                        mego = ugo = FALSE;
                        Tcnt = 0;
                        sum = 0;
                        mego = ugo = FALSE;
                        Tcnt = 0;
-                   }
+                       last = FALSE;                   /* disable last flag */
                }
                }
-               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);
-                   remove(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 (sum >= 31) {
-               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)
        }
        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");
-               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");
                            "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
  */
 }
 
 /*
  * prtable:
  *     Print out the table with the current score
  */
+void
 prtable(score)
 prtable(score)
-int    score;
+       int score;
 {
        prhand(Table, Tcnt, Tablewin, FALSE);
        mvwprintw(Tablewin, (Tcnt + 2) * 2, Tcnt + 1, "%2d", score);
 {
        prhand(Table, Tcnt, Tablewin, FALSE);
        mvwprintw(Tablewin, (Tcnt + 2) * 2, Tcnt + 1, "%2d", score);
@@ -555,25 +571,26 @@ int       score;
  * score:
  *     Handle the scoring of the hands
  */
  * score:
  *     Handle the scoring of the hands
  */
+int
 score(mycrib)
 score(mycrib)
-BOOLEAN                mycrib;
+       BOOLEAN mycrib;
 {
        sorthand(crib, CINHAND);
        if (mycrib) {
 {
        sorthand(crib, CINHAND);
        if (mycrib) {
-           if (plyrhand(phand, "hand"))
-               return TRUE;
-           if (comphand(chand, "hand"))
-               return TRUE;
-           if (comphand(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);
        }
        }
-       else {
-           if (comphand(chand, "hand"))
-               return TRUE;
-           if (plyrhand(phand, "hand"))
-               return TRUE;
-           if (plyrhand(crib, "crib"))
-               return TRUE;
-       }
-       return FALSE;
+       return (FALSE);
 }
 }