1*59264Sbostic /*- 2*59264Sbostic * Copyright (c) 1980 The Regents of the University of California. 333705Sbostic * All rights reserved. 433705Sbostic * 542575Sbostic * %sccs.include.redist.c% 621514Smckusick */ 712571Sarnold 821514Smckusick #ifndef lint 921514Smckusick char copyright[] = 10*59264Sbostic "@(#) Copyright (c) 1980 The Regents of the University of California.\n\ 1121514Smckusick All rights reserved.\n"; 1233705Sbostic #endif /* not lint */ 1321514Smckusick 1421514Smckusick #ifndef lint 15*59264Sbostic static char sccsid[] = "@(#)crib.c 5.8 (Berkeley) 04/26/93"; 1633705Sbostic #endif /* not lint */ 1721514Smckusick 18*59264Sbostic #include <curses.h> 19*59264Sbostic #include <signal.h> 20*59264Sbostic #include <stdlib.h> 21*59264Sbostic #include <string.h> 22*59264Sbostic #include <unistd.h> 237706Sarnold 24*59264Sbostic #include "deck.h" 25*59264Sbostic #include "cribbage.h" 26*59264Sbostic #include "cribcur.h" 27*59264Sbostic #include "pathnames.h" 28*59264Sbostic 29*59264Sbostic int 307871Sarnold main(argc, argv) 31*59264Sbostic int argc; 32*59264Sbostic char *argv[]; 337706Sarnold { 34*59264Sbostic BOOLEAN playing; 35*59264Sbostic FILE *f; 3641186Sbostic int ch; 377706Sarnold 3841186Sbostic while ((ch = getopt(argc, argv, "eqr")) != EOF) 39*59264Sbostic switch (ch) { 4041186Sbostic case 'e': 417706Sarnold explain = TRUE; 427706Sarnold break; 4341186Sbostic case 'q': 447706Sarnold quiet = TRUE; 457706Sarnold break; 4641186Sbostic case 'r': 477706Sarnold rflag = TRUE; 487706Sarnold break; 4941186Sbostic case '?': 5041186Sbostic default: 5141186Sbostic (void) fprintf(stderr, "usage: cribbage [-eqr]\n"); 5241186Sbostic exit(1); 537706Sarnold } 547871Sarnold 557871Sarnold initscr(); 56*59264Sbostic (void)signal(SIGINT, rint); 577871Sarnold crmode(); 587871Sarnold noecho(); 59*59264Sbostic 6012315Sarnold Playwin = subwin(stdscr, PLAY_Y, PLAY_X, 0, 0); 6112315Sarnold Tablewin = subwin(stdscr, TABLE_Y, TABLE_X, 0, PLAY_X); 6212315Sarnold Compwin = subwin(stdscr, COMP_Y, COMP_X, 0, TABLE_X + PLAY_X); 6312315Sarnold Msgwin = subwin(stdscr, MSG_Y, MSG_X, Y_MSG_START, SCORE_X + 1); 647871Sarnold leaveok(Playwin, TRUE); 657871Sarnold leaveok(Tablewin, TRUE); 667871Sarnold leaveok(Compwin, TRUE); 6712162Sarnold clearok(stdscr, FALSE); 687871Sarnold 697871Sarnold if (!quiet) { 70*59264Sbostic msg("Do you need instructions for cribbage? "); 71*59264Sbostic if (getuchar() == 'Y') { 72*59264Sbostic endwin(); 73*59264Sbostic clear(); 74*59264Sbostic mvcur(0, COLS - 1, LINES - 1, 0); 75*59264Sbostic fflush(stdout); 76*59264Sbostic instructions(); 77*59264Sbostic crmode(); 78*59264Sbostic noecho(); 79*59264Sbostic clear(); 80*59264Sbostic refresh(); 81*59264Sbostic msg("For cribbage rules, use \"man cribbage\""); 82*59264Sbostic } 837706Sarnold } 847706Sarnold playing = TRUE; 857871Sarnold do { 86*59264Sbostic wclrtobot(Msgwin); 87*59264Sbostic msg(quiet ? "L or S? " : "Long (to 121) or Short (to 61)? "); 88*59264Sbostic if (glimit == SGAME) 89*59264Sbostic glimit = (getuchar() == 'L' ? LGAME : SGAME); 90*59264Sbostic else 91*59264Sbostic glimit = (getuchar() == 'S' ? SGAME : LGAME); 92*59264Sbostic game(); 93*59264Sbostic msg("Another game? "); 94*59264Sbostic playing = (getuchar() == 'Y'); 957871Sarnold } while (playing); 967871Sarnold 9741186Sbostic if (f = fopen(_PATH_LOG, "a")) { 9841186Sbostic (void)fprintf(f, "%s: won %5.5d, lost %5.5d\n", 99*59264Sbostic getlogin(), cgames, pgames); 100*59264Sbostic (void) fclose(f); 1017706Sarnold } 1027871Sarnold bye(); 10341186Sbostic if (!f) { 104*59264Sbostic (void) fprintf(stderr, "\ncribbage: can't open %s.\n", 10541186Sbostic _PATH_LOG); 10641186Sbostic exit(1); 10741186Sbostic } 10841186Sbostic exit(0); 1097706Sarnold } 1107706Sarnold 1117871Sarnold /* 1127871Sarnold * makeboard: 1137871Sarnold * Print out the initial board on the screen 1147871Sarnold */ 115*59264Sbostic void 1167871Sarnold makeboard() 1177871Sarnold { 118*59264Sbostic mvaddstr(SCORE_Y + 0, SCORE_X, 119*59264Sbostic "+---------------------------------------+"); 120*59264Sbostic mvaddstr(SCORE_Y + 1, SCORE_X, 121*59264Sbostic "| Score: 0 YOU |"); 122*59264Sbostic mvaddstr(SCORE_Y + 2, SCORE_X, 123*59264Sbostic "| *.....:.....:.....:.....:.....:..... |"); 124*59264Sbostic mvaddstr(SCORE_Y + 3, SCORE_X, 125*59264Sbostic "| *.....:.....:.....:.....:.....:..... |"); 126*59264Sbostic mvaddstr(SCORE_Y + 4, SCORE_X, 127*59264Sbostic "| |"); 128*59264Sbostic mvaddstr(SCORE_Y + 5, SCORE_X, 129*59264Sbostic "| *.....:.....:.....:.....:.....:..... |"); 130*59264Sbostic mvaddstr(SCORE_Y + 6, SCORE_X, 131*59264Sbostic "| *.....:.....:.....:.....:.....:..... |"); 132*59264Sbostic mvaddstr(SCORE_Y + 7, SCORE_X, 133*59264Sbostic "| Score: 0 ME |"); 134*59264Sbostic mvaddstr(SCORE_Y + 8, SCORE_X, 135*59264Sbostic "+---------------------------------------+"); 136*59264Sbostic gamescore(); 1377949Sarnold } 1387949Sarnold 1397949Sarnold /* 1407949Sarnold * gamescore: 1417949Sarnold * Print out the current game score 1427949Sarnold */ 143*59264Sbostic void 1447949Sarnold gamescore() 1457949Sarnold { 146*59264Sbostic extern int Lastscore[]; 1477949Sarnold 148*59264Sbostic if (pgames || cgames) { 149*59264Sbostic mvprintw(SCORE_Y + 1, SCORE_X + 28, "Games: %3d", pgames); 150*59264Sbostic mvprintw(SCORE_Y + 7, SCORE_X + 28, "Games: %3d", cgames); 151*59264Sbostic } 152*59264Sbostic Lastscore[0] = -1; 153*59264Sbostic Lastscore[1] = -1; 1547871Sarnold } 1557871Sarnold 1567706Sarnold /* 1577871Sarnold * game: 1587933Sarnold * Play one game up to glimit points. Actually, we only ASK the 1597933Sarnold * player what card to turn. We do a random one, anyway. 1607706Sarnold */ 161*59264Sbostic void 1627706Sarnold game() 1637706Sarnold { 164*59264Sbostic register int i, j; 165*59264Sbostic BOOLEAN flag; 166*59264Sbostic BOOLEAN compcrib; 1677706Sarnold 1687871Sarnold makedeck(deck); 1697871Sarnold shuffle(deck); 1707871Sarnold if (gamecount == 0) { 171*59264Sbostic flag = TRUE; 172*59264Sbostic do { 173*59264Sbostic if (!rflag) { /* player cuts deck */ 174*59264Sbostic msg(quiet ? "Cut for crib? " : 175*59264Sbostic "Cut to see whose crib it is -- low card wins? "); 176*59264Sbostic getline(); 177*59264Sbostic } 178*59264Sbostic i = (rand() >> 4) % CARDS; /* random cut */ 179*59264Sbostic do { /* comp cuts deck */ 180*59264Sbostic j = (rand() >> 4) % CARDS; 181*59264Sbostic } while (j == i); 182*59264Sbostic addmsg(quiet ? "You cut " : "You cut the "); 183*59264Sbostic msgcard(deck[i], FALSE); 184*59264Sbostic endmsg(); 185*59264Sbostic addmsg(quiet ? "I cut " : "I cut the "); 186*59264Sbostic msgcard(deck[j], FALSE); 187*59264Sbostic endmsg(); 188*59264Sbostic flag = (deck[i].rank == deck[j].rank); 189*59264Sbostic if (flag) { 190*59264Sbostic msg(quiet ? "We tied..." : 191*59264Sbostic "We tied and have to try again..."); 192*59264Sbostic shuffle(deck); 193*59264Sbostic continue; 194*59264Sbostic } else 195*59264Sbostic compcrib = (deck[i].rank > deck[j].rank); 196*59264Sbostic } while (flag); 197*59264Sbostic clear(); 198*59264Sbostic makeboard(); 199*59264Sbostic refresh(); 200*59264Sbostic } else { 201*59264Sbostic werase(Tablewin); 202*59264Sbostic wrefresh(Tablewin); 203*59264Sbostic werase(Compwin); 204*59264Sbostic wrefresh(Compwin); 205*59264Sbostic msg("Loser (%s) gets first crib", (iwon ? "you" : "me")); 206*59264Sbostic compcrib = !iwon; 2077706Sarnold } 2087871Sarnold 2097706Sarnold pscore = cscore = 0; 2107706Sarnold flag = TRUE; 2117871Sarnold do { 212*59264Sbostic shuffle(deck); 213*59264Sbostic flag = !playhand(compcrib); 214*59264Sbostic compcrib = !compcrib; 2157871Sarnold } while (flag); 2167706Sarnold ++gamecount; 2177871Sarnold if (cscore < pscore) { 218*59264Sbostic if (glimit - cscore > 60) { 219*59264Sbostic msg("YOU DOUBLE SKUNKED ME!"); 220*59264Sbostic pgames += 4; 221*59264Sbostic } else 222*59264Sbostic if (glimit - cscore > 30) { 223*59264Sbostic msg("YOU SKUNKED ME!"); 224*59264Sbostic pgames += 2; 225*59264Sbostic } else { 226*59264Sbostic msg("YOU WON!"); 227*59264Sbostic ++pgames; 228*59264Sbostic } 229*59264Sbostic iwon = FALSE; 230*59264Sbostic } else { 231*59264Sbostic if (glimit - pscore > 60) { 232*59264Sbostic msg("I DOUBLE SKUNKED YOU!"); 233*59264Sbostic cgames += 4; 234*59264Sbostic } else 235*59264Sbostic if (glimit - pscore > 30) { 236*59264Sbostic msg("I SKUNKED YOU!"); 237*59264Sbostic cgames += 2; 238*59264Sbostic } else { 239*59264Sbostic msg("I WON!"); 240*59264Sbostic ++cgames; 241*59264Sbostic } 242*59264Sbostic iwon = TRUE; 2437706Sarnold } 2447949Sarnold gamescore(); 2457706Sarnold } 2467706Sarnold 2477706Sarnold /* 2487871Sarnold * playhand: 2497871Sarnold * Do up one hand of the game 2507706Sarnold */ 251*59264Sbostic int 2527871Sarnold playhand(mycrib) 253*59264Sbostic BOOLEAN mycrib; 2547871Sarnold { 255*59264Sbostic register int deckpos; 2567706Sarnold 2577871Sarnold werase(Compwin); 2587706Sarnold 2597706Sarnold knownum = 0; 2607871Sarnold deckpos = deal(mycrib); 2617871Sarnold sorthand(chand, FULLHAND); 2627871Sarnold sorthand(phand, FULLHAND); 2637871Sarnold makeknown(chand, FULLHAND); 2648073Sarnold prhand(phand, FULLHAND, Playwin, FALSE); 2657871Sarnold discard(mycrib); 2667871Sarnold if (cut(mycrib, deckpos)) 267*59264Sbostic return TRUE; 2687871Sarnold if (peg(mycrib)) 269*59264Sbostic return TRUE; 2707871Sarnold werase(Tablewin); 2717871Sarnold wrefresh(Tablewin); 2727871Sarnold if (score(mycrib)) 273*59264Sbostic return TRUE; 2747871Sarnold return FALSE; 2757706Sarnold } 2767706Sarnold 2777706Sarnold /* 2787706Sarnold * deal cards to both players from deck 2797706Sarnold */ 280*59264Sbostic int 281*59264Sbostic deal(mycrib) 282*59264Sbostic BOOLEAN mycrib; 2837706Sarnold { 284*59264Sbostic register int i, j; 2857706Sarnold 286*59264Sbostic for (i = j = 0; i < FULLHAND; i++) { 287*59264Sbostic if (mycrib) { 288*59264Sbostic phand[i] = deck[j++]; 289*59264Sbostic chand[i] = deck[j++]; 290*59264Sbostic } else { 291*59264Sbostic chand[i] = deck[j++]; 292*59264Sbostic phand[i] = deck[j++]; 293*59264Sbostic } 2947706Sarnold } 295*59264Sbostic return (j); 2967706Sarnold } 2977706Sarnold 2987706Sarnold /* 2997871Sarnold * discard: 3007871Sarnold * Handle players discarding into the crib... 3017871Sarnold * Note: we call cdiscard() after prining first message so player doesn't wait 3027706Sarnold */ 303*59264Sbostic void 3047871Sarnold discard(mycrib) 305*59264Sbostic BOOLEAN mycrib; 3067706Sarnold { 307*59264Sbostic register char *prompt; 308*59264Sbostic CARD crd; 3097706Sarnold 3107946Sarnold prcrib(mycrib, TRUE); 3117871Sarnold prompt = (quiet ? "Discard --> " : "Discard a card --> "); 312*59264Sbostic cdiscard(mycrib); /* puts best discard at end */ 3137871Sarnold crd = phand[infrom(phand, FULLHAND, prompt)]; 31446743Sbostic cremove(crd, phand, FULLHAND); 3158073Sarnold prhand(phand, FULLHAND, Playwin, FALSE); 3167706Sarnold crib[0] = crd; 317*59264Sbostic 318*59264Sbostic /* Next four lines same as last four except for cdiscard(). */ 3197871Sarnold crd = phand[infrom(phand, FULLHAND - 1, prompt)]; 32046743Sbostic cremove(crd, phand, FULLHAND - 1); 3218073Sarnold prhand(phand, FULLHAND, Playwin, FALSE); 3227706Sarnold crib[1] = crd; 3237706Sarnold crib[2] = chand[4]; 3247706Sarnold crib[3] = chand[5]; 3257871Sarnold chand[4].rank = chand[4].suit = chand[5].rank = chand[5].suit = EMPTY; 3267706Sarnold } 3277706Sarnold 3287706Sarnold /* 3297871Sarnold * cut: 3307933Sarnold * Cut the deck and set turnover. Actually, we only ASK the 3317933Sarnold * player what card to turn. We do a random one, anyway. 3327706Sarnold */ 333*59264Sbostic int 3347871Sarnold cut(mycrib, pos) 335*59264Sbostic BOOLEAN mycrib; 336*59264Sbostic int pos; 3377706Sarnold { 338*59264Sbostic register int i; 339*59264Sbostic BOOLEAN win; 3407706Sarnold 341*59264Sbostic win = FALSE; 3427871Sarnold if (mycrib) { 343*59264Sbostic if (!rflag) { /* random cut */ 344*59264Sbostic msg(quiet ? "Cut the deck? " : 345*59264Sbostic "How many cards down do you wish to cut the deck? "); 346*59264Sbostic getline(); 347*59264Sbostic } 348*59264Sbostic i = (rand() >> 4) % (CARDS - pos); 349*59264Sbostic turnover = deck[i + pos]; 350*59264Sbostic addmsg(quiet ? "You cut " : "You cut the "); 351*59264Sbostic msgcard(turnover, FALSE); 352*59264Sbostic endmsg(); 353*59264Sbostic if (turnover.rank == JACK) { 354*59264Sbostic msg("I get two for his heels"); 355*59264Sbostic win = chkscr(&cscore, 2); 356*59264Sbostic } 357*59264Sbostic } else { 358*59264Sbostic i = (rand() >> 4) % (CARDS - pos) + pos; 359*59264Sbostic turnover = deck[i]; 360*59264Sbostic addmsg(quiet ? "I cut " : "I cut the "); 361*59264Sbostic msgcard(turnover, FALSE); 362*59264Sbostic endmsg(); 363*59264Sbostic if (turnover.rank == JACK) { 364*59264Sbostic msg("You get two for his heels"); 365*59264Sbostic win = chkscr(&pscore, 2); 366*59264Sbostic } 3677706Sarnold } 3687871Sarnold makeknown(&turnover, 1); 3697946Sarnold prcrib(mycrib, FALSE); 370*59264Sbostic return (win); 3717706Sarnold } 3727706Sarnold 3737706Sarnold /* 3747946Sarnold * prcrib: 3757946Sarnold * Print out the turnover card with crib indicator 3767946Sarnold */ 377*59264Sbostic void 3787946Sarnold prcrib(mycrib, blank) 379*59264Sbostic BOOLEAN mycrib, blank; 3807946Sarnold { 381*59264Sbostic register int y, cardx; 3827946Sarnold 3837946Sarnold if (mycrib) 384*59264Sbostic cardx = CRIB_X; 3857946Sarnold else 386*59264Sbostic cardx = 0; 3877946Sarnold 3887946Sarnold mvaddstr(CRIB_Y, cardx + 1, "CRIB"); 3897946Sarnold prcard(stdscr, CRIB_Y + 1, cardx, turnover, blank); 39012162Sarnold 39112162Sarnold if (mycrib) 392*59264Sbostic cardx = 0; 39312162Sarnold else 394*59264Sbostic cardx = CRIB_X; 39512162Sarnold 39612162Sarnold for (y = CRIB_Y; y <= CRIB_Y + 5; y++) 397*59264Sbostic mvaddstr(y, cardx, " "); 3987946Sarnold } 3997946Sarnold 4007946Sarnold /* 4017871Sarnold * peg: 4027871Sarnold * Handle all the pegging... 4037706Sarnold */ 404*59264Sbostic static CARD Table[14]; 405*59264Sbostic static int Tcnt; 4067706Sarnold 407*59264Sbostic int 4087871Sarnold peg(mycrib) 409*59264Sbostic BOOLEAN mycrib; 4107706Sarnold { 411*59264Sbostic static CARD ch[CINHAND], ph[CINHAND]; 412*59264Sbostic register int i, j, k; 413*59264Sbostic register int l; 414*59264Sbostic register int cnum, pnum, sum; 415*59264Sbostic register BOOLEAN myturn, mego, ugo, last, played; 416*59264Sbostic CARD crd; 4177706Sarnold 4187706Sarnold cnum = pnum = CINHAND; 419*59264Sbostic for (i = 0; i < CINHAND; i++) { /* make copies of hands */ 420*59264Sbostic ch[i] = chand[i]; 421*59264Sbostic ph[i] = phand[i]; 4227706Sarnold } 423*59264Sbostic Tcnt = 0; /* index to table of cards played */ 424*59264Sbostic sum = 0; /* sum of cards played */ 4257706Sarnold mego = ugo = FALSE; 4267706Sarnold myturn = !mycrib; 4277871Sarnold for (;;) { 428*59264Sbostic last = TRUE; /* enable last flag */ 429*59264Sbostic prhand(ph, pnum, Playwin, FALSE); 430*59264Sbostic prhand(ch, cnum, Compwin, TRUE); 431*59264Sbostic prtable(sum); 432*59264Sbostic if (myturn) { /* my tyrn to play */ 433*59264Sbostic if (!anymove(ch, cnum, sum)) { /* if no card to play */ 434*59264Sbostic if (!mego && cnum) { /* go for comp? */ 435*59264Sbostic msg("GO"); 436*59264Sbostic mego = TRUE; 437*59264Sbostic } 438*59264Sbostic /* can player move? */ 439*59264Sbostic if (anymove(ph, pnum, sum)) 440*59264Sbostic myturn = !myturn; 441*59264Sbostic else { /* give him his point */ 442*59264Sbostic msg(quiet ? "You get one" : 443*59264Sbostic "You get one point"); 444*59264Sbostic if (chkscr(&pscore, 1)) 445*59264Sbostic return TRUE; 446*59264Sbostic sum = 0; 447*59264Sbostic mego = ugo = FALSE; 448*59264Sbostic Tcnt = 0; 449*59264Sbostic } 450*59264Sbostic } else { 451*59264Sbostic played = TRUE; 452*59264Sbostic j = -1; 453*59264Sbostic k = 0; 454*59264Sbostic /* maximize score */ 455*59264Sbostic for (i = 0; i < cnum; i++) { 456*59264Sbostic l = pegscore(ch[i], Table, Tcnt, sum); 457*59264Sbostic if (l > k) { 458*59264Sbostic k = l; 459*59264Sbostic j = i; 460*59264Sbostic } 461*59264Sbostic } 462*59264Sbostic if (j < 0) /* if nothing scores */ 463*59264Sbostic j = cchose(ch, cnum, sum); 464*59264Sbostic crd = ch[j]; 465*59264Sbostic cremove(crd, ch, cnum--); 466*59264Sbostic sum += VAL(crd.rank); 467*59264Sbostic Table[Tcnt++] = crd; 468*59264Sbostic if (k > 0) { 469*59264Sbostic addmsg(quiet ? "I get %d playing " : 470*59264Sbostic "I get %d points playing ", k); 471*59264Sbostic msgcard(crd, FALSE); 472*59264Sbostic endmsg(); 473*59264Sbostic if (chkscr(&cscore, k)) 474*59264Sbostic return TRUE; 475*59264Sbostic } 476*59264Sbostic myturn = !myturn; 4777706Sarnold } 478*59264Sbostic } else { 479*59264Sbostic if (!anymove(ph, pnum, sum)) { /* can player move? */ 480*59264Sbostic if (!ugo && pnum) { /* go for player */ 481*59264Sbostic msg("You have a GO"); 482*59264Sbostic ugo = TRUE; 483*59264Sbostic } 484*59264Sbostic /* can computer play? */ 485*59264Sbostic if (anymove(ch, cnum, sum)) 486*59264Sbostic myturn = !myturn; 487*59264Sbostic else { 488*59264Sbostic msg(quiet ? "I get one" : 489*59264Sbostic "I get one point"); 490*59264Sbostic do_wait(); 491*59264Sbostic if (chkscr(&cscore, 1)) 492*59264Sbostic return TRUE; 493*59264Sbostic sum = 0; 494*59264Sbostic mego = ugo = FALSE; 495*59264Sbostic Tcnt = 0; 496*59264Sbostic } 497*59264Sbostic } else { /* player plays */ 498*59264Sbostic played = FALSE; 499*59264Sbostic if (pnum == 1) { 500*59264Sbostic crd = ph[0]; 501*59264Sbostic msg("You play your last card"); 502*59264Sbostic } else 503*59264Sbostic for (;;) { 504*59264Sbostic prhand(ph, 505*59264Sbostic pnum, Playwin, FALSE); 506*59264Sbostic crd = ph[infrom(ph, 507*59264Sbostic pnum, "Your play: ")]; 508*59264Sbostic if (sum + VAL(crd.rank) <= 31) 509*59264Sbostic break; 510*59264Sbostic else 511*59264Sbostic msg("Total > 31 -- try again"); 512*59264Sbostic } 513*59264Sbostic makeknown(&crd, 1); 514*59264Sbostic cremove(crd, ph, pnum--); 515*59264Sbostic i = pegscore(crd, Table, Tcnt, sum); 516*59264Sbostic sum += VAL(crd.rank); 517*59264Sbostic Table[Tcnt++] = crd; 518*59264Sbostic if (i > 0) { 519*59264Sbostic msg(quiet ? "You got %d" : 520*59264Sbostic "You got %d points", i); 521*59264Sbostic if (chkscr(&pscore, i)) 522*59264Sbostic return TRUE; 523*59264Sbostic } 524*59264Sbostic myturn = !myturn; 525*59264Sbostic } 5267706Sarnold } 527*59264Sbostic if (sum >= 31) { 528*59264Sbostic if (!myturn) 529*59264Sbostic do_wait(); 5307706Sarnold sum = 0; 5317706Sarnold mego = ugo = FALSE; 5327871Sarnold Tcnt = 0; 533*59264Sbostic last = FALSE; /* disable last flag */ 5347706Sarnold } 535*59264Sbostic if (!pnum && !cnum) 536*59264Sbostic break; /* both done */ 5377871Sarnold } 5388073Sarnold prhand(ph, pnum, Playwin, FALSE); 5398073Sarnold prhand(ch, cnum, Compwin, TRUE); 5408072Sarnold prtable(sum); 5417871Sarnold if (last) 542*59264Sbostic if (played) { 543*59264Sbostic msg(quiet ? "I get one for last" : 544*59264Sbostic "I get one point for last"); 545*59264Sbostic do_wait(); 546*59264Sbostic if (chkscr(&cscore, 1)) 547*59264Sbostic return TRUE; 548*59264Sbostic } else { 549*59264Sbostic msg(quiet ? "You get one for last" : 5507871Sarnold "You get one point for last"); 551*59264Sbostic if (chkscr(&pscore, 1)) 552*59264Sbostic return TRUE; 553*59264Sbostic } 554*59264Sbostic return (FALSE); 5557706Sarnold } 5567706Sarnold 5577871Sarnold /* 5587871Sarnold * prtable: 5597871Sarnold * Print out the table with the current score 5607871Sarnold */ 561*59264Sbostic void 5627871Sarnold prtable(score) 563*59264Sbostic int score; 5647871Sarnold { 5658073Sarnold prhand(Table, Tcnt, Tablewin, FALSE); 5667871Sarnold mvwprintw(Tablewin, (Tcnt + 2) * 2, Tcnt + 1, "%2d", score); 5677871Sarnold wrefresh(Tablewin); 5687871Sarnold } 5697706Sarnold 5707706Sarnold /* 5717871Sarnold * score: 5727871Sarnold * Handle the scoring of the hands 5737706Sarnold */ 574*59264Sbostic int 5757871Sarnold score(mycrib) 576*59264Sbostic BOOLEAN mycrib; 5777706Sarnold { 5787871Sarnold sorthand(crib, CINHAND); 5797871Sarnold if (mycrib) { 580*59264Sbostic if (plyrhand(phand, "hand")) 581*59264Sbostic return (TRUE); 582*59264Sbostic if (comphand(chand, "hand")) 583*59264Sbostic return (TRUE); 584*59264Sbostic do_wait(); 585*59264Sbostic if (comphand(crib, "crib")) 586*59264Sbostic return (TRUE); 587*59264Sbostic } else { 588*59264Sbostic if (comphand(chand, "hand")) 589*59264Sbostic return (TRUE); 590*59264Sbostic if (plyrhand(phand, "hand")) 591*59264Sbostic return (TRUE); 592*59264Sbostic if (plyrhand(crib, "crib")) 593*59264Sbostic return (TRUE); 5947706Sarnold } 595*59264Sbostic return (FALSE); 5967706Sarnold } 597