Last active
May 15, 2017 13:44
-
-
Save tiagosiebler/ff169d71e51e0cb6892dac2c2ac2aeab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int64_t evalCustomLength(uint32_t cs[], uint32_t length) { | |
if(length <= 1) return (int64_t)1 << HC_SHIFT; | |
int64_t s[] = {-1, -1, -1, -1, -1}; | |
uint32_t count = 1, straight = 1, flush = 1, i; | |
uint32_t s0 = suit(cs[0]), r0 = rank(cs[0]); | |
s[0] = r0<<16; | |
// set flags for straight, flush, n-of-a-kind | |
for (i=1; i<length+1; i++) { | |
s[0] |= rank(cs[i])<<(4-i)*4; | |
if (straight && rank(cs[i-1])-rank(cs[i]) != 1 && !(i == 1 && r0 == 12 && rank(cs[1]) == 3)) | |
straight = 0; | |
if (flush == 1 && suit(cs[i]) != s0) | |
flush = 0; | |
if (rank(cs[i]) == rank(cs[i-1])) | |
count++; | |
if (i == 4 || rank(cs[i]) != rank(cs[i-1])) { | |
if (count == 2 && s[2] > -1) s[1] = rank(cs[i-1]); | |
else if (count == 2) s[2] = rank(cs[i-1]); | |
else if (count > 2) s[count] = rank(cs[i-1]); | |
count = 1; | |
} | |
} | |
// straight flush then straight | |
if (straight) { | |
if (r0 == 12 && rank(cs[1]) == 3) r0 = 3; | |
if (flush) return (int64_t)r0 << SFLUSH_SHIFT; | |
return (int64_t)r0 << STRAIGHT_SHIFT; | |
} | |
// flush | |
if (flush) { | |
return (int64_t)1 << FLUSH_SHIFT | | |
(int64_t)s[0] << HC_SHIFT; | |
} | |
// builds bitmask for n-of-a-kind and fullhouse | |
if (s[4] > -1) { | |
return ((int64_t)s[4]+1) << FOAK_SHIFT | s[0] << HC_SHIFT; | |
} | |
if (s[3] > -1) { | |
// fullhouse | |
if (s[2] > -1) | |
return (((int64_t)s[3]+1) << TOAK_SHIFT) | (((int64_t)s[2]+1) << PAIR2_SHIFT) | (int64_t)1 << FULL_SHIFT; | |
// three-of-a-kind | |
return ((int64_t)s[3]+1) << TOAK_SHIFT | s[0] << HC_SHIFT; | |
} | |
if (s[2] > -1) { | |
// two pairs | |
if (s[1] > -1) | |
return (((int64_t)s[2]+1) << PAIR2_SHIFT) | (((int64_t)s[1]+1) << PAIR1_SHIFT) | s[0] << HC_SHIFT; | |
// two-of-a-kind | |
return ((int64_t)s[2]+1) << PAIR1_SHIFT | s[0] << HC_SHIFT; | |
} | |
return (int64_t)s[0] << HC_SHIFT; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment