java - 如何用Java打印扑克中所有可能的 "full houses"?

标签 java poker

我想知道是否有人知道如何用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/

相关文章:

java - 数据库连接工厂 : error getting dbconnection jdbc/dotCMSPool

java - ms access 中查询值和目标字段的数量不相同

java - 我的 Java 扑克游戏中的每个玩家都使用自己的牌组

node.js - 通过 RTM 私信 Slack 用户

javascript - 在 JavaScript 中使用 mod 运算符进行环绕

Java 输入不工作(初学者)

java - 如何防止在java xml签名和证书中添加空格?

java - DigestUtils 和 MessageDigest 的 MD5 结果不同

php - 在 MySQL 中创建查找表的最快方法

algorithm - 一种高效的高效算法,可以找到 N 张牌的所有可能手牌? (OFC幻想世界)