1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| public class Poker { public static void main(String[] args) {
HashMap<Integer, String> pokerMap = new HashMap<Integer, String>(); ArrayList<String> colors = new ArrayList<String>(); ArrayList<String> numbers = new ArrayList<String>(); Collections.addAll(colors, "♦", "♣", "♥", "♠"); Collections.addAll(numbers, "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"); int count = 1; pokerMap.put(count++, "大王"); pokerMap.put(count++, "小王"); for (String number : numbers) { for (String color : colors) { String card = color + number; pokerMap.put(count++, card); } }
Set<Integer> numberSet = pokerMap.keySet(); ArrayList<Integer> numberList = new ArrayList<Integer>(); numberList.addAll(numberSet); Collections.shuffle(numberList); ArrayList<Integer> noP1 = new ArrayList<Integer>(); ArrayList<Integer> noP2 = new ArrayList<Integer>(); ArrayList<Integer> noP3 = new ArrayList<Integer>(); ArrayList<Integer> dipaiNo = new ArrayList<Integer>(); for (int i = 0; i < numberList.size(); i++) { Integer no = numberList.get(i); if (i >= 51) { dipaiNo.add(no); } else { if (i % 3 == 0) { noP1.add(no); } else if (i % 3 == 1) { noP2.add(no); } else { noP3.add(no); } } } Collections.sort(noP1); Collections.sort(noP2); Collections.sort(noP3); Collections.sort(dipaiNo); ArrayList<String> player1 = new ArrayList<String>(); ArrayList<String> player2 = new ArrayList<String>(); ArrayList<String> player3 = new ArrayList<String>(); ArrayList<String> dipai = new ArrayList<String>(); for (Integer i : noP1) { String card = pokerMap.get(i); player1.add(card); } for (Integer i : noP2) { String card = pokerMap.get(i); player2.add(card); } for (Integer i : noP3) { String card = pokerMap.get(i); player3.add(card); } for (Integer i : dipaiNo) { String card = pokerMap.get(i); dipai.add(card); } System.out.println("令狐冲:"+player1); System.out.println("石破天:"+player2); System.out.println("鸠摩智:"+player3); System.out.println("底牌:"+dipai); } }
|