Rules:
1.54 cards, with suit
2. Order disruption, one person a card in turn, one person 17, leave three card as a hole card
3. Look at the cards: by the size of the King 2A .... 43 Sequential Print
Example:
Packagedemo;Importjava.util.ArrayList;Importjava.util.Collections;ImportJava.util.HashMap; Public classDoudizhu { Public Static voidMain (string[] args) {//Create Map collection, key is number, value is cardHashmap<integer, string> pooker =NewHashmap<integer, string>(); //List Collection Storage number//set reason with list: You can call the Sort methodArraylist<integer> Pookernumber =NewArraylist<integer>(); //since 13 points are constant, the array is definedstring[] numbers = {"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3" }; //color constant, defining arraysstring[] colors = {"?", "?", "?", "?" }; //define integer variables, as keys, 0 and 1 are left to the size of the King intindex = 2; //iterate through the array and deposit into the map collection for(String number:numbers) { for(String color:colors) {pooker.put (index, Color+Number ); Pookernumber.add (index); Index++; } } //Separate storage size KingPooker.put (0, "King")); Pookernumber.add (0); Pooker.put (1, "Xiao Wang"); Pookernumber.add (1); //Shuffle, the number of cards upsetcollections.shuffle (Pookernumber); // Licensing//three players and cardsArraylist<integer> Player1 =NewArraylist<integer>(); ArrayList<Integer> Player2 =NewArraylist<integer>(); ArrayList<Integer> Player3 =NewArraylist<integer>(); ArrayList<Integer> Dipai =NewArraylist<integer>(); //three players per card, in turn for(inti = 0; I < pookernumber.size (); i++) { //do the cards first . if(I < 3) {Dipai.add (Pookernumber.get (i)); } //give each player a card, in turn Else if(i% 3 = = 0) {Player1.add (Pookernumber.get (i)); } Else if(i% 3 = = 1) {Player2.add (Pookernumber.get (i)); } Else if(i% 3 = = 2) {Player3.add (Pookernumber.get (i)); } } //sort cards in the hands of playersCollections.sort (Player1); Collections.sort (PLAYER2); Collections.sort (PLAYER3); //look at the card, find the value according to the keyLook ("Player 1", Player1, Pooker); Look ("Player 2", Player2, Pooker); Look ("Player 3", Player3, Pooker); Look (Cards, Dipai, Pooker); } Public Static voidLook (String name, arraylist<integer> player, Hashmap<integer, string>Pooker) {System.out.print (name+ ":"); for(Integer key:player) {String value=Pooker.get (key); System.out.print (" " +value); } System.out.println (); }}
Effect:
Each time the results are inconsistent:
Interested friends can continue to develop according to the rules of the landlord, make a simple game of landlords
Java Learning Note 34 (Set Frame VIII: Comprehensive case: Simulation of the Landlord's shuffle Licensing)