import java.util.*;标签:begin,String,斗地主,al,add,hm,模拟,TreeSet From: https://www.cnblogs.com/zhaoshengfu/p/18081123
public class Main {
public static void main(String[] args) {
HashMap<Integer, String> hm = new HashMap<Integer, String>();
ArrayList<Integer> al = new ArrayList<>();
//扑克牌(♦ ♣ ♠ ♥)
String[] color = {"♦", "♣", "♠", "♥"};
//牌号(2,3,4,5,6,7,8,9,10,J,Q,K,A)
String[] paihao = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
//大王小王
int begin = 0;
for (String p : paihao) {
for (String c : color) {
hm.put(begin, c + p);
al.add(begin);
begin++;
}
}
hm.put(begin, "大王");
al.add(begin);
begin++;
hm.put(begin, "小王");
al.add(begin);
Collections.shuffle(al);
//三个人
System.out.println(al);
TreeSet<Integer> zsf = new TreeSet<>();
TreeSet<Integer> jcs = new TreeSet<>();
TreeSet<Integer> zxt = new TreeSet<>();
TreeSet<Integer> dp = new TreeSet<>();
for (int i = 0; i < al.size(); i++) {
Integer i1 = al.get(i);
if (i >= al.size() - 3) {
dp.add(i1);
} else if (i % 3 == 0) {
zsf.add(i1);
} else if (i % 3 == 1) {
zxt.add(i1);
} else if (i % 3 == 2) {
jcs.add(i1);
}
}
show("zsf", zsf, hm);
show("jcs", jcs, hm);
show("zxt", zxt, hm);
show("dp", dp, hm);
}
public static void show(String demos, TreeSet<Integer> demots, HashMap<Integer, String> demohm) {
System.out.print(demos + "的牌是");
for (Integer i : demots) {
String s = demohm.get(i);
System.out.print(s + " ");
}
System.out.println();
}
}