BSD 4_3_Reno release
[unix-history] / usr / src / games / cribbage / crib.c
index 6e7ed4f..7c73764 100644 (file)
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that: (1) source distributions retain this entire copyright
+ * notice and comment, and (2) distributions including binaries display
+ * the following acknowledgement:  ``This product includes software
+ * developed by the University of California, Berkeley and its contributors''
+ * in the documentation or other materials provided with the distribution
+ * and in all advertising materials mentioning features or use of this
+ * software. 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
 
 
-#include       <stdio.h>
-#include       "deck.h"
-
-
-#define                LOGFILE         "/usr/games/lib/criblog"
-#define                INSTRCMD        "ul /usr/games/lib/crib.instr | more -f"
-
-
-CARD           deck[ CARDS ];                  /* a deck */
-CARD           phand[ FULLHAND ];              /* player's hand */
-CARD           chand[ FULLHAND ];              /* computer's hand */
-CARD           crib[ CINHAND ];                /* the crib */
-CARD           turnover;                       /* the starter */
-
-CARD           known[ CARDS ];                 /* cards we have seen */
-int            knownum         = 0;            /* number of cards we know */
-
-int            pscore          = 0;            /* player score in current game */
-int            cscore          = 0;            /* comp score in current game */
-int            pgames          = 0;            /* number games player won */
-int            cgames          = 0;            /* number games comp won */
-int            gamecount       = 0;            /* number games played */
-int            glimit          = LGAME;        /* game playe to glimit */
-
-BOOLEAN                iwon            = FALSE;        /* if comp won last game */
-BOOLEAN                explain         = FALSE;        /* player mistakes explained */
-BOOLEAN                rflag           = FALSE;        /* if all cuts random */
-BOOLEAN                quiet           = FALSE;        /* if suppress random mess */
-
-char           expl[ 128 ];                    /* explanation */
-
-
-main( argc, argv )
-
-    int                argc;
-    char       *argv[];
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)crib.c     5.5 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include      <sys/signal.h>
+# include      <curses.h>
+# include      "deck.h"
+# include      "cribbage.h"
+# include      "cribcur.h"
+# include      "pathnames.h"
+
+main(argc, argv)
+int    argc;
+char   *argv[];
 {
 {
-       FILE                    *fopen();
-       FILE                    *f;
-       char                    *getline();
+       extern char *optarg;
+       extern int optind;
        register  char          *p;
        register  char          *p;
+       int ch;
        BOOLEAN                 playing;
        char                    *s;             /* for reading arguments */
        BOOLEAN                 playing;
        char                    *s;             /* for reading arguments */
-       char                    bust;           /* flag for arg reader */
-
-       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 )  {
+       FILE                    *f;
+       FILE                    *fopen();
+       char                    *getline(), *getlogin();
+       void                    rint();
 
 
-                   case  'e':
+       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;
-           }
-       }
-       if( !quiet )  {
-           printf( "\nDo you need instructions for cribbage? " );
-           p = getline();
-           if(  *p == 'Y'  )  {
-               system( INSTRCMD );
-               printf( "\nFor the rules of this game, do 'man cribbage'\n" );
+
+       initscr();
+       signal(SIGINT, rint);
+       crmode();
+       noecho();
+       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) {
+           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 the rules of this program, do \"man cribbage\"");
            }
        }
        playing = TRUE;
            }
        }
        playing = TRUE;
-       do  {
-           printf( quiet ? "\nL or S? " :
-                               "\nLong (to 121) or Short (to 61)? " );
-           p = getline();
-           glimit = ( *p == 'S' ? SGAME : LGAME );
+       do {
+           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();
            game();
-           printf( "\nAnother game? " );
-           p = getline();
-           playing = (*p == 'Y');
-       }  while( playing );
-       if(  ( f = fopen(LOGFILE, "a") ) != NULL  )  {
-           fprintf( f, "Won %5.5d, Lost %5.5d\n",  cgames, pgames );
-           fclose( f );
+           msg("Another game? ");
+           playing = (getuchar() == 'Y');
+       } while (playing);
+
+       if (f = fopen(_PATH_LOG, "a")) {
+               (void)fprintf(f, "%s: won %5.5d, lost %5.5d\n",
+                  getlogin(), cgames, pgames);
+               (void)fclose(f);
        }
        }
