我想知道是否有人知道如何用java实现代码来打印满堂彩的所有情况。大约有 3700 种不同的情况。到目前为止我已经2700左右了,但是我在换套装时遇到了麻烦,她就是我目前所拥有的。
public class FullHouseTest
{//
static int count = 1;
static int [] cards ={1,2,3,4,5,6,7,8,9,10,11,12,13};
static int[] suit ={1,2,3,4};
static int[] suit2 ={2,3,4,1};
static int[] suit3 ={3,4,1,2};
public static void main(String[] args)
{
for(int k = 0; k< 12; k++)
{
for(int i = 0; i < 3; i++)
{
for (int t = 0; t <3; t++)
{
Card one = new Card(new Suit(suit[t]), new Pips(cards[k]));
Card two = new Card(new Suit(suit2[t]), new Pips(cards[k]));
Card three = new Card(new Suit(suit3[t]),new Pips(cards[k]));
for (int j =0; j < 12; j++)
{
Card four = new Card(new Suit(suit2[i]), new Pips(cards[j+1]));
Card five = new Card(new Suit(suit[i]), new Pips(cards[j+1]));
System.out.println("Hand:" + count + " | " + one + two + three + four + five);
count ++;
}
}
}
}
for(int i = 0; i < 3; i++)
{
for(int k = 0; k< 12; k++)
{
for(int s = 0; s<3; s++)
{
Card one = new Card(new Suit(suit[i]), new Pips(cards[k]));
Card two = new Card(new Suit(suit2[i]), new Pips(cards[k]));
for (int j =0; j < 12; j++)
{
Card three = new Card(new Suit(suit3[s]),new Pips(cards[j+1]));
Card four = new Card(new Suit(suit2[s]), new Pips(cards[j+1]));
Card five = new Card(new Suit(suit[s]), new Pips(cards[j+1]));
System.out.println("Hand:" + count + " | " + one + two + three + four + five);
count ++;
}
}
}
}
}
}
最佳答案
在继续之前,向您的代码添加一些注释。它将帮助您了解发生了什么,特别是当您使用单字符变量名称嵌套 4 层循环时。
接下来,分解问题:满堂彩的真正独特之处是什么?两个点数都是唯一的,但不能相同。 3 同种有 3 种不同的花色(或者只是缺少一种),而配对有 2 种不同的花色。
total_pips * (total_pips-1) * number_suits * (possible combinations of 2 suits ) = 3744
13 12 4 6
想想这个列表中您可能缺少什么。如果您有任何具体问题,只需编辑答案,我们就会立即解决:)
关于java - 如何用Java打印扑克中所有可能的 "full houses"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3868510/