int main(int argc, char *argv[]) { int i, j, k, l, c; hand_t hand; score_t sc = -1; scanf("%d %d %d %d %d", &i, &j, &k, &l, &c); hand = (hand_t) {.cards[0] = i, .cards[1] = j, .cards[2] = k, .cards[3] = l, .crib = c}; # ifdef TEST_PAIRS sc = pairs(&hand); # elif TEST_FIFTEENS sc = fifteens(&hand); # elif TEST_RUNS sc = runs(&hand); # elif TEST_RIGHTJACK sc = right_jack(&hand); # elif TEST_SCORE sc = score(&hand); # elif TEST_TYPE //fprintf(stderr, "Using card: %d\n", hand.cards[0]); sc = type(hand.cards[0]); //fprintf(stderr, "Type: %d\n", sc); # elif TEST_VALUES fprintf(stderr, "Using card: %d\n", hand.cards[4]); sc = value(hand.cards[4]); fprintf(stderr, "Value: %d\n", sc); # endif /* TEST_* */ printf("%d\n", (int) sc); return 0; }
/* Score the hand */ score_t score(hand_t * hand) { return right_jack(hand) + runs(hand) + pairs(hand) + fifteens(hand); }
/* * 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); }