+       bye();
+       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()
+{
+    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();
+}
 
 /*
 
 /*
- * play one game up to glimit points
+ * gamescore:
+ *     Print out the current game score
  */
  */
+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;
+}
 
 
+/*
+ * game:
+ *     Play one game up to glimit points.  Actually, we only ASK the
+ *     player what card to turn.  We do a random one, anyway.
+ */
 game()
 {
 game()
 {
-       register  int           i, j;
+       register int            i, j;
        BOOLEAN                 flag;
        BOOLEAN                 compcrib;
 
        BOOLEAN                 flag;
        BOOLEAN                 compcrib;
 
-       makedeck( deck );
-       shuffle( deck );
-       if( gamecount == 0 )  {
+       makeboard();
+       refresh();
+       makedeck(deck);
+       shuffle(deck);
+       if (gamecount == 0) {
            flag = TRUE;
            flag = TRUE;
-           do  {
-               if( rflag )  {                          /* player cuts deck */
-                   i = ( rand() >>4 ) % CARDS;         /* random cut */
-               }
-               else  {
-                   printf( quiet ? "\nCut for crib? " :
-                       "\nCut to see whose crib it is -- low card wins? " );
-                   i = number( 0, CARDS - 1 );
+           do {
+               if (!rflag) {                           /* player cuts deck */
+                   msg(quiet ? "Cut for crib? " :
+                       "Cut to see whose crib it is -- low card wins? ");
+                   getline();
                }
                }
-               do  {                                   /* comp cuts deck */
-                   j = ( rand() >> 4 ) % CARDS;
-               }  while( j == i );
-               printf( quiet ? "You cut " : "You cut the " );
-               printcard( deck[i], FALSE );
-               printf( quiet ? ", I cut " : ",  I cut the " );
-               printcard( deck[j], FALSE );
-               printf( ".\n" );
-               flag = ( deck[i].rank == deck[j].rank );
-               if( flag )  {
-                   printf( quiet ? "We tied...\n" :
-                               "We tied and have to try again...\n" );
-                   shuffle( deck );
+               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;
                }
                    continue;
                }
-               else  {
-                   compcrib = deck[i].rank > deck[j].rank;
-               }
-           }  while( flag );
+               else
+                   compcrib = (deck[i].rank > deck[j].rank);
+           } while (flag);
        }
        }
-       else  {
-           printf( "Loser (%s) gets first crib.\n",  (iwon ? "you" : "me") );
+       else {
+           werase(Tablewin);
+           wrefresh(Tablewin);
+           werase(Compwin);
+           wrefresh(Compwin);
+           msg("Loser (%s) gets first crib",  (iwon ? "you" : "me"));
            compcrib = !iwon;
        }
            compcrib = !iwon;
        }
+
        pscore = cscore = 0;
        flag = TRUE;
        pscore = cscore = 0;
        flag = TRUE;
-       do  {
-           shuffle( deck );
-           flag = !playhand( compcrib );
+       do {
+           shuffle(deck);
+           flag = !playhand(compcrib);
            compcrib = !compcrib;
            compcrib = !compcrib;
-           printf( "\nYou have %d points, I have %d.\n", pscore, cscore );
-       }  while( flag );
+       } while (flag);
        ++gamecount;
        ++gamecount;
-       if(  cscore < pscore  )  {
-           if(  glimit - cscore > 30  )  {
-               if(  glimit - cscore > 60  )  {
-                   printf( "\nYOU DOUBLE SKUNKED ME!\n\n" );
-                   pgames += 4;
-               }
-               else  {
-                   printf( "\nYOU SKUNKED ME!\n\n" );
-                   pgames += 2;
-               }
+       if (cscore < pscore) {
+           if (glimit - cscore > 60) {
+               msg("YOU DOUBLE SKUNKED ME!");
+               pgames += 4;
            }
            }
-           else  {
-               printf( "\nYOU WON!\n\n" );
+           else if (glimit - cscore > 30) {
+               msg("YOU SKUNKED ME!");
+               pgames += 2;
+           }
+           else {
+               msg("YOU WON!");
                ++pgames;
            }
            iwon = FALSE;
        }
                ++pgames;
            }
            iwon = FALSE;
        }
-       else  {
-           if(  glimit - pscore > 30  )  {
-               if(  glimit - pscore > 60  )  {
-                   printf( "\nI DOUBLE SKUNKED YOU!\n\n" );
-                   cgames += 4;
-               }
-               else  {
-                   printf( "\nI SKUNKED YOU!\n\n" );
-                   cgames += 2;
-               }
+       else {
+           if (glimit - pscore > 60) {
+               msg("I DOUBLE SKUNKED YOU!");
+               cgames += 4;
            }
            }
-           else  {
-               printf( "\nI WON!\n\n" );
+           else if (glimit - pscore > 30) {
+               msg("I SKUNKED YOU!");
+               cgames += 2;
+           }
+           else {
+               msg("I WON!");
                ++cgames;
            }
            iwon = TRUE;
        }
                ++cgames;
            }
            iwon = TRUE;
        }
-       printf( "\nI have won %d games, you have won %d\n", cgames, pgames );
+       gamescore();
 }
 
 }
 
-
-
 /*
 /*
- * hand does up one hand of the game
+ * playhand:
+ *     Do up one hand of the game
  */
  */
-
-playhand( mycrib )
-
-    BOOLEAN            mycrib;
+playhand(mycrib)
+BOOLEAN                mycrib;
 {
 {
-       register  int                   deckpos;
+       register int            deckpos;
+       extern char             Msgbuf[];
+
+       werase(Compwin);
 
        knownum = 0;
 
        knownum = 0;
-       deckpos = deal( mycrib );
-       sorthand( chand, FULLHAND );
-       sorthand( phand, FULLHAND );
-       makeknown( chand, FULLHAND );
-       printf( "\nYour hand is: " );
-       prhand( phand, FULLHAND, TRUE );
-       printf( ".\n" );
-       discard( mycrib );
-       if(  cut( mycrib, deckpos )  )  return( TRUE );
-       if(  peg( mycrib )  )  return( TRUE );
-       if(  score( mycrib )  )  return( TRUE );
-       return( FALSE );
+       deckpos = deal(mycrib);
+       sorthand(chand, FULLHAND);
+       sorthand(phand, FULLHAND);
+       makeknown(chand, FULLHAND);
+       prhand(phand, FULLHAND, Playwin, FALSE);
+       discard(mycrib);
+       if (cut(mycrib, deckpos))
+           return TRUE;
+       if (peg(mycrib))
+           return TRUE;
+       werase(Tablewin);
+       wrefresh(Tablewin);
+       if (score(mycrib))
+           return TRUE;
+       return FALSE;
 }
 
 
 }
 
 
@@ -244,257 +303,294 @@ deal( mycrib )
        return( j );
 }
 
        return( j );
 }
 
-
-
 /*
 /*
- * handle players discarding into the crib...
- * note: we call cdiscard() after prining first message so player doesn't wait
+ * discard:
+ *     Handle players discarding into the crib...
+ * Note: we call cdiscard() after prining first message so player doesn't wait
  */
  */
-
-discard( mycrib )
-
-    BOOLEAN            mycrib;
+discard(mycrib)
+BOOLEAN                mycrib;
 {
 {
-
-       CARD                    crd;
-
-       printf( "It's %s crib...\n", (mycrib ? "my" : "your") );
-       printf( quiet ? "Discard --> " : "Discard a card --> " );
-       cdiscard( mycrib );                     /* puts best discard at end */
-       crd = phand[ infrom(phand, FULLHAND) ];
-       remove( crd, phand, FULLHAND);
+       register char   *prompt;
+       CARD            crd;
+
+       prcrib(mycrib, TRUE);
+       prompt = (quiet ? "Discard --> " : "Discard a card --> ");
+       cdiscard(mycrib);                       /* puts best discard at end */
+       crd = phand[infrom(phand, FULLHAND, prompt)];
+       remove(crd, phand, FULLHAND);
+       prhand(phand, FULLHAND, Playwin, FALSE);
        crib[0] = crd;
        crib[0] = crd;
-    /* next four lines same as last four except for cdiscard() */
-       printf( quiet ? "Discard --> " : "Discard a card --> " );
-       crd = phand[ infrom(phand, FULLHAND - 1) ];
-       remove( crd, phand, FULLHAND - 1 );
+/* next four lines same as last four except for cdiscard() */
+       crd = phand[infrom(phand, FULLHAND - 1, prompt)];
+       remove(crd, phand, FULLHAND - 1);
+       prhand(phand, FULLHAND, Playwin, FALSE);
        crib[1] = crd;
        crib[2] = chand[4];
        crib[3] = chand[5];
        crib[1] = crd;
        crib[2] = chand[4];
        crib[3] = chand[5];
-       chand[4].rank = chand[4].suit = chand[5].rank = chand[5].suit = -1;
+       chand[4].rank = chand[4].suit = chand[5].rank = chand[5].suit = EMPTY;
 }
 
 }
 
