/** * Copyright (C) 2008 Thomas Cort * License: GPLv3 or later. */ #include #include #define EVAL_C ( 2ll) #define EVAL_H ( 3ll) #define EVAL_D ( 5ll) #define EVAL_S ( 7ll) #define EVAL_2 (11ll) #define EVAL_3 (13ll) #define EVAL_4 (17ll) #define EVAL_5 (19ll) #define EVAL_6 (23ll) #define EVAL_7 (29ll) #define EVAL_8 (31ll) #define EVAL_9 (37ll) #define EVAL_T (41ll) #define EVAL_J (43ll) #define EVAL_Q (47ll) #define EVAL_K (53ll) #define EVAL_A (59ll) #define EVAL_STR_5 ( 2725151ll) #define EVAL_STR_6 ( 1062347ll) #define EVAL_STR_7 ( 2800733ll) #define EVAL_STR_8 ( 6678671ll) #define EVAL_STR_9 ( 14535931ll) #define EVAL_STR_T ( 31367009ll) #define EVAL_STR_J ( 58642669ll) #define EVAL_STR_Q ( 95041567ll) #define EVAL_STR_K (162490421ll) #define EVAL_STR_A (259106347ll) int64_t primes[] = { /* i */ EVAL_C, /* 0 */ EVAL_H, /* 1 */ EVAL_D, /* 2 */ EVAL_S, /* 3 */ EVAL_2, /* 4 */ EVAL_3, /* 5 */ EVAL_4, /* 6 */ EVAL_5, /* 7 */ EVAL_6, /* 8 */ EVAL_7, /* 9 */ EVAL_8, /* 10 */ EVAL_9, /* 11 */ EVAL_T, /* 12 */ EVAL_J, /* 13 */ EVAL_Q, /* 14 */ EVAL_K, /* 15 */ EVAL_A /* 16 */ }; #define NPRIMES (17) void eval(int64_t hand) { int i, cnt; int64_t tmp, ranks; int cnts[NPRIMES]; int flush = 0, straight = 0, quad = 0, triple = 0, paira = 0, pairb = 0; for (i = 0; i < NPRIMES; i++) { if (i == 4) { ranks = hand; } cnt = 0; while ((tmp=hand/primes[i]) * primes[i] == hand) { hand = tmp; cnt++; } cnts[i] = cnt; if (i > 3) { switch (cnt) { case 4: quad = primes[i]; break; case 3: triple = primes[i]; break; case 2: if (paira == 0) { paira = primes[i]; } else { pairb = primes[i]; } break; default: break; } } else if (cnt == 5) { flush = primes[i]; } } if (!paira && !triple && !quad) { switch (ranks) { case EVAL_STR_5: case EVAL_STR_6: case EVAL_STR_7: case EVAL_STR_8: case EVAL_STR_9: case EVAL_STR_T: case EVAL_STR_J: case EVAL_STR_Q: case EVAL_STR_K: case EVAL_STR_A: straight = ranks; break; default: break; } } if (flush && straight) { printf("STRAIGHTFLUSH\n"); } else if (quad) { printf("FOUR OF A KIND\n"); } else if (triple && paira) { printf("FULL HOUSE\n"); } else if (flush) { printf("FLUSH\n"); } else if (straight) { printf("STRAIGHT\n"); } else if (triple) { printf("THREE OF A KIND\n"); } else if (paira && pairb) { printf("TWO PAIR\n"); } else if (paira) { printf("ONE PAIR\n"); } else { printf("HIGH CARD\n"); } } int main(int argc, char *argv[]) { int64_t hand; hand = (EVAL_A * EVAL_S) * (EVAL_K * EVAL_S) * (EVAL_Q * EVAL_S) * (EVAL_J * EVAL_S) * (EVAL_T * EVAL_S); eval(hand); printf("--\n"); hand = (EVAL_A * EVAL_D) * (EVAL_2 * EVAL_S) * (EVAL_3 * EVAL_S) * (EVAL_4 * EVAL_S) * (EVAL_5 * EVAL_S); eval(hand); printf("--\n"); hand = (EVAL_A * EVAL_S) * (EVAL_A * EVAL_H) * (EVAL_A * EVAL_D) * (EVAL_J * EVAL_S) * (EVAL_J * EVAL_C); eval(hand); return 0; }