我在检查扑克手时遇到了一些问题。因此,在此代码中,我们选择要玩多少套牌,然后其余套牌就像视频扑克一样。我的问题是,有些手被“看见”了。对于笔直,我假设是因为设置好,好像我的arraylist是按假设排序一样,我该如何解决呢?

另外,对于两对,我的朋友说,有几次它不能正确检查我是否真的有两对,并说没有正确检查。这是我的检查算法,有人可以告诉我如何解决它们吗?另外,如果您有任何问题,除了直对和两对还存在问题。我还没能满堂而已,还没有去测试。 .get(#)从我的手(数组列表)中获得牌服或等级(getsuit或getrank)。我也认为我的同花顺可能是不正确的。

private boolean flush(){
        if (currentHand.get(0).getSuit() == currentHand.get(1).getSuit()
                && currentHand.get(1).getSuit() == currentHand.get(2).getSuit()
                && currentHand.get(2).getSuit() == currentHand.get(3).getSuit()
                && currentHand.get(3).getSuit() == currentHand.get(4).getSuit()){
        return true;
        }
        return false;
    }

    private boolean royal(){

            if ((currentHand.get(0).getRank() == 1)
                    && (currentHand.get(1).getRank() == 10)
                    && (currentHand.get(2).getRank() == 11)
                    && (currentHand.get(3).getRank() == 12)
                    && (currentHand.get(4).getRank() == 13)) {

                return true;

            }
        return false;
    }
    private boolean straight(){//look up
        if (currentHand.get(0).getRank() + 1 == currentHand.get(1).getRank()
                    && currentHand.get(1).getRank() + 1 == currentHand.get(2).getRank()
                    && currentHand.get(2).getRank() + 1 == currentHand.get(3).getRank()
                    && currentHand.get(3).getRank() + 1 == currentHand.get(4).getRank()) {

        return true;
        }
        return false;

    }
    private boolean four(){
        if (currentHand.get(0).getRank() == currentHand.get(1).getRank()
                && currentHand.get(1).getRank() == currentHand.get(2).getRank()
                && currentHand.get(2).getRank() == currentHand.get(3).getRank()) {
            return true;
        } else if (currentHand.get(1).getRank() == currentHand.get(2).getRank()
                && currentHand.get(2).getRank() == currentHand.get(3).getRank()
                && currentHand.get(3).getRank() == currentHand.get(4).getRank()) {
            return true;
        }
        return false;

    }
    private boolean fullHouse() {
        if (currentHand.get(0).getRank() == currentHand.get(1).getRank()
                && currentHand.get(1).getRank() == currentHand.get(2).getRank()) {
            if (currentHand.get(3).getRank() == currentHand.get(4).getRank()) {

                return true;
            }


        }else if(currentHand.get(0).getRank() == currentHand.get(1).getRank()){
            if(currentHand.get(2).getRank() == currentHand.get(3).getRank()
                && currentHand.get(3).getRank() == currentHand.get(4).getRank()){
                return true;
            }

        }
        return false;
    }
    private boolean threeOfKind(){
        if ((currentHand.get(0).getRank() == currentHand.get(1).getRank()
                && currentHand.get(1).getRank() == currentHand.get(2).getRank())
                || (currentHand.get(1).getRank() == currentHand.get(2).getRank()
                && currentHand.get(2).getRank() == currentHand.get(3).getRank())
                || (currentHand.get(2).getRank() == currentHand.get(3).getRank()
                && currentHand.get(3).getRank() == currentHand.get(4).getRank())){
        return true;
        }
        return false;
    }
    private boolean twoPair() {
        if (currentHand.get(0).getRank() == currentHand.get(1).getRank()
                && currentHand.get(2).getRank() == currentHand.get(3).getRank()){
            return true;
        }


            else if((currentHand.get(1).getRank() == currentHand.get(2).getRank())&&
            (currentHand.get(3).getRank() == currentHand.get(4).getRank())){
                return true;
            }

           else if((currentHand.get(0).getRank() == currentHand.get(1).getRank())&&
            (currentHand.get(3).getRank() == currentHand.get(4).getRank())){
                return true;
            }else

        return false;
    }
    private boolean jackOrBetter() {
        for (int i = 11; i <= 14; i++) {
            int comp;
            if (i == 14)
                comp =1;
            else comp = i;
            for (int j = 0; j < 4; j++) {
                if (currentHand.get(j).getRank() ==comp ) {
                    if (currentHand.get(j).getRank() == currentHand.get(j + 1).getRank()) {
                        return true;
                    }
                }
            }
        }
        return false;

最佳答案

通常,您在已知的(且非常快的)扑克评估器中可以找到的代码级别要比该级别低得多:没有花哨的OO或类似的东西。只是普通的快速位操作和疯狂的,疯狂的快速表查找。那里的快速手牌评估员可以每秒评估数亿只手!但是,让我们撇开它,从您的OOish代码开始。

我认为您需要一个五张牌的评估者,然后如果您玩德州扑克,那么您将测试C(7,5),它给出21种可能的方法来从七张牌中抽取5张(板上5个+ 2个孔卡)。并保持最佳状态。

接下来是您的五张卡片评估程序。

“技巧”通过保留中间信息来简化您的工作。这样就大大简化了您的逻辑。

这是您可以使用的一种方法(再次:与真正的快速评估人员相比,这过于简化了,但是它应该可以帮助您完成工作):

final boolean isFlush = flush();
final int[] nbPerRank = findNumberForEachRank();
final boolean isStraight = straight( nbPerRank );


例如,用于“装满五只皇后”(三只皇后和两个五只皇后)的nbPerRank数组可能如下所示:

;                   2  3  4  5  6  7  8  9  T  J  Q  K  A

int[] nbPerRank = [ 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 3, 0, 0 ]


然后,您的主要方法应如下所示:

if ( isStraight ) {
    final int highCard = findStraightHighCard();
    if ( isFlush ) {
        if ( highCard == 13 ) {     // starting with the 'A'
            System.out.println( "You have a royal flush" );
        else if ( highCard = 4 ) {  // starting with the '5'
            System.out.println( "You have a wheel straight flush" );
        } else {
            System.out.println( "You have a straight flush " );
        }
     } else {
        ... // rinse and repeat for normal straight
     }
 } else {
    ...


请注意,看到您的评估者是5卡评估者,一旦您获得了顺子,便知道只有两种可能的情况:顺子和顺子同花(有5张牌,如果您已经有顺子,就不可能有一对)这五张卡片)。

因此,到目前为止,您已经考虑了同花顺和同花顺,现在您需要检查以下内容:


同一样四个
满屋/船
平齐(但不再是平齐)

两对
一对


要检查您是否有四种,您可以查看nbPerRank int数组中是否有数字4。

伪代码可能是这样的:

// no need to test for straight an straight flush anymore...
if ( hasFourSameRank ) {
   " You have four of a kind ";
} else if ( hasThreeSameRank && hasTwoSameRank ) {
    " You have a full house ";
} else if ( isFlush ) {
    " You have a flush";
} else if ( hasThreeSameRank ) {
    " You have a set ";
} else if ( hasTwoSameRank ) {
    // two possible cases here: two pairs or one pair
    if ( hasTwoPairs ) {
        "You have two pairs";
    } else {
        "You have one pair";
} else {
    "You have no pair";
}


嵌套的if / else在这样的评估器中是很正常的(至少那些不使用查找表/ LUT的评估器)。

请注意,这仅是一种方法。您可以“发烧友”,而不是简单地返回包含每个等级的每张牌的数量的int [],您还可以返回最大牌数,相似等级的最大数量等。

然后,您将必须找到一种方法来为每只手分配一个值(因此称为“评估者”名称),以使“两对,八分和二进十出,踢脚杰克”击败“两对,八分和二进十出,踢脚九人”等等

但这应该可以帮助您入门。

另一种解决方案是简单地重用现有的一个评估器(除了经过尝试和测试之外,还应该非常快:这只是位操作和查找表,没有慢的OO)。

(略有关联),您可能还想在这里阅读我的旧答案:On Two Plus Two poker hand evaluator, how do you get the best 5 cards combination out of the 7 that you passed to it?

10-04 14:52
查看更多