Bug Summary

File:src/games/cribbage/crib.c
Warning:line 102, column 2
Value stored to 'playing' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name crib.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/games/cribbage/obj -resource-dir /usr/local/lib/clang/13.0.0 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/games/cribbage/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/games/cribbage/crib.c
1/* $OpenBSD: crib.c,v 1.24 2021/10/23 11:22:48 mestre Exp $ */
2/* $NetBSD: crib.c,v 1.7 1997/07/10 06:47:29 mikel Exp $ */
3
4/*-
5 * Copyright (c) 1980, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <err.h>
34#include <signal.h>
35#include <stdlib.h>
36#include <unistd.h>
37
38#include "cribbage.h"
39#include "cribcur.h"
40
41int
42main(int argc, char *argv[])
43{
44 bool_Bool playing;
45 int ch;
46
47 while ((ch = getopt(argc, argv, "ehmqr")) != -1)
48 switch (ch) {
49 case 'e':
50 explain = TRUE1;
51 break;
52 case 'm':
53 muggins = TRUE1;
54 break;
55 case 'q':
56 quiet = TRUE1;
57 break;
58 case 'r':
59 rflag = TRUE1;
60 break;
61 case 'h':
62 default:
63 (void) fprintf(stderr(&__sF[2]), "usage: %s [-emqr]\n",
64 getprogname());
65 return 1;
66 }
67
68 initscr();
69 (void)signal(SIGINT2, rintsig);
70 cbreak();
71 noecho();
72
73 Playwin = subwin(stdscr, PLAY_Y15, PLAY_X12, 0, 0);
74 Tablewin = subwin(stdscr, TABLE_Y21, TABLE_X14, 0, PLAY_X12);
75 Compwin = subwin(stdscr, COMP_Y15, COMP_X12, 0, TABLE_X14 + PLAY_X12);
76 Msgwin = subwin(stdscr, MSG_Y(LINES - (9 + 1)), MSG_X(COLS - (12 + 14 + 12) - 1), Y_MSG_START(9 + 1), SCORE_X(12 + 14 + 12) + 1);
77
78 leaveok(Playwin, TRUE1);
79 leaveok(Tablewin, TRUE1);
80 leaveok(Compwin, TRUE1);
81 clearok(stdscr, FALSE0);
82
83 if (!quiet) {
84 msg("Do you need instructions for cribbage? ");
85 if (getuchar() == 'Y') {
86 endwin();
87 clear()wclear(stdscr);
88 mvcur(0, COLS - 1, LINES - 1, 0);
89 fflush(stdout(&__sF[1]));
90 instructions();
91 cbreak();
92 noecho();
93 clear()wclear(stdscr);
94 refresh()wrefresh(stdscr);
95 msg("For cribbage rules, use \"man cribbage\"");
96 }
97 }
98
99 if (pledge("stdio tty", NULL((void *)0)) == -1)
100 err(1, "pledge");
101
102 playing = TRUE1;
Value stored to 'playing' is never read
103 do {
104 wclrtobot(Msgwin);
105 msg(quiet ? "L or S? " : "Long (to 121) or Short (to 61)? ");
106 if (glimit == SGAME61)
107 glimit = (getuchar() == 'L' ? LGAME121 : SGAME61);
108 else
109 glimit = (getuchar() == 'S' ? SGAME61 : LGAME121);
110 game();
111 msg("Another game? ");
112 playing = (getuchar() == 'Y');
113 } while (playing);
114
115 bye();
116 return 0;
117}
118
119/*
120 * makeboard:
121 * Print out the initial board on the screen
122 */
123void
124makeboard(void)
125{
126 mvaddstr(SCORE_Y + 0, SCORE_X,(wmove(stdscr,0 + 0,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"+---------------------------------------+",-1))
127 "+---------------------------------------+")(wmove(stdscr,0 + 0,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"+---------------------------------------+",-1))
;
128 mvaddstr(SCORE_Y + 1, SCORE_X,(wmove(stdscr,0 + 1,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"| Score: 0 YOU |",-1))
129 "| Score: 0 YOU |")(wmove(stdscr,0 + 1,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"| Score: 0 YOU |",-1))
;
130 mvaddstr(SCORE_Y + 2, SCORE_X,(wmove(stdscr,0 + 2,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"| *.....:.....:.....:.....:.....:..... |",-1))
131 "| *.....:.....:.....:.....:.....:..... |")(wmove(stdscr,0 + 2,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"| *.....:.....:.....:.....:.....:..... |",-1))
;
132 mvaddstr(SCORE_Y + 3, SCORE_X,(wmove(stdscr,0 + 3,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"| *.....:.....:.....:.....:.....:..... |",-1))
133 "| *.....:.....:.....:.....:.....:..... |")(wmove(stdscr,0 + 3,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"| *.....:.....:.....:.....:.....:..... |",-1))
;
134 mvaddstr(SCORE_Y + 4, SCORE_X,(wmove(stdscr,0 + 4,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"| |",-1))
135 "| |")(wmove(stdscr,0 + 4,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"| |",-1))
;
136 mvaddstr(SCORE_Y + 5, SCORE_X,(wmove(stdscr,0 + 5,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"| *.....:.....:.....:.....:.....:..... |",-1))
137 "| *.....:.....:.....:.....:.....:..... |")(wmove(stdscr,0 + 5,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"| *.....:.....:.....:.....:.....:..... |",-1))
;
138 mvaddstr(SCORE_Y + 6, SCORE_X,(wmove(stdscr,0 + 6,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"| *.....:.....:.....:.....:.....:..... |",-1))
139 "| *.....:.....:.....:.....:.....:..... |")(wmove(stdscr,0 + 6,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"| *.....:.....:.....:.....:.....:..... |",-1))
;
140 mvaddstr(SCORE_Y + 7, SCORE_X,(wmove(stdscr,0 + 7,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"| Score: 0 ME |",-1))
141 "| Score: 0 ME |")(wmove(stdscr,0 + 7,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"| Score: 0 ME |",-1))
;
142 mvaddstr(SCORE_Y + 8, SCORE_X,(wmove(stdscr,0 + 8,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"+---------------------------------------+",-1))
143 "+---------------------------------------+")(wmove(stdscr,0 + 8,(12 + 14 + 12)) == (-1) ? (-1) : waddnstr
(stdscr,"+---------------------------------------+",-1))
;
144 gamescore();
145}
146
147/*
148 * gamescore:
149 * Print out the current game score
150 */
151void
152gamescore(void)
153{
154 if (pgames || cgames) {
155 mvprintw(SCORE_Y0 + 1, SCORE_X(12 + 14 + 12) + 28, "Games: %3d", pgames);
156 mvprintw(SCORE_Y0 + 7, SCORE_X(12 + 14 + 12) + 28, "Games: %3d", cgames);
157 }
158 Lastscore[0] = -1;
159 Lastscore[1] = -1;
160}
161
162/*
163 * game:
164 * Play one game up to glimit points. Actually, we only ASK the
165 * player what card to turn. We do a random one, anyway.
166 */
167void
168game(void)
169{
170 int i, j;
171 bool_Bool flag;
172 bool_Bool compcrib;
173
174 makedeck(deck);
175 shuffle(deck);
176 if (gamecount == 0) {
177 flag = TRUE1;
178 do {
179 if (!rflag) { /* player cuts deck */
180 char *foo;
181
182 /* This is silly, but we should parse user input
183 * even if we're not actually going to use it.
184 */
185 do {
186 msg(quiet ? "Cut for crib? " :
187 "Cut to see whose crib it is -- low card wins? ");
188 foo = get_line();
189 if (*foo != '\0' && ((i = atoi(foo)) < 4 || i > 48))
190 msg("Invalid cut");
191 else
192 *foo = '\0';
193 } while (*foo != '\0');
194 }
195 i = arc4random_uniform(CARDS52); /* random cut */
196 do { /* comp cuts deck */
197 j = arc4random_uniform(CARDS52);
198 } while (j == i);
199 addmsg(quiet ? "You cut " : "You cut the ");
200 msgcard(deck[i], FALSE0);
201 endmsg();
202 addmsg(quiet ? "I cut " : "I cut the ");
203 msgcard(deck[j], FALSE0);
204 endmsg();
205 flag = (deck[i].rank == deck[j].rank);
206 if (flag) {
207 msg(quiet ? "We tied..." :
208 "We tied and have to try again...");
209 shuffle(deck);
210 continue;
211 } else
212 compcrib = (deck[i].rank > deck[j].rank);
213 } while (flag);
214 do_wait();
215 clear()wclear(stdscr);
216 makeboard();
217 refresh()wrefresh(stdscr);
218 } else {
219 makeboard();
220 refresh()wrefresh(stdscr);
221 werase(Tablewin);
222 wrefresh(Tablewin);
223 werase(Compwin);
224 wrefresh(Compwin);
225 msg("Loser (%s) gets first crib", (iwon ? "you" : "me"));
226 compcrib = !iwon;
227 }
228
229 pscore = cscore = 0;
230 flag = TRUE1;
231 do {
232 shuffle(deck);
233 flag = !playhand(compcrib);
234 compcrib = !compcrib;
235 } while (flag);
236 ++gamecount;
237 if (cscore < pscore) {
238 if (glimit - cscore > 60) {
239 msg("YOU DOUBLE SKUNKED ME!");
240 pgames += 4;
241 } else
242 if (glimit - cscore > 30) {
243 msg("YOU SKUNKED ME!");
244 pgames += 2;
245 } else {
246 msg("YOU WON!");
247 ++pgames;
248 }
249 iwon = FALSE0;
250 } else {
251 if (glimit - pscore > 60) {
252 msg("I DOUBLE SKUNKED YOU!");
253 cgames += 4;
254 } else
255 if (glimit - pscore > 30) {
256 msg("I SKUNKED YOU!");
257 cgames += 2;
258 } else {
259 msg("I WON!");
260 ++cgames;
261 }
262 iwon = TRUE1;
263 }
264 gamescore();
265}
266
267/*
268 * playhand:
269 * Do up one hand of the game
270 */
271int
272playhand(bool_Bool mycrib)
273{
274 int deckpos;
275
276 werase(Compwin);
277 wrefresh(Compwin);
278 werase(Tablewin);
279 wrefresh(Tablewin);
280
281 knownum = 0;
282 deckpos = deal(mycrib);
283 sorthand(chand, FULLHAND6);
284 sorthand(phand, FULLHAND6);
285 makeknown(chand, FULLHAND6);
286 prhand(phand, FULLHAND6, Playwin, FALSE0);
287 discard(mycrib);
288 if (cut(mycrib, deckpos))
289 return TRUE1;
290 if (peg(mycrib))
291 return TRUE1;
292 werase(Tablewin);
293 wrefresh(Tablewin);
294 if (score(mycrib))
295 return TRUE1;
296 return FALSE0;
297}
298
299/*
300 * deal cards to both players from deck
301 */
302int
303deal(bool_Bool mycrib)
304{
305 int i, j;
306
307 for (i = j = 0; i < FULLHAND6; i++) {
308 if (mycrib) {
309 phand[i] = deck[j++];
310 chand[i] = deck[j++];
311 } else {
312 chand[i] = deck[j++];
313 phand[i] = deck[j++];
314 }
315 }
316 return (j);
317}
318
319/*
320 * discard:
321 * Handle players discarding into the crib...
322 * Note: we call cdiscard() after prining first message so player doesn't wait
323 */
324void
325discard(bool_Bool mycrib)
326{
327 char *prompt;
328 CARD crd;
329
330 prcrib(mycrib, TRUE1);
331 prompt = (quiet ? "Discard --> " : "Discard a card --> ");
332 cdiscard(mycrib); /* puts best discard at end */
333 crd = phand[infrom(phand, FULLHAND6, prompt)];
334 cremove(crd, phand, FULLHAND6);
335 prhand(phand, FULLHAND6, Playwin, FALSE0);
336 crib[0] = crd;
337
338 /* Next four lines same as last four except for cdiscard(). */
339 crd = phand[infrom(phand, FULLHAND6 - 1, prompt)];
340 cremove(crd, phand, FULLHAND6 - 1);
341 prhand(phand, FULLHAND6, Playwin, FALSE0);
342 crib[1] = crd;
343 crib[2] = chand[4];
344 crib[3] = chand[5];
345 chand[4].rank = chand[4].suit = chand[5].rank = chand[5].suit = EMPTY13;
346}
347
348/*
349 * cut:
350 * Cut the deck and set turnover. Actually, we only ASK the
351 * player what card to turn. We do a random one, anyway.
352 */
353int
354cut(bool_Bool mycrib, int pos)
355{
356 int i;
357 bool_Bool win;
358
359 win = FALSE0;
360 if (mycrib) {
361 if (!rflag) { /* random cut */
362 char *foo;
363
364 /* This is silly, but we should parse user input,
365 * even if we're not actually going to use it.
366 */
367 do {
368 msg(quiet ? "Cut the deck? " :
369 "How many cards down do you wish to cut the deck? ");
370 foo = get_line();
371 if (*foo != '\0' && ((i = atoi(foo)) < 4 || i > 36))
372 msg("Invalid cut");
373 else
374 *foo = '\0';
375 } while (*foo != '\0');
376 }
377 i = arc4random_uniform(CARDS52 - pos);
378 turnover = deck[i + pos];
379 addmsg(quiet ? "You cut " : "You cut the ");
380 msgcard(turnover, FALSE0);
381 endmsg();
382 prcrib(mycrib, FALSE0);
383 if (turnover.rank == JACK10) {
384 msg("I get two for his heels");
385 win = chkscr(&cscore, 2);
386 }
387 } else {
388 i = arc4random_uniform(CARDS52 - pos) + pos;
389 turnover = deck[i];
390 addmsg(quiet ? "I cut " : "I cut the ");
391 msgcard(turnover, FALSE0);
392 endmsg();
393 prcrib(mycrib, FALSE0);
394 if (turnover.rank == JACK10) {
395 msg("You get two for his heels");
396 win = chkscr(&pscore, 2);
397 }
398 }
399 makeknown(&turnover, 1);
400 return (win);
401}
402
403/*
404 * prcrib:
405 * Print out the turnover card with crib indicator
406 */
407void
408prcrib(bool_Bool mycrib, bool_Bool blank)
409{
410 int y, cardx;
411
412 if (mycrib)
413 cardx = CRIB_X(12 + 14);
414 else
415 cardx = 0;
416
417 mvaddstr(CRIB_Y, cardx + 1, "CRIB")(wmove(stdscr,17,cardx + 1) == (-1) ? (-1) : waddnstr(stdscr,
"CRIB",-1))
;
418 prcard(stdscr, CRIB_Y17 + 1, cardx, turnover, blank);
419
420 if (mycrib)
421 cardx = 0;
422 else
423 cardx = CRIB_X(12 + 14);
424
425 for (y = CRIB_Y17; y <= CRIB_Y17 + 5; y++)
426 mvaddstr(y, cardx, " ")(wmove(stdscr,y,cardx) == (-1) ? (-1) : waddnstr(stdscr," "
,-1))
;
427 refresh()wrefresh(stdscr);
428}
429
430/*
431 * peg:
432 * Handle all the pegging...
433 */
434static CARD Table[14];
435static int Tcnt;
436
437int
438peg(bool_Bool mycrib)
439{
440 static CARD ch[CINHAND4], ph[CINHAND4];
441 int i, j, k;
442 int l;
443 int cnum, pnum, sum;
444 bool_Bool myturn, mego, ugo, last, played;
445 CARD crd;
446
447 played = FALSE0;
448 cnum = pnum = CINHAND4;
449 for (i = 0; i < CINHAND4; i++) { /* make copies of hands */
450 ch[i] = chand[i];
451 ph[i] = phand[i];
452 }
453 Tcnt = 0; /* index to table of cards played */
454 sum = 0; /* sum of cards played */
455 mego = ugo = FALSE0;
456 myturn = !mycrib;
457 for (;;) {
458 last = TRUE1; /* enable last flag */
459 prhand(ph, pnum, Playwin, FALSE0);
460 prhand(ch, cnum, Compwin, TRUE1);
461 prtable(sum);
462 if (myturn) {
463 if (!anymove(ch, cnum, sum)) { /* if no card to play */
464 if (!mego && cnum) { /* go for comp? */
465 msg("GO");
466 mego = TRUE1;
467 }
468 /* can player move? */
469 if (anymove(ph, pnum, sum))
470 myturn = !myturn;
471 else { /* give him his point */
472 msg(quiet ? "You get one" :
473 "You get one point");
474 do_wait();
475 if (chkscr(&pscore, 1))
476 return TRUE1;
477 sum = 0;
478 mego = ugo = FALSE0;
479 Tcnt = 0;
480 }
481 } else {
482 played = TRUE1;
483 j = -1;
484 k = 0;
485 /* maximize score */
486 for (i = 0; i < cnum; i++) {
487 l = pegscore(ch[i], Table, Tcnt, sum);
488 if (l > k) {
489 k = l;
490 j = i;
491 }
492 }
493 if (j < 0) /* if nothing scores */
494 j = cchose(ch, cnum, sum);
495 crd = ch[j];
496 cremove(crd, ch, cnum--);
497 sum += VAL(crd.rank)( (crd.rank) < 9 ? (crd.rank)+1 : 10 );
498 Table[Tcnt++] = crd;
499 if (k > 0) {
500 addmsg(quiet ? "I get %d playing " :
501 "I get %d points playing ", k);
502 msgcard(crd, FALSE0);
503 endmsg();
504 prhand(ph, pnum, Playwin, FALSE0);
505 prhand(ch, cnum, Compwin, TRUE1);
506 prtable(sum);
507 if (chkscr(&cscore, k))
508 return TRUE1;
509 }
510 myturn = !myturn;
511 }
512 } else {
513 if (!anymove(ph, pnum, sum)) { /* can player move? */
514 if (!ugo && pnum) { /* go for player */
515 msg("You have a GO");
516 ugo = TRUE1;
517 }
518 /* can computer play? */
519 if (anymove(ch, cnum, sum))
520 myturn = !myturn;
521 else {
522 msg(quiet ? "I get one" :
523 "I get one point");
524 do_wait();
525 prhand(ph, pnum, Playwin, FALSE0);
526 prhand(ch, cnum, Compwin, TRUE1);
527 prtable(sum);
528 if (chkscr(&cscore, 1))
529 return TRUE1;
530 sum = 0;
531 mego = ugo = FALSE0;
532 Tcnt = 0;
533 }
534 } else { /* player plays */
535 played = FALSE0;
536 if (pnum == 1) {
537 crd = ph[0];
538 msg("You play your last card");
539 } else
540 for (;;) {
541 prhand(ph,
542 pnum, Playwin, FALSE0);
543 crd = ph[infrom(ph,
544 pnum, "Your play: ")];
545 if (sum + VAL(crd.rank)( (crd.rank) < 9 ? (crd.rank)+1 : 10 ) <= 31)
546 break;
547 else
548 msg("Total > 31 -- try again");
549 }
550 makeknown(&crd, 1);
551 cremove(crd, ph, pnum--);
552 i = pegscore(crd, Table, Tcnt, sum);
553 sum += VAL(crd.rank)( (crd.rank) < 9 ? (crd.rank)+1 : 10 );
554 Table[Tcnt++] = crd;
555 if (i > 0) {
556 msg(quiet ? "You got %d" :
557 "You got %d points", i);
558 if (pnum == 0)
559 do_wait();
560 prhand(ph, pnum, Playwin, FALSE0);
561 prhand(ch, cnum, Compwin, TRUE1);
562 prtable(sum);
563 if (chkscr(&pscore, i))
564 return TRUE1;
565 }
566 myturn = !myturn;
567 }
568 }
569 if (sum >= 31) {
570 if (!myturn)
571 do_wait();
572 sum = 0;
573 mego = ugo = FALSE0;
574 Tcnt = 0;
575 last = FALSE0; /* disable last flag */
576 }
577 if (!pnum && !cnum)
578 break; /* both done */
579 }
580 prhand(ph, pnum, Playwin, FALSE0);
581 prhand(ch, cnum, Compwin, TRUE1);
582 prtable(sum);
583 if (last) {
584 if (played) {
585 msg(quiet ? "I get one for last" :
586 "I get one point for last");
587 do_wait();
588 if (chkscr(&cscore, 1))
589 return TRUE1;
590 } else {
591 msg(quiet ? "You get one for last" :
592 "You get one point for last");
593 do_wait();
594 if (chkscr(&pscore, 1))
595 return TRUE1;
596 }
597 }
598 return (FALSE0);
599}
600
601/*
602 * prtable:
603 * Print out the table with the current score
604 */
605void
606prtable(int score)
607{
608 prhand(Table, Tcnt, Tablewin, FALSE0);
609 mvwprintw(Tablewin, (Tcnt + 2) * 2, Tcnt + 1, "%2d", score);
610 wrefresh(Tablewin);
611}
612
613/*
614 * score:
615 * Handle the scoring of the hands
616 */
617int
618score(bool_Bool mycrib)
619{
620 sorthand(crib, CINHAND4);
621 if (mycrib) {
622 if (plyrhand(phand, "hand"))
623 return (TRUE1);
624 if (comphand(chand, "hand"))
625 return (TRUE1);
626 do_wait();
627 if (comphand(crib, "crib"))
628 return (TRUE1);
629 do_wait();
630 } else {
631 if (comphand(chand, "hand"))
632 return (TRUE1);
633 if (plyrhand(phand, "hand"))
634 return (TRUE1);
635 if (plyrhand(crib, "crib"))
636 return (TRUE1);
637 }
638 return (FALSE0);
639}