我正在尝试找到在 5 张牌和 2 张底牌的情况下可以形成的 21 手 5 张牌扑克牌。这是我到目前为止所拥有的:
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 元素数组。
谢谢!
最佳答案
对于每手牌,从 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++;
}
}
关于java - 给定 7 张牌,获得所有可能的 5 张牌扑克牌,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33859993/