Deck Simplification
Unique Rank Patterns
| Core Hand Type | Formula | Result |
| Four of a Kind | Combin(13, 1) * Combin(12, 1) | 156 |
| Full House | Combin(13, 1) * Combin(12, 1) | 156 |
| Three of a Kind | Combin(13, 1) * Combin(12, 2) | 858 |
| Two Pair | Combin(13, 2) * Combin(11, 1) | 858 |
| One Pair | Combin(13, 1) * Combin(12, 3) | 2,860 |
| No Pair | Combin(13, 5) | 1,287 |
Unique Suit Patterns
| Four of a Kind |
Full House |
Three of a Kind |
Two Pair |
One Pair |
No Pair |
| Pattern | Count |
Pattern | Count |
Pattern | Count |
Pattern | Count |
Pattern | Count |
Pattern | Count |
| ABCDA | 4 | ABCAB | 12 | ABCAA | 12 | ABABA | 12 | ABAAA | 12 | AAAAA | 4 |
| | ABCAD | 12 | ABCAB | 24 | ABABC | 12 | ABAAB | 12 | AAAAB | 12 |
| | | | ABCAD | 12 | ABACA | 24 | ABAAC | 24 | AAABA | 12 |
| | | | ABCDA | 12 | ABACB | 24 | ABABA | 12 | AAABB | 12 |
| | | | ABCDD | 4 | ABACC | 24 | ABABB | 12 | AAABC | 24 |
| | | | | | ABACD | 24 | ABABC | 24 | AABAA | 12 |
| | | | | | ABCDA | 12 | ABACA | 24 | AABAB | 12 |
| | | | | | ABCDC | 12 | ABACB | 24 | AABAC | 24 |
| | | | | | | | ABACC | 24 | AABBA | 12 |
| | | | | | | | ABACD | 24 | AABBB | 12 |
| | | | | | | | ABCAA | 24 | AABBC | 24 |
| | | | | | | | ABCAB | 24 | AABCA | 24 |
| | | | | | | | ABCAC | 24 | AABCB | 24 |
| | | | | | | | ABCAD | 24 | AABCC | 24 |
| | | | | | | | ABCCA | 24 | AABCD | 24 |
| | | | | | | | ABCCC | 12 | ABAAA | 12 |
| | | | | | | | ABCCD | 12 | ABAAB | 12 |
| | | | | | | | ABCDA | 24 | ABAAC | 24 |
| | | | | | | | ABCDC | 12 | ABABA | 12 |
| | | | | | | | ABCDD | 12 | ABABB | 12 |
| | | | | | | | | | ABABC | 24 |
| | | | | | | | | | ABACA | 24 |
| | | | | | | | | | ABACB | 24 |
| | | | | | | | | | ABACC | 24 |
| | | | | | | | | | ABACD | 24 |
| | | | | | | | | | ABBAA | 12 |
| | | | | | | | | | ABBAB | 12 |
| | | | | | | | | | ABBAC | 24 |
| | | | | | | | | | ABBBA | 12 |
| | | | | | | | | | ABBBB | 12 |
| | | | | | | | | | ABBBC | 24 |
| | | | | | | | | | ABBCA | 24 |
| | | | | | | | | | ABBCB | 24 |
| | | | | | | | | | ABBCC | 24 |
| | | | | | | | | | ABBCD | 24 |
| | | | | | | | | | ABCAA | 24 |
| | | | | | | | | | ABCAB | 24 |
| | | | | | | | | | ABCAC | 24 |
| | | | | | | | | | ABCAD | 24 |
| | | | | | | | | | ABCBA | 24 |
| | | | | | | | | | ABCBB | 24 |
| | | | | | | | | | ABCBC | 24 |
| | | | | | | | | | ABCBD | 24 |
| | | | | | | | | | ABCCA | 24 |
| | | | | | | | | | ABCCB | 24 |
| | | | | | | | | | ABCCC | 24 |
| | | | | | | | | | ABCCD | 24 |
| | | | | | | | | | ABCDA | 24 |
| | | | | | | | | | ABCDB | 24 |
| | | | | | | | | | ABCDC | 24 |
| | | | | | | | | | ABCDD | 24 |
Total Unique Patterns
| Core Hand Type | Rank Patterns | Suit Patterns | Total |
| Four of a Kind | 156 | 1 | 156 |
| Full House | 156 | 2 | 312 |
| Three of a Kind | 858 | 5 | 4,290 |
| Two Pair | 858 | 8 | 6,864 |
| One Pair | 2,860 | 20 | 57,200 |
| No Pair | 1,287 | 51 | 65,637 |
| Total | 134,459 |
| Reduction in processing time | 94.8264% |
Hand Identification Codes
Because virtually any type of hand can be defined as a winner, numeric codes are used to describe each type of paying hand. The first four bits of each code identifies the Core Hand Type. The
following table illustrates the possible values for the Core Hand Type:
| Description | Value |
| Nothing | 0 |
| One Pair | 1 |
| Two Pair | 2 |
| Three of a Kind | 3 |
| Straight | 4 |
| Flush | 5 |
| Full House | 6 |
| Four of a Kind | 7 |
| Straight Flush (incl. Royal Flush) | 8 |
In addition to the Core Hand Type value above, there are two sets of 13 bits ("Major" and "Minor"). Each bit refers to one of the 13 card ranks (Deuce through Ace) and can be either zero or one,
depending on whether or not the card is allowed in each specific context. The context changes depending on the Core Hand Type, as illustrated in the following table:
| Core Hand Type | Major | Minor |
| Nothing | Not Used | Not Used |
| One Pair | Pair Rank | Not Used |
| Two Pair | Not Used | Not Used |
| Three of a Kind | Trips Rank | Not Used |
| Straight | Not Used | Not Used |
| Flush | Not Used | Not Used |
| Full House | Not Used | Not Used |
| Four of a Kind | Quads Rank | Kicker Rank |
| Straight Flush | High Card | Not Used |
Each 13-bit chunk is then combined with the Core Hand Type to produce a final
HandCode value using the following formula:
HandCode[x] = (CoreHandType << 26) + (Major << 13) + Minor;
Hand Scoring Code
The
HandCode[] array contains the numeric codes described above.
HandCode[0] corresponds to a losing hand, and all other
HandCode values correspond to
the winning hand types defined in the Paytable section.
int GetHandType(int C1, int C2, int C3, int C4, int C5)
{
int Code = 0, Hand = 0, Flags1 = 0, Flags2 = 0, x = 0;
int HC, F1, F2;
int FinalHand = 0;
int R1 = Rank[C1],
R2 = Rank[C2],
R3 = Rank[C3],
R4 = Rank[C4],
R5 = Rank[C5];
int S1 = Suit[C1],
S2 = Suit[C2],
S3 = Suit[C3],
S4 = Suit[C4],
S5 = Suit[C5];
bool Flush =
(S1 == S2) &&
(S2 == S3) &&
(S3 == S4) &&
(S4 == S5);
if (R1 > R2) { R1 ^= R2; R2 ^= R1; R1 ^= R2; }
if (R1 > R3) { R1 ^= R3; R3 ^= R1; R1 ^= R3; }
if (R1 > R4) { R1 ^= R4; R4 ^= R1; R1 ^= R4; }
if (R1 > R5) { R1 ^= R5; R5 ^= R1; R1 ^= R5; }
if (R2 > R3) { R2 ^= R3; R3 ^= R2; R2 ^= R3; }
if (R2 > R4) { R2 ^= R4; R4 ^= R2; R2 ^= R4; }
if (R2 > R5) { R2 ^= R5; R5 ^= R2; R2 ^= R5; }
if (R3 > R4) { R3 ^= R4; R4 ^= R3; R3 ^= R4; }
if (R3 > R5) { R3 ^= R5; R5 ^= R3; R3 ^= R5; }
if (R4 > R5) { R4 ^= R5; R5 ^= R4; R4 ^= R5; }
if (Flush)
{
if ((R4 == 3) && (R5 == 12))
{
Hand = 8; Flags1 = (1 << R4); // Straight Flush, Five High
}
else if ((R5 - R1) == 4)
{
Hand = 8; Flags1 = (1 << R5); // Straight Flush, Six through Ace High
}
else
{
Hand = 5; // Flush
}
}
else
{
if ((R1 == R2) && (R2 == R3) && (R3 == R4))
{
Hand = 7; Flags1 = (1 << R3); Flags2 = (1 << R5); // Four of a Kind, QQQQk
}
else if ((R2 == R3) && (R3 == R4) && (R4 == R5))
{
Hand = 7; Flags1 = (1 << R3); Flags2 = (1 << R1); // Four of a Kind, kQQQQ
}
else if ((R1 == R2) && (R2 == R3) && (R4 == R5)) // Full House, AAAbb
{
Hand = 6;
}
else if ((R1 == R2) && (R3 == R4) && (R4 == R5)) // Full House, aaBBB
{
Hand = 6;
}
else if ((R1 == (R2 - 1)) &&
(R2 == (R3 - 1)) &&
(R3 == (R4 - 1)) &&
((R4 == (R5 - 1)) || ((R1 == 0) && (R5 == 12))))
{
Hand = 4; // Straight
}
else if (((R1 == R2) && (R2 == R3)) ||
((R2 == R3) && (R3 == R4)) ||
((R3 == R4) && (R4 == R5)))
{
Hand = 3; Flags1 = (1 << R3); // Three of a Kind
}
else if (((R1 == R2) && (R3 == R4)) ||
((R1 == R2) && (R4 == R5)) ||
((R2 == R3) && (R4 == R5)))
{
Hand = 2; // Two Pair
}
else if ((R1 == R2) || (R2 == R3))
{
Hand = 1; Flags1 = (1 << R2); // One Pair, AAbcd or aBBcd
}
else if ((R3 == R4) || (R4 == R5))
{
Hand = 1; Flags1 = (1 << R4); // One Pair, abCCd or abcDD
}
}
for (x = NumHands - 1; x >= 1; x--)
{
HC = HandCode[x] >> 26; // Core Type
F1 = HandCode[x] & 16383; // Low Flags
F2 = (HandCode[x] >> 13) & 16383; // High Flags
if ((HC == Hand) && ((F1 & Flags1) == Flags1) && ((F2 & Flags2) == Flags2))
{
FinalHand = x; break;
}
}
return FinalHand;
}