在给定 7 张牌的情况下获得所有可能的 5 张扑克手牌
Get all possible 5 card poker hands given 7 cards
我正在尝试找出在 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 元素数组。
谢谢!
每手 select 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++;
}
}
我正在尝试找出在 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 元素数组。
谢谢!
每手 select 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++;
}
}