import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Set;
import java.util.TreeMap;
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 (Integer in : al) {
if(in>=al.size()-3){
dipai.put(in, hm.get(in));
}
if(in%3==0){
ouy.put(in, hm.get(in));
}if(in%3==1){
gaojin.put(in, hm.get(in));
}if(in%3==2){
zhouxingchi.put(in, hm.get(in));
}
}
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);
}
}
|
|