Collections.shuffle(poker); //使用默认随机源对指定列表进行置换。
//System.out.println(poker); //查看集合中的元素
//创建TreeSet集合,set根据其元素的自然顺序进行排序
TreeSet dong = new TreeSet();
TreeSet nan = new TreeSet();
TreeSet xi = new TreeSet();
TreeSet dipai = new TreeSet();
for (int i = 0;i < poker.size() ;i++ ) { //通过循环进行发牌
if (i >= poker.size()-3) { //当牌数等于小于3时就作为底牌
dipai.add(poker.get(i));
}else if (i % 3 == 0) { //当牌数模于等于0时给东家发牌
dong.add(poker.get(i));
}else if (i % 3 == 1) { //当牌数模于等于1时给南家发牌
nan.add(poker.get(i));
}else { //当牌数模于等于2时给西家发牌
xi.add(poker.get(i));
}
}
lookPoker(dong,map);
lookPoker(nan,map);
lookPoker(xi,map);
lookPoker(dipai,map);
}
public static void lookPoker(TreeSet<Integer> ts,HashMap<Integer,String> hm) {
for (Integer index : ts ) {
System.out.print(hm.get(index)+ " ");
}
System.out.println();
}
}
class Poker {
private final String[] STR1 = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
private final char[] COLOR = {3,4,5,6};
private final char[] GHOST = {1,2};
private final String STR2 = "";
public String[][] poker() {
String[] poker = new String[54];
String[][] test = new String[13][4];
for (int i = 0;i < STR1.length;i++ ) {
for (int j = 0;j < COLOR.length ;j++ ) {
test[i][j] = STR1[i] + COLOR[j];
}
}
/*
for (int i = 0;i < COLOR.length;i++ ) {
for (int j = 0;j < STR1.length ;j++ ) {
if (i == 0) {
test1[j] = COLOR[i] + STR1[j];
}else if (i == 1) {
test2[j] = COLOR[i] + STR1[j];
}else if (i == 2) {
test3[j] = COLOR[i] + STR1[j];
}else {
test4[j] = COLOR[i] + STR1[j];
}
}
}
for (int k = 0;k < 52 ;k++ ) {
if (k < 13) {
poker[k] = test1[k];
}else if (k>=13 && k <26) {
poker[k] = test2[k-13];
}else if (k>=26 && k <39) {
poker[k] = test3[k-26];
}else if (k>=39 && k <52) {
poker[k] = test4[k-39];
}
}
*/
poker[52] = GHOST[0] + STR2;
poker[53] = GHOST[1] + STR2;
return test;
}
public static void testPoker() {
String[] num = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
String[] color = {"黑","红","梅","方"};
ArrayList<String> poker = new ArrayList<>(); //创建数组集合
for (String s1 : num ) {
for (String s2 :color ) {
poker.add(s2.concat(s1)); //添加元素进入数组集合
}
}
}
public static void look() {
ArrayList<Integer> dong = new ArrayList<>();
ArrayList<Integer> xi = new ArrayList<>();
ArrayList<Integer> nan = new ArrayList<>();
ArrayList<Integer> dipan = new ArrayList<>();
for (int i = 0;i < poker.size() ;i++ ) { //通过循环进行发牌
if (i >= poker.size()-3) { //当牌数等于小于3时就作为底牌
dipan.add(poker.get(i));
}else if (i % 3 == 0) { //当牌数模于等于0时给东家发牌
dong.add(poker.get(i));
}else if (i % 3 == 1) { //当牌数模于等于1时给南家发牌
nan.add(poker.get(i));
}else { //当牌数模于等于2时给西家发牌
xi.add(poker.get(i));
}
}