-
-
 /*
 /*
- * cut the deck and set turnover
+ * cut:
+ *     Cut the deck and set turnover.  Actually, we only ASK the
+ *     player what card to turn.  We do a random one, anyway.
  */
  */
-
-cut( mycrib, pos )
-
-    BOOLEAN            mycrib;
-    int                        pos;
+cut(mycrib, pos)
+BOOLEAN                mycrib;
+int            pos;
 {
 {
-       register  int           i;
+       register int            i, cardx;
        BOOLEAN                 win = FALSE;
 
        BOOLEAN                 win = FALSE;
 
-       if( mycrib )  {
-           if( rflag )  {                      /* random cut */
-               i = ( rand() >> 4 ) % (CARDS - pos);
-           }
-           else  {
-               printf( quiet ? "Cut the deck? " :
-                       "How many cards down do you wish to cut the deck? " );
-               i = number( 0, CARDS - pos - 1 );
+       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];
            turnover = deck[i + pos];
-           printf( quiet ? "You cut " : "You cut the " );
-           printcard( turnover, FALSE );
-           printf( ".\n" );
-           if(  turnover.rank == JACK  )  {
-               printf( "I get two for his heels.\n" );
-               win = chkscr( &cscore, 2 );
+           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;
+       else {
+           i = (rand() >> 4) % (CARDS - pos) + pos;
            turnover = deck[i];
            turnover = deck[i];
-           printf( quiet ? "I cut " : "I cut the " );
-           printcard( turnover, FALSE );
-           printf( ".\n" );
-           if(  turnover.rank == JACK  )  {
-               printf( "You get two for his heels.\n" );
-               win = chkscr( &pscore, 2 );
+           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 );
-       return( win );
+       makeknown(&turnover, 1);
+       prcrib(mycrib, FALSE);
+       return win;
 }
 
 }
 
+/*
+ * prcrib:
+ *     Print out the turnover card with crib indicator
+ */
+prcrib(mycrib, blank)
+BOOLEAN                mycrib, blank;
+{
+       register int    y, cardx;
 
 
+       if (mycrib)
+           cardx = CRIB_X;
+       else
+           cardx = 0;
+
+       mvaddstr(CRIB_Y, cardx + 1, "CRIB");
+       prcard(stdscr, CRIB_Y + 1, cardx, turnover, blank);
+
+       if (mycrib)
+           cardx = 0;
+       else
+           cardx = CRIB_X;
+
+       for (y = CRIB_Y; y <= CRIB_Y + 5; y++)
+           mvaddstr(y, cardx, "       ");
+}
 
 /*
 
 /*
- * handle all the pegging...
+ * peg:
+ *     Handle all the pegging...
  */
 
  */
 
-peg( mycrib )
+static CARD            Table[14];
+
+static int             Tcnt;
 
 
-    BOOLEAN            mycrib;
+peg(mycrib)
+BOOLEAN                mycrib;
 {
 {
-       static  CARD            ch[ CINHAND ],  ph[ CINHAND ];
-       static  CARD            table[ 14 ];
+       static CARD             ch[CINHAND], ph[CINHAND];
        CARD                    crd;
        CARD                    crd;
-       register  int           i, j, k;
-       int                     l;
-       int                     cnum, pnum, tcnt, sum;
-       BOOLEAN                 myturn, mego, ugo, last, played;
+       register int            i, j, k;
+       register int            l;
+       register int            cnum, pnum, sum;
+       register BOOLEAN        myturn, mego, ugo, last, played;
 
        cnum = pnum = CINHAND;
 
        cnum = pnum = CINHAND;
-       for( i = 0; i < CINHAND; i++ )  {       /* make copies of hands */
+       for (i = 0; i < CINHAND; i++) {         /* make copies of hands */
            ch[i] = chand[i];
            ph[i] = phand[i];
        }
            ch[i] = chand[i];
            ph[i] = phand[i];
        }
-       tcnt = 0;                       /* index to table of cards played */
+       Tcnt = 0;                       /* index to table of cards played */
        sum = 0;                        /* sum of cards played */
        mego = ugo = FALSE;
        myturn = !mycrib;
        sum = 0;                        /* sum of cards played */
        mego = ugo = FALSE;
        myturn = !mycrib;
-       do  {
+       for (;;) {
            last = TRUE;                                /* enable last flag */
            last = TRUE;                                /* enable last flag */
-           if(  myturn  )  {                           /* my tyrn to play */
-               if(  !anymove( ch, cnum, sum )  )  {    /* if no card to play */
-                   if(  !mego  &&  cnum  )  {          /* go for comp? */
-                       printf( "GO.\n" );
+           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;
                    }
                        mego = TRUE;
                    }
-                   if(  anymove( ph, pnum, sum )  )  { /* can player move? */
+                   if (anymove(ph, pnum, sum))         /* can player move? */
                        myturn = !myturn;
                        myturn = !myturn;
-                   }
-                   else  {                             /* give him his point */
-                       printf( quiet ? "You get one.\n" :
-                                       "You get one point.\n" );
-                       if(  chkscr( &pscore, 1 )  )  return( TRUE );
+                   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;
                        sum = 0;
                        mego = ugo = FALSE;
-                       tcnt = 0;
+                       Tcnt = 0;
                    }
                }
                    }
                }
-               else  {
+               else {
                    played = TRUE;
                    j = -1;
                    k = 0;
                    played = TRUE;
                    j = -1;
                    k = 0;
-                   for( i = 0; i < cnum; i++ )  {      /* maximize score */
-                       l = pegscore( ch[i], table, tcnt, sum );
-                       if(  l > k  )  {
+                   for (i = 0; i < cnum; i++) {        /* maximize score */
+                       l = pegscore(ch[i], Table, Tcnt, sum);
+                       if (l > k) {
                            k = l;
                            j = i;
                        }
                    }
                            k = l;
                            j = i;
                        }
                    }
-                   if(  j < 0  )  {                    /* if nothing scores */
-                       j = cchose( ch, cnum, sum );
-                   }
+                   if (j < 0)                          /* if nothing scores */
+                       j = cchose(ch, cnum, sum);
                    crd = ch[j];
                    crd = ch[j];
-                   printf( quiet ? "I play " : "I play the " );
-                   printcard( crd, FALSE );
-                   remove( crd, ch, cnum-- );
-                   sum += VAL( crd.rank );
-                   table[ tcnt++ ] = crd;
-                   printf( ".  Total is %d", sum );
-                   if( k > 0 )  {
-                       printf( quiet ? ".  I got %d" :
-                                               ".  I got %d points", k );
-                       if(  chkscr( &cscore, k )  )  return( TRUE );
+                   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;
                    }
                    }
-                   printf( ".\n" );
                    myturn = !myturn;
                }
            }
                    myturn = !myturn;
                }
            }
-           else  {
-               if(  !anymove( ph, pnum, sum )  )  {    /* can player move? */
-                   if(  !ugo  &&  pnum  )  {           /* go for player */
-                       printf( "You have a GO.\n" );
+           else {
+               if (!anymove(ph, pnum, sum)) {          /* can player move? */
+                   if (!ugo && pnum) {                 /* go for player */
+                       msg("You have a GO");
                        ugo = TRUE;
                    }
                        ugo = TRUE;
                    }
-                   if(  anymove( ch, cnum, sum )  )  { /* can computer play? */
+                   if (anymove(ch, cnum, sum))         /* can computer play? */
                        myturn = !myturn;
                        myturn = !myturn;
-                   }
-                   else  {
-                       printf( quiet ? "I get one.\n" : "I get one point.\n" );
-                       if(  chkscr( &cscore, 1 )  )  return( TRUE );
+                   else {
+                       msg(quiet ? "I get one" : "I get one point");
+                       do_wait();
+                       if (chkscr(&cscore, 1))
+                           return TRUE;
                        sum = 0;
                        mego = ugo = FALSE;
                        sum = 0;
                        mego = ugo = FALSE;
-                       tcnt = 0;
+                       Tcnt = 0;
                    }
                }
                    }
                }
-               else  {                                 /* player plays */
+               else                                  /* player plays */
                    played = FALSE;
                    played = FALSE;
-                   if(  pnum == 1  )  {
+                   if (pnum == 1) {
                        crd = ph[0];
                        crd = ph[0];
-                       printf( "You play your last card, the " );
-                       printcard( crd, TRUE );
-                       printf( ".  " );
+                       msg("You play your last card");
                    }
                    }
-                   else  {
-                       do  {
-                           printf( "Your play ( " );
-                           prhand( ph, pnum, TRUE );
-                           printf( " ): " );
-                           crd = ph[ infrom(ph, pnum) ];
-                           if(  sum + VAL( crd.rank )  <=  31  )  {
+                   else
+                       for (;;) {
+                           prhand(ph, pnum, Playwin, FALSE);
+                           crd = ph[infrom(ph, pnum, "Your play: ")];
+                           if (sum + VAL(crd.rank) <= 31)
                                break;
                                break;
-                           }
-                           else  {
-                               printf( "Total > 31 -- try again.\n" );
-                           }
-                       }  while( TRUE );
-                   }
-                   makeknown( &crd, 1 );
-                   remove( crd, ph, pnum-- );
-                   i = pegscore( crd, table, tcnt, sum );
-                   sum += VAL( crd.rank );
-                   table[ tcnt++ ] = crd;
-                   printf( "Total is %d", sum );
-                   if( i > 0 )  {
-                       printf( quiet ? ".  You got %d" :
-                                               ".  You got %d points", i );
-                       if(  chkscr( &pscore, i )  )  return( TRUE );
+                           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;
                    }
                    }
-                   printf( ".\n" );
                    myturn = !myturn;
                }
            }
                    myturn = !myturn;
                }
            }
-           if(  sum >= 31  )  {
+           if (sum >= 31) {
+               if (!myturn)
+                   do_wait();
                sum = 0;
                mego = ugo = FALSE;
                sum = 0;
                mego = ugo = FALSE;
-               tcnt = 0;
+               Tcnt = 0;
                last = FALSE;                           /* disable last flag */
            }
                last = FALSE;                           /* disable last flag */
            }
-           if(  !pnum  &&  !cnum  )  break;            /* both done */
-       }  while( TRUE );
-       if( last )  {
-           if( played )  {
-               printf( quiet ? "I get one for last.\n" :
-                                       "I get one point for last.\n" );
-               if(  chkscr( &cscore, 1 )  )  return( TRUE );
+           if (!pnum && !cnum)
+               break;                                  /* both done */
+       }
+       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");
+               do_wait();
+               if (chkscr(&cscore, 1))
+                   return TRUE;
            }
            }
