void chkwinner(int player, const int *hand) { int cb, i, ub; for (i = 0; i < RANKS; ++i) if (hand[i] > 0 && hand[i] < CARDS) return; printplayer(player); (void)printf("don't have any more cards!\n"); (void)printf("My books:"); cb = countbooks(comphand); (void)printf("Your books:"); ub = countbooks(userhand); (void)printf("\nI have %d, you have %d.\n", cb, ub); if (ub > cb) { (void)printf("\nYou win!!!\n"); if (nrandom(1024) == 0723) (void)printf("Cheater, cheater, pumpkin eater!\n"); } else if (cb > ub) { (void)printf("\nI win!!!\n"); if (nrandom(1024) == 0723) (void)printf("Hah! Stupid peasant!\n"); } else (void)printf("\nTie!\n"); exit(0); }
static void chkwinner (enum EPlayer player) { for (unsigned i = 0; i < RANKS; ++i) if (_hand[player][i] > 0 && _hand[player][i] < SUITS) return; draw_panel(); printplayer (player); waddstr (_wmsg, "don't have any more cards!\n\nMy books:"); unsigned cb = countbooks (COMPUTER); waddstr (_wmsg, "Your books:"); unsigned ub = countbooks (USER); wprintw (_wmsg, "\nI have %d, you have %d.\n", cb, ub); if (ub > cb) { waddstr (_wmsg, "\nYou win!!!\n"); if (!nrand(64)) waddstr (_wmsg, "Cheater, cheater, pumpkin eater!\n"); } else if (cb > ub) { waddstr (_wmsg, "\nI win!!!\n"); if (!nrand(64)) waddstr (_wmsg, "Hah! Stupid peasant!\n"); } else waddstr (_wmsg, "\nTie!\n"); wgetch (_wmsg); exit (EXIT_SUCCESS); }
int usermove(void) { int n; const char *const *p; char buf[256]; (void)printf("\nYour hand is:"); printhand(userhand); for (;;) { (void)printf("You ask me for: "); (void)fflush(stdout); if (fgets(buf, sizeof(buf), stdin) == NULL) exit(0); if (buf[0] == '\0') continue; if (buf[0] == '\n') { (void)printf("%d cards in my hand, %d in the pool.\n", countcards(comphand), curcard); (void)printf("My books:"); (void)countbooks(comphand); continue; } buf[strlen(buf) - 1] = '\0'; if (!strcasecmp(buf, "p") && !promode) { promode = 1; (void)printf("Entering pro mode.\n"); continue; } if (!strcasecmp(buf, "quit")) exit(0); for (p = cards; *p; ++p) if (!strcasecmp(*p, buf)) break; if (!*p) { (void)printf("I don't understand!\n"); continue; } n = p - cards; if (userhand[n]) { userasked[n] = 1; return(n); } if (nrandom(3) == 1) (void)printf("You don't have any of those!\n"); else (void)printf("You don't have any %s's!\n", cards[n]); if (nrandom(4) == 1) (void)printf("No cheating!\n"); (void)printf("Guess again.\n"); } /* NOTREACHED */ }