import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;
public class DouDiZhuUpdate {
public static void main(String[] args) {
HashMap<Integer, String> hm = new HashMap<>();
//定义一副牌
ArrayList<String> arr = new ArrayList<>();
String[] colors = {"♤", "♡", "♢", "♧"};
String[] pokers = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
for (int i = 0; i < pokers.length; i++) {
String poker = pokers[i];
for (int j = 0; j < colors.length; j++) {
String color = colors[j];
arr.add(poker + color);
}
}
arr.add("大王");
arr.add("小王");
//给牌上一副索引
ArrayList<Integer> integers = new ArrayList<>();
for (int i = 0; i < arr.size(); i++) {
integers.add(i);
hm.put(i, arr.get(i));
}
//洗牌
Collections.shuffle(integers);
//定义三个玩家和底牌
TreeSet<Integer> player1 = new TreeSet<>();
TreeSet<Integer> player2 = new TreeSet<>();
TreeSet<Integer> player3 = new TreeSet<>();
TreeSet<Integer> dipai = new TreeSet<>();
//发牌
for (int i = 0; i < integers.size(); i++) {
Integer integer = integers.get(i);
if (i >= integers.size() - 3) {
dipai.add(integer);
} else if (i % 3 == 0) {
player1.add(integer);
} else if (i % 3 == 1) {
player2.add(integer);
} else if (i % 3 == 2) {
player3.add(integer);
}
}
//遍历牌
for (Integer integer : player1) {
String s = hm.get(integer);
System.out.print(s);
}
}
} |
|