-           else  {
-               printf( quiet ? "You get one for last.\n" :
-                                       "You get one point for last.\n" );
-               if(  chkscr( &pscore, 1 )  )  return( TRUE );
+           else {
+               msg(quiet ? "You get one for last" :
+                           "You get one point for last");
+               if (chkscr(&pscore, 1))
+                   return TRUE;
            }
            }
-       }
-       return( FALSE );
+       return FALSE;
 }
 
 }
 
-
-
 /*
 /*
- * handle the scoring of the hands
+ * prtable:
+ *     Print out the table with the current score
  */
  */
+prtable(score)
+int    score;
+{
+       prhand(Table, Tcnt, Tablewin, FALSE);
+       mvwprintw(Tablewin, (Tcnt + 2) * 2, Tcnt + 1, "%2d", score);
+       wrefresh(Tablewin);
+}
 
 
-score( mycrib )
-
-    BOOLEAN            mycrib;
+/*
+ * score:
+ *     Handle the scoring of the hands
+ */
+score(mycrib)
+BOOLEAN                mycrib;
 {
 {
-       if(  mycrib  )  {
-           if(  plyrhand( phand, "hand" )  )  return( TRUE );
-           if(  comphand( chand, "hand" )  )  return( TRUE );
-           if(  comphand( crib, "crib" )  )  return( TRUE );
+       sorthand(crib, CINHAND);
+       if (mycrib) {
+           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;
 }
 }
-