// Straight 5 sucessive diff suits N^5 + N^4 + 2*N^3 + highest Type // the Aces may be higher or lower static int checkStraight() { int id = 0, j, mcount = 0, HandCards = 5; for (j = 0; j <= HAND_CARDS - HandCards + 1; j++) { id = Card.idType(deck[j]); mcount = HandCards - 1; for (int i = j + 1; mcount != 0 && i < HAND_CARDS && mcount <= HAND_CARDS - i + 1; i++) { if (id == Card.idType(deck[i]) + 1) { mcount--; id = Card.idType(deck[i]); } } if (mcount == 0) { return(N5 + N4 + 2 * N3 + Card.idType(deck[j])); } } // check for low-Ace straight if (mcount == 1 && id == (int)CardType.Two && Card.idType(deck[0]) == (int)CardType.A) { return(N5 + N4 + 2 * N3 + (int)Card.idType(deck[j - 1])); } return(-1); }
/* delegate bool CheckKickerDel(int val, int f1, int f2); * CheckKickerDel checkKicker; * bool CheckKicker0(int val, int f1, int f2) { return true; } * bool CheckKicker1(int val, int f1, int f2) { return (val != f1); } * bool CheckKicker2(int val, int f1, int f2) { return (val != f1 && val != f2); } * * // factors only the 5 highest letters * int getKickersValue(int num, int found1, int found2) * { * int val = 0; * * for (int i = 0; num != 0 && i < HAND_CARDS; i++) * if (checkKicker(Card.idType(deck[i]), found1, found2)) * val += Card.idType(deck[i]) * Utils.pow(N, --num); * * return val; * } */ // extended static int getKickersValue0(int num) { int val = 0; for (int i = 0; num != 0 && i < HAND_CARDS; i++) { val += Card.idType(deck[i]) * Utils.pow(N, --num); } return(val); }
static int getKickersValue2(int num, int found1, int found2) { int val = 0; for (int i = 0; num != 0 && i < HAND_CARDS; i++) { int tt = Card.idType(deck[i]); if (tt != found1 && tt != found2) { val += Card.idType(deck[i]) * Utils.pow(N, --num); } } return(val); }
// Flush 5 increasing same suit N^5 + N^4 + 3*N^3 + type1*N^4 + type2*N^3 static int checkFlush() { int i; int HandCards = 5; int[] sol = new int[HandCards]; for (int j = 0; j <= HAND_CARDS - HandCards; j++) { int count = 1; int id = sol[HandCards - count] = deck[j]; for (i = j + 1; count < HandCards && i < HAND_CARDS; i++) { if (Card.idType(id) > Card.idType(deck[i]) && Card.idSuit(id) == Card.idSuit(deck[i])) { id = sol[HandCards - ++count] = deck[i]; } } if (count == HandCards) { int val = N5 + N4 + 3 * N3, exp = 4; for (int t = 0; t < HandCards && exp >= 0; t++) { val += Card.idType(sol[t]) * Utils.pow(N, exp--); } return(val); } } return(-1); }
// StraightFlush 5 sucessive same suit 2*N^5 + N^4 + 5*N^3 + highest cardtype static int checkStrFlush() { int i, id = 0, mcount = 0, suit = 0, HandCards = 5; int ttj = HAND_CARDS - HandCards + 1; for (int j = 0; j <= ttj; j++) { id = Card.idType(deck[j]); suit = Card.idSuit(deck[j]); mcount = HandCards - 1; for (i = j + 1; mcount != 0 && i < HAND_CARDS && mcount <= HAND_CARDS - i + 1; i++) { if (id == Card.idType(deck[i]) + 1 && suit == Card.idSuit(deck[i])) { mcount--; id = Card.idType(deck[i]); } } if (mcount == 0) { return(2 * N5 + N4 + 5 * N3 + Card.idType(deck[j])); } } // check for low-Ace straight flush if (mcount == 1 && id == (int)CardType.Two && Card.idType(deck[0]) == (int)CardType.A && Card.idSuit(deck[0]) == suit) { return(2 * N5 + N4 + 5 * N3 + Card.idType(deck[HAND_CARDS - HandCards])); } return(-1); }
// Highest Card type1*N^4 + type2*N^3 + type3*N^2 + type4*N + type5 // Pair N^5 + Type*N^3 + kicker1*N^2 + kicker2*N + kicker3 // Two Pairs N^5 + N^4 + Type1*N*N + Type2*N + kicker // Trio N^5 + N^4 + N^3 + Type*N^2 + kicker1*N + kicker2 // Full House trio + pair 2*N^5 + N^4 + 3*N^3 + N * Trio CardType + Pair CardType // Four-of-Kind 2*N^5 + N^4 + 4*N^3 + type static int checkKinds() { int i, idf, idt = -1, idp1 = -1, idp2 = -1; // four, trio, pair1, pair2 for (int j = 0; j <= HAND_CARDS - 2; j += i) { idf = Card.idType(deck[j]); for (i = 1; i + j < HAND_CARDS; i++) { if (idf != Card.idType(deck[i + j])) { break; } } if (i == 4) // four of a kind { return(2 * N5 + N4 + 4 * N3 + idf); } if (i == 3 && idt < 0) // trio { idt = idf; } else if (i > 1) // single pair or pair from trio { if (idp1 < 0) { idp1 = idf; } else if (idp2 < 0) { idp2 = idf; } } } if (idt >= 0) { if (idp1 >= 0) // fullhouse { return(2 * N5 + N4 + 3 * N3 + N * idt + idp1); } else // trio { return(N5 + N4 + N3 + N2 * idt + getKickersValue1(2, idt)); } } if (idp1 >= 0) { if (idp2 < 0) // pair { return(N5 + N3 * idp1 + getKickersValue1(3, idp1)); } else // two pairs { return(N5 + N4 + N2 * idp1 + N * idp2 + getKickersValue2(1, idp1, idp2)); } } return(getKickersValue0(5)); // highest card }