【问题标题】:Get all possible 5 card poker hands given 7 cards得到所有可能的 5 张牌扑克手给 7 张牌
【发布时间】:2016-02-24 21:46:12
【问题描述】:

我试图找到 21 支 5 张牌的扑克牌,给定一个 5 张牌板和 2 张底牌。这是我目前所拥有的:

public String[] joinArrays(String[] first, String[] second) {
        String[] result = new String[first.length + second.length];
        for (int i = 0; i < first.length; i++) {
            result[i] = first[i];
        }
        for (int i = 0; i < second.length; i++) {   
            result[i + first.length] = second[i]; 
        }
        return result;
    }

    public String[][] getAllPossibleHands(String[] board, String[] hand){
        String[] allCards = joinArrays(board, hand);
        String[][] allHands = new String[21][5];
        ...
    }

关于从这里去哪里的任何提示?我有一个包含 7 个元素的数组,并希望从这些元素中创建 7C5 (21) 个 5 元素数组。

谢谢!

【问题讨论】:

    标签: java poker


    【解决方案1】:

    对于每一手牌,从 7 张牌中选择两张不要使用。添加所有其他人

    int cardsSelected = 0;
    int hand = 0;
    // select first card not to be in the hand
    for(int firstCard = 0; firstCard < 7; firstCard++){
        // select first card not to be in the hand
        for(int secondCard = firstCard + 1; secondCard < 7; secondCard++){
            // every card that is not the first or second will added to the hand
            for(int i = 0; i < 7; i++){
                if(i != firstCard && i != secondCard){
                    allHands[hand][cardsSelected++] = allCards[i];
                }
            }
            // next hand
            cardsSelected = 0;
            hand++;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-19
      • 2021-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多