我正在努力让我的扑克来评估玩家手牌。我可以让Flush和千斤顶或更好的一对工作,但我遇到了问题,弄清楚我将如何做其余的事情。关于如何将卡片评估为合适类型的任何建议?
int Game::HandCheck()
{
//ROYAL FLUSH
//return 9;
//STRAIGHT FLUSH
//return 8;
//FOUR OF A KIND
//return 7;
//FULL HOUSE
//return 6;
//FLUSH
if( currentHand[ 0 ].GetSuit() == currentHand[ 1 ].GetSuit() && currentHand[ 1 ].GetSuit() == currentHand[ 2 ].GetSuit() &&
currentHand[ 2 ].GetSuit() == currentHand[ 3 ].GetSuit() && currentHand[ 4 ].GetSuit() == currentHand[ 4 ].GetSuit() )
return 5;
//STRAIGHT
//return 4;
//THREE OF A KIND
if( currentHand[ 0 ].GetValue() == currentHand[ 2 ].GetValue() && currentHand[ 0 ].GetValue() == currentHand[ 3 ].GetValue()
//return 3;
//TWO PAIR
//return 2;
//JACKS OR BETTER PAIR
for( int i = 0; i < 5; i++ )
{
if( currentHand[ i ].GetValue() == 11 || currentHand[ i ].GetValue() == 12 || currentHand[ i ].GetValue() == 13 || currentHand[ i ].GetValue() == 1 )
{
if( currentHand[ i ].GetValue() == currentHand[ i + 1 ].GetValue() || currentHand[ i ].GetValue() == currentHand[ i + 2 ].GetValue() || //pair
currentHand[ i ].GetValue() == currentHand[ i + 3 ].GetValue() || currentHand[ i ].GetValue() == currentHand[ i + 4 ].GetValue() )
return 1;
}
}
return 0;
}
答案 0 :(得分:5)
我会创建一个直方图数组来进行计数。
填充阵列。 如果只有一个桶有两个或更多的数量,你有一对,绊倒或四种。 如果两个桶的数量为两个或更多,则有两个或一个满屋。
答案 1 :(得分:3)
您的Flush
算法正在将4
与自身进行比较:
//FLUSH
if( currentHand[ 0 ].GetSuit() == currentHand[ 1 ].GetSuit() && currentHand[ 1 ].GetSuit() == currentHand[ 2 ].GetSuit() &&
currentHand[ 2 ].GetSuit() == currentHand[ 3 ].GetSuit() && currentHand[ 4 ].GetSuit() == currentHand[ 4 ].GetSuit() )
return 5;
^^^---------------------------^^^
你的三种算法假设所有三个值都在前三个位置:
//THREE OF A KIND
if( currentHand[ 0 ].GetValue() == currentHand[ 2 ].GetValue() && currentHand[ 0 ].GetValue() == currentHand[ 3 ].GetValue()
//return 3;
也许三个相同的值存储在手中的第一张,中间张和最后一张牌中。
我不知道传统的扑克手评估器是如何编写的,但我感觉他们执行了一些额外的计算:创建一个由卡值索引的数组,用于存储 count 该值的卡数:
int reverse_hand[13] = {0};
for (int i=0; i<HAND_SIZE; i++) {
reverse_hand[currentHand[i].getValue()] += 1;
}
int pairs[2] = {-1, -1};
int pairs_count = 0;
int triple = -1;
int quad = -1;
int straight_pos = -1;
for (int i=0; i<13; i++) {
count = reverse_hand[i];
if (count == 2) {
pairs[pairs_count++] = i;
} else if (count == 3) {
triple = i;
} else if (count == 4) {
quad = i;
} else if (count == 1) {
if ((i < (13-5)) && (reverse_hand[i] == 1) &&
(reverse_hand[i+1] == 1) &&
(reverse_hand[i+2] == 1) &&
(reverse_hand[i+3] == 1) &&
(reverse_hand[i+4] == 1)) {
straight_pos = i;
}
}
if (pairs_count == 2) {
printf("You had two pairs, %d low and %d high\n", pairs[0], pairs[1]);
} else if (pairs_count == 1) {
printf("YOu had one pair of %d\n", pairs[0]);
}
if (triple >= 0) {
printf("You had a three of a kind: %d\n", triple);
}
if (quad >= 0) {
printf("You had a four of a kind: %d\n", quad);
}
if (pairs_count == 1 && triple >=0) {
printf("Full house, three %d and two %d\n", triple, pairs[0]);
}
/* code here for flush detection */
if (straight_pos >= 0) {
int p = straight_pos;
/* if straight flush print a different message */
printf("Straight, %d %d %d %d %d\n", p, p+1, p+2, p+3, p+4);
}