模拟斗地主洗牌发牌
public class DouDiZhuDemo {
public static HashMap<Integer,String> map = new HashMap<Integer, String>();
public static void main(String[] args) {
String[] colors = {"♠","♥","♣","♦"};
String[] numbers = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
int index = 1;
for (String number : numbers) {
for (String color : colors) {
String card = color+number;
map.put(index++,card);
}
}
map.put(53,"小S");
map.put(54,"大S");
ArrayList<Integer> cardBox = new ArrayList<Integer>();
for (int i = 1; i < 55; i++) {
cardBox.add(i);
}
Collections.shuffle(cardBox);
ArrayList<Integer> p1 = new ArrayList<Integer>();
ArrayList<Integer> p2 = new ArrayList<Integer>();
ArrayList<Integer> p3 = new ArrayList<Integer>();
ArrayList<Integer> dp = new ArrayList<Integer>();
for (int i = 0; i < cardBox.size() - 3; i++) {
Integer card = cardBox.get(i);
if (i % 3 == 0) {
p1.add(card);
} else if (i % 3 == 1) {
p2.add(card);
} else{
p3.add(card);
}
}
dp.add(cardBox.get(51));
dp.add(cardBox.get(52));
dp.add(cardBox.get(53));
Collections.sort(p1);
Collections.sort(p2);
Collections.sort(p3);
Collections.sort(dp);
showCard(p1);
showCard(p2);
showCard(p3);
showCard(dp);
}
public static void showCard(ArrayList<Integer> ps){
for (Integer index : ps) {
String card = map.get(index);
System.out.print(card+" ");
}
System.out.println();
}
}