3

我正在努力让我的扑克评估玩家手牌。我可以让同花顺和千斤顶或更好的配对工作,但在弄清楚我将如何做剩下的事情时遇到了问题。关于如何将卡片评估为适当类型的任何建议?

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;

}
4

2 回答 2

5

我会创建一个直方图数组来进行计数。

填充数组。如果恰好一个桶的计数为两个或更多,则您有一对,三条或四条。如果两个桶的计数为 2 或更多,则您有两对或满堂彩。

于 2011-12-07T22:46:37.177 回答
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;

也许这三个相同的值存储在手中的第一张、中间和最后一张牌中。

我不知道传统的扑克手评估器是如何编写的,但我感觉它们执行了一些额外的计算:创建一个数组,按卡片值索引,存储该值的卡片数量的计数

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);
}
于 2011-12-07T22:49:23.393 回答