我用随机抽样的方法从一副52张牌中选出了三张牌。现在,我想在N手中找到赢家。
这些是找到赢家的规则。
试用(三张价值相同的卡)
二次运行(三张值顺序相同的卡片)
运行(连续三张卡)
颜色(同套装三张牌)
相同(三张卡中有两张值相同)
正常状态
赢牌的优先顺序为降序,获得这些牌的概率为升序。

受审概率最小,胜诉率最高等。
我已按试验顺序检查到正常。

boolean trial = this.checkTrial();
    if(!trial){
        boolean doubleRun = this.checkDoubleRun();
        if(!doubleRun){
            boolean run = this.checkRun();
            if(!run){
                boolean color = this.checkColor();
                if(!color){
                    boolean same = this.checkSame();
                    if(!same){
                        this.checkHighest();
                        System.out.println("Normal");
                    }
                    else{
                        System.out.println("Same");
                    }
                }
                else{
                    System.out.println("Color");
                }
            }
            else{
                System.out.println("Run");
            }
        }
        else{
            System.out.println("Double Run");
        }
    }
    else{
        System.out.println("Trial");
    }

这是最好的办法吗?
我有两个选择
在这两人中找到赢家的最佳方法是什么?
最小到最大概率(从试验检查到正常)
最大到最小概率(从正常检查到试验)
如有任何建议,我们将不胜感激。

最佳答案

我认为你需要建立一个用三张扑克牌或三张扑克牌或冲水的游戏系统,
允许识别所有涉及的对象
卡-有2个属性颜色和基数,因此类卡将
班级卡{

char color;
short number;

public Card(char color, short number) {
    this.color = color;
    this.number = number;

}

public char getColor() {
    return color;
}

public void setColor(char color) {
    this.color = color;
}

public short getNumber() {
    return number;
}

public void setNumber(short number) {
    this.number = number;
}

}
一副牌是由52张牌组成的,因此
甲板{
char[] deckColors = {'♦', '♠', '♣', '♥'};
short[] cardNum = {(short) 'A', (short) '2', (short) '3', (short) '4', (short) '5', (short) '6', (short) '7',
                   (short) '8', (short) '9', (short) 'T', (short) 'J', (short) 'Q', (short) 'K'};
int cardCount;

public Card[] getShuffledDeck() {

    Random r = new Random();


    Card[] deckCards = new Card[(deckColors.length * cardNum.length)];

    int cnt = 0;

    for (char c : deckColors) {
        for (short s : cardNum) {
            deckCards[cnt++] = new Card(c, s);
        }
    }

    Card[] shuffledDeck = new Card[deckCards.length];

    int addedCount = 0;


    while (addedCount < deckCards.length) {
        int tInt = r.nextInt((deckCards.length));

        Card c = deckCards[tInt];

        if (c != null) {

            shuffledDeck[addedCount++] = c;
            deckCards[tInt] = null;

        } else {

        }
    }

    return shuffledDeck;

}

}
一组3张牌,但是最好用getHandRanking()这样的方法创建一个类,它将实际计算牌手的力量
班手{
Card[] cards;

int handRank;

public Hand(Card[] cards) {

    this.cards = new Card[3];

    //sort all cards
    if (cards[0].getNumber() > cards[1].getNumber()) {
        if (cards[0].getNumber() > cards[2].getNumber()) {
            //0 index is highest card
            this.cards[2] = cards[0];
            if (cards[2].getNumber() > cards[1].getNumber()) {
                //2 is second highest
                this.cards[1] = cards[2];
                this.cards[0] = cards[1];
            } else {
                //1 is second highest
                this.cards[1] = cards[1];
                this.cards[0] = cards[2];
            }

        } else {
            //2 index is highest

            this.cards[2] = cards[2];
            if (cards[0].getNumber() > cards[1].getNumber()) {
                //0 is second highest
                this.cards[1] = cards[0];
                this.cards[0] = cards[1];
            } else {
                //1 is second highest
                this.cards[1] = cards[1];
                this.cards[0] = cards[0];
            }
        }

    } else {
        if (cards[1].getNumber() > cards[2].getNumber()) {
            //1 index is highest card
            this.cards[2] = cards[1];
            if (cards[2].getNumber() > cards[0].getNumber()) {
                //2 is second highest
                this.cards[1] = cards[2];
                this.cards[0] = cards[0];
            } else {
                //0 is second highest
                this.cards[1] = cards[0];
                this.cards[0] = cards[2];
            }
        } else {
            //2 index is highest
            this.cards[2] = cards[2];
            if (cards[0].getNumber() > cards[1].getNumber()) {
                //0 is second highest
                this.cards[1] = cards[0];
                this.cards[0] = cards[1];
            } else {
                //1 is second highest
                this.cards[1] = cards[1];
                this.cards[0] = cards[0];
            }
        }
    }
}

public int getHandRank() {
    return handRank > 0 ? handRank : calculateHandRank();
}

public int calculateHandRank() {
    //assuming 3 cards dealt
    //Trial - ColorSeq - Seq - Color - Pair
    int[] powerOf2s = {1, 2, 4, 8, 16};
    return ((cards[0].getNumber() == cards[1].getNumber() && cards[1].getNumber() == cards[2].getNumber()) ? 1 : 0) * powerOf2s[4]
            + (((cards[2].getNumber() - 1 == cards[1].getNumber() && cards[1].getNumber() - 1 == cards[0].getNumber()) && (cards[2].getColor() == cards[1].getColor() && cards[1].getColor() == cards[0].getColor())) ? 1 : 0) * powerOf2s[3]
            + ((cards[2].getNumber() - 1 == cards[1].getNumber() && cards[1].getNumber() - 1 == cards[0].getNumber()) ? 1 : 0) * powerOf2s[2]
            + (((cards[2].getColor() == cards[1].getColor() && cards[1].getColor() == cards[0].getColor())) ? 1 : 0) * powerOf2s[1]
            + ((cards[0].getNumber() == cards[1].getNumber() || cards[1].getNumber() == cards[2].getNumber() || cards[0].getNumber() == cards[2].getNumber()) ? 1 : 0) * powerOf2s[0];

}

}
现在你只需要看看哪个玩家的手的等级在所有玩家的手中最高,如果两个玩家碰巧有相同的手的等级,那么看看谁的手的等级高。卡[2],[1],[0]。
如果需要任何解释,请告诉我。
算法可以得到很大的改进,给出的代码示例只是为了说明思想过程。

关于java - 如何确定3张纸牌中的纸牌模式以寻找获胜者?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43713602/

10-13 05:04