|
using System; |
|
using Com.Expload; |
|
|
|
[Program] |
|
class MyProgram |
|
{ |
|
private int get_suit(int card) |
|
{ |
|
// 0 = spades |
|
// 1 = clubs |
|
// 2 = hearts |
|
// 3 = diamonds |
|
return card - (card % 20); |
|
} |
|
private int get_value(int card) |
|
{ |
|
// 0 = 2 |
|
// 1 = 3 |
|
// ... |
|
// 8 = 10 |
|
// 9 = J |
|
// 10 = Q |
|
// 11 = K |
|
// 12 = A |
|
return card % 20; |
|
} |
|
private int CARD_VAL_2 = 0; |
|
private int CARD_VAL_A = 12; |
|
|
|
public int get_combination_value(int c0, int c1, int c2, int c3, int c4) |
|
{ |
|
// if (isRoyalFlush(cards)) // royal flush doesn't mean shit because it's just a straight flush with highest card Ace |
|
// return 65000; |
|
|
|
int cv0 = get_value(c0); |
|
int cv1 = get_value(c1); |
|
int cv2 = get_value(c2); |
|
int cv3 = get_value(c3); |
|
int cv4 = get_value(c4); |
|
|
|
// High cards by rank |
|
return 5 * cv4 + 4 * cv3 + 3 * cv2 + 2 * cv1 + cv0; |
|
} |
|
|
|
|
|
// ###### ####### ## ## ######## ###### |
|
// ## ## ## ## ### ### ## ## ## ## |
|
// ## ## ## #### #### ## ## ## |
|
// ## ## ## ## ### ## ######## ###### |
|
// ## ## ## ## ## ## ## ## |
|
// ## ## ## ## ## ## ## ## ## ## |
|
// ###### ####### ## ## ######## ###### |
|
|
|
|
|
private bool isFourOfAKind(int c0, int c1, int c2, int c3, int c4) |
|
{ |
|
// optimized version (cards are sorted by value already) |
|
if ((c0 == c1) |
|
&& (c0 == c2) |
|
&& (c0 == c3)) |
|
return true; |
|
|
|
if ((c4 == c1) |
|
&& (c4 == c2) |
|
&& (c4 == c3)) |
|
return true; |
|
|
|
return false; |
|
} |
|
private bool isFlush(int c0, int c1, int c2, int c3, int c4) |
|
{ |
|
int suit = get_suit(c0); |
|
return (suit == get_suit(c1)) |
|
&& (suit == get_suit(c2)) |
|
&& (suit == get_suit(c3)) |
|
&& (suit == get_suit(c4)) |
|
; |
|
} |
|
private bool isStraightSimple(int c0, int c1, int c2, int c3, int c4) |
|
{ |
|
if (c0 != (c1 - 1)) |
|
return false; |
|
if (c0 != (c2 - 2)) |
|
return false; |
|
if (c0 != (c3 - 3)) |
|
return false; |
|
if (c0 != (c4 - 4)) |
|
return false; |
|
|
|
return true; |
|
} |
|
private bool isStraight(int c0, int c1, int c2, int c3, int c4) |
|
{ |
|
// 5,6,7,8,9 |
|
// 2,3,4,5,A |
|
// 10,J,Q,K,A |
|
// straights can't wrap around (2,3,4,K,A is not a straight) |
|
if (isStraightSimple(c0, c1, c2, c3, c4)) |
|
return true; |
|
|
|
if (c0 != CARD_VAL_2) |
|
return false; |
|
if (c4 != CARD_VAL_A) |
|
return false; |
|
|
|
if ((c1 == (c0 + 1)) |
|
&& (c2 == (c0 + 2)) |
|
&& (c3 == (c0 + 3))) |
|
return true; |
|
|
|
if ((c4 == (c3 + 1)) |
|
&& (c4 == (c2 + 2)) |
|
&& (c4 == (c1 + 3))) |
|
return true; |
|
|
|
return false; |
|
} |
|
|
|
// Three of a kind |
|
private bool isThreeOfAKind(int c0, int c1, int c2, int c3, int c4) |
|
{ |
|
if ((c0 == c1) |
|
&& (c0 == c2)) |
|
return true; |
|
|
|
if ((c1 == c2) |
|
&& (c1 == c3)) |
|
return true; |
|
|
|
if ((c2 == c3) |
|
&& (c2 == c4)) |
|
return true; |
|
|
|
return false; |
|
} |
|
} |
|
|
|
class MainClass |
|
{ |
|
public static void Main() {} |
|
} |