/* * playhand: * Do up one hand of the game */ int playhand(bool mycrib) { int deckpos; werase(Compwin); wrefresh(Compwin); werase(Tablewin); wrefresh(Tablewin); knownum = 0; 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; }
/* * score: * Handle the scoring of the hands */ int score(bool mycrib) { 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); do_wait(); } else { if (comphand(chand, "hand")) return (TRUE); if (plyrhand(phand, "hand")) return (TRUE); if (plyrhand(crib, "crib")) return (TRUE); } return (FALSE); }
/* * scorehand: * Score the given hand of n cards and the starter card. * n must be <= 4 * crb is true if scoring crib * do_explain is true if must explain this hand */ int scorehand(CARD hand[], CARD starter, int n, bool crb, bool do_explain) { int i, k; int score; bool flag; CARD h[(CINHAND + 1)]; char buf[32]; explstr[0] = '\0'; /* initialize explanation */ score = 0; flag = true; k = hand[0].suit; for (i = 0; i < n; i++) { /* check for flush */ flag = (flag && (hand[i].suit == k)); if (hand[i].rank == JACK) /* check for his nibs */ if (hand[i].suit == starter.suit) { score++; if (do_explain) strcat(explstr, "His Nobs"); } h[i] = hand[i]; } if (flag && n >= CINHAND) { if (do_explain && explstr[0] != '\0') strcat(explstr, ", "); if (starter.suit == k) { score += 5; if (do_explain) strcat(explstr, "Five-flush"); } else if (!crb) { score += 4; if (do_explain && explstr[0] != '\0') strcat(explstr, ", Four-flush"); else strcpy(explstr, "Four-flush"); } } if (do_explain && explstr[0] != '\0') strcat(explstr, ", "); h[n] = starter; sorthand(h, n + 1); /* sort by rank */ i = 2 * fifteens(h, n + 1); score += i; if (do_explain) { if (i > 0) { sprintf(buf, "%d points in fifteens", i); strcat(explstr, buf); } else strcat(explstr, "No fifteens"); } i = pairuns(h, n + 1); score += i; if (do_explain) { if (i > 0) { sprintf(buf, ", %d points in pairs, %d in runs", pairpoints, runpoints); strcat(explstr, buf); } else strcat(explstr, ", No pairs/runs"); } return (score); }