package com.ThreadPool;
import java.util.*;
public class Demo_Poker {
private static HashMap<String,Integer> map;
public static void main(String[] args) {
String[] color = new String[]{"黑桃","红桃","梅花","方块"};
String[] num = new String[]{"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
ArrayList<String> poker = new ArrayList<>();
map = new LinkedHashMap<>();
int i = 1;
for (String n : num) {
for (String color1 : color) {
String p = color1.concat(n);
poker.add(p);
map.put(p,i++);
}
}
poker.add("小王");
map.put("小王",i++);
poker.add("大王");
map.put("大王",i);
List<String> wo = new ArrayList<>();
List<String> zh = new ArrayList<>();
List<String> zyf = new ArrayList<>();
List<String> dp = new ArrayList<>();
Collections.shuffle(poker);
for (int i1 = 0; i1 < poker.size(); i1++) {
if (i1 > 50) {
dp.add(poker.get(i1));
} else if (i1 % 3 == 0) {
wo.add(poker.get(i1));
} else if (i1 % 3 == 1) {
zh.add(poker.get(i1));
} else if (i1 % 3 == 2) {
zyf.add(poker.get(i1));
}
}
sortPoker(wo);
sortPoker(zh);
sortPoker(zyf);
sortPoker(dp);
System.out.println(wo);
System.out.println(zh);
System.out.println(zyf);
System.out.println(dp);
}
public static void sortPoker(List list) {
TreeSet<String> set = new TreeSet<>(new Comparator<String>() {
public int compare(String o1,String o2) {
return map.get(o1) - map.get(o2);
}
});
set.addAll(list);
list.clear();
list.addAll(set);
}
}
运用集合框架模拟斗地主的发牌与洗牌
最新推荐文章于 2024-07-19 17:37:28 发布