Java - 如何评估最好的高牌手?

我正在制作一个扑克应用程序。然而,我坚持评估高牌。(我知道怎么拿到大牌,但是如果2/3玩家的大牌是一样的呢?)


我的清单是有序的,所以这不是问题。问题是我不知道将 5 张手牌与其他玩家的手牌进行比较的好方法。


是的,卡片是按rankComparator班级排序的。


我有一个简单的Player类,其中包含一组卡片(他的手):


public class Player {


    private List<Card> cards;

    private int valueWaarde;

    private String valueAsString;

    private String name;

    private HandEval1 h1;


    public String getValueAsString() {

        return valueAsString;

    }



    public Integer getValueWaarde() {

        return valueWaarde;

    }


    public List<Card> getCards() {

        return cards;

    }


    public Player(String name){

        this.name = name;

    }


    public Player() {

    }


    public void addCard(Card c) {

        if (cards == null) {

            this.cards = new ArrayList<>();

        }


        this.cards.add(c);

    }


    public void clearCards() {

        if (cards != null) {

            cards.clear();

        }

    }


    public Map<String, Integer> valueOfHand(List<Card> cards, List<Card> cardsBoard) {

       h1 = new HandEval1(cards, cardsBoard);

       Map<String, Integer> map = h1.evaluateHand();


        for (Map.Entry<String, Integer> entry : map.entrySet()) {

            this.valueWaarde = entry.getValue();

            this.valueAsString = entry.getKey();

        }


       return map;

    }



    @Override

    public String toString() {

        return name;

    }


}

我有一个简单的卡片类,如下所示:


public class Card {


    private final int suitValue;

    private Rank rank;

    private Suit suit;

    private int value;


    public int getSuitValue() {

        return suitValue;

    }


    public int getValue() {

        return value;

    }


    public Rank getRank() {

        return rank;

    }


    public Suit getSuit() {

        return suit;

    }


    public enum Suit {

        h(1), c(2), d(3), s(4);


        final int value;

        Suit(int value) {

            this.value = value;

        }

    }


ABOUTYOU
浏览 153回答 2
2回答

慕神8447489

您可以向您的Rank和Suit枚举添加一个方法,以便您可以轻松检索int枚举的值。例如,您的Rank枚举可能是这样的:public enum Rank {&nbsp; &nbsp; ACE(1),TWO(2), THREE(3), FOUR(4), FIVE(5), SIX(6), SEVEN(7), EIGHT(8), NINE(9), TEN(10),&nbsp; &nbsp; JACK(11), QUEEN(12), KING(13);&nbsp; &nbsp; final int value;&nbsp; &nbsp; Rank(int value) {&nbsp; &nbsp; &nbsp; &nbsp; this.value = value;&nbsp; &nbsp; }&nbsp; &nbsp; public int getValue() { // Added method&nbsp; &nbsp; &nbsp; &nbsp; return value;&nbsp; &nbsp; }}因此,您可以执行以下操作,根据排名比较两只手:public void calculateGreaterHand(List<Card> cards1, List<Card> cards2) {&nbsp; &nbsp; for (int i = 0; i < cards1.size(); i++) {&nbsp; &nbsp; &nbsp; &nbsp; if (cards1.get(i).getRank().getValue() > cards2.get(i).getRank().getValue()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("cards1 is greater");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;&nbsp; &nbsp; &nbsp; &nbsp; } else if (cards1.get(i).getRank().getValue() < cards2.get(i).getRank().getValue()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println("cards2 is greater");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; // If code gets to this point, then the hands are equal.}如果这与您要查找的内容相似,请告诉我。

慕尼黑8549860

即使这只是一个爱好项目,您可能迟早要向前迈进,评估/比较所有可能的扑克牌,而不仅仅是高牌。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java