public class pukepai {
/**
* 模拟斗地主洗牌和发牌并对牌进行排序的代码实现
*/
public static void main(String[] args) {
String[] color ={"黑桃","梅花","方块","红桃"};
String[] pai = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
HashMap<Integer,String> hm = new HashMap<>();
int i = 0;
for (String st : pai) {
for (String str : color) {
hm.put(i++, str.concat(st)) ;
}
}
hm.put(52, "小王");
hm.put(53, "大王");
System.out.println(hm);
TreeMap<Integer,String> ouy = new TreeMap<>();
TreeMap<Integer,String> gaojin = new TreeMap<>();
TreeMap<Integer,String> zhouxingchi = new TreeMap<>();
TreeMap<Integer,String> dipai = new TreeMap<>();
ArrayList <Integer> al = new ArrayList<>();
Set<Integer> keySet = hm.keySet();
for (Integer integer : keySet) {
al.add(integer);
}
System.out.println(al);
System.out.println("-----------");
Collections.shuffle(al);
System.out.println(al);
for (int i1 =0;i1<al.size();i1++) {
if(i1>=al.size()-3){
dipai.put(i1,hm.get(al.get(i1)));
}
if(i1%3==0){
ouy.put(i1,hm.get(al.get(i1)));
}if(i1%3==1){
gaojin.put(i1, hm.get(al.get(i1)));
}else{
zhouxingchi.put(i1, hm.get(al.get(i1)));
}
}
System.out.println(ouy);
System.out.println("-----");
System.out.println(gaojin);
System.out.println("-----");
System.out.println(zhouxingchi);
System.out.println("-----");
System.out.println(dipai);
}
}
|
|