1 /*2 simulation of the landlord's licensing function (after the card is issued hand on the hand is in order)3 Analysis:4 A: Create a HashMap collection5 B: Create a ArrayList collection6 C: Create two strings, one is suit, one is the number of cards (the card must have a box of cards)7 in order to facilitate later sorting, when creating these two strings, in order of size (size order in the bucket landlord)8 except for the king size9 D: Put these two strings into the HashMap collection (stitching together a suit + grade) and encode each card in the 0--52 and storeTen at the same time also to the ArrayList collection of memory encoding, the size of the code after the completion of the coding, One E: Shuffle A F: Licensing, in fact, hair is numbered, due to order, so create TreeSet collection, bucket landlord is 3 people and hole cards 3, corresponding to 4 sets, - A: Using the method of modulus to 3 people licensing, x%3=0;x%3=1;x%3=2 - B: 3 cards to start the G: Look at the card, because to use this function 3 times, so set a method: - A: return type: void - B: Parameter list: String name (player name); Treeset<integer> I (number of cards); Hashmap<integer,string> HM (CARD) - */ + - PackageZl_mapdemo; + A Importjava.util.ArrayList; at Importjava.util.Collections; - ImportJava.util.HashMap; - ImportJava.util.TreeSet; - - Public classPokerdemo { - Public Static voidMain (string[] args) { in - //Create a HashMap collection toHashmap<integer, string> poker =NewHashmap<integer, string>(); + - //Create a ArrayList collection theArraylist<integer> index =NewArraylist<integer>(); * $ //Create two strings, one is suit, one is the number of cards (the card must have a box of cards)Panax Notoginsengstring[] Colors = {"♦", "♣", "♥", "♠"}; - thestring[] numbers = {"3", "4", "5", "6", "7", "8", "9", "Ten", "J", "Q", +"K", "A", "2", }; A //Put these two strings into the HashMap collection (stitching together a suit + grade) and encode each card in the 0--52 and store the intCount = 0; + for(String number:numbers) { - for(String color:colors) { $ //Stitching $String PK =color.concat (number); - //store the code and cards in the HashMap - Poker.put (count, PK); the - //Save the code in the ArrayListWuyi Index.add (count); the -Count + +; Wu } - } About //encode and store the king size $Poker.put (Count, "Xiao Wang"); - Index.add (count); -Count + +; -Poker.put (Count, "King"); A Index.add (count); + the //Shuffle - collections.shuffle (index); $ the //Licensing , due to order, so create TreeSet collection, bucket landlord is 3 people and 3 cards, corresponding to 4 sets, theTreeset<integer> Player1 =NewTreeset<integer>(); theTreeset<integer> Player2 =NewTreeset<integer>(); theTreeset<integer> Player3 =NewTreeset<integer>(); -Treeset<integer> Dipai =NewTreeset<integer>(); in the //A: Using the method of modulus to 3 people licensing, x%3=0;x%3=1;x%3=2 B: Hole cards The remaining 3 the //at this point, 0-54 of the encoding is already stored in the ArrayList About for(intx = 0; x < index.size (); X + +){ the if(x >= index.size ()-3){ theDipai.add (Index.get (x));//give ArrayList the first 3 number of cards, not Dipai.add (x), so the hole is 0,1,2 the } + Else if(x% 3 = = 0){ - Player1.add (Index.get (x)); the }Bayi Else if(x% 3 = = 1){ the Player2.add (Index.get (x)); the } - Else if(x% 3 = = 2){ - Player3.add (Index.get (x)); the } the } the the //look at the cards -Lookpoker ("Player 1", player1, poker); theLookpoker ("Player 2", player2, poker); theLookpoker ("Player 3", Player3, poker); theLookpoker ("Hole cards", Dipai, poker);94 } the the //create a way to see a card, a: return type: void the //B: Parameter list: String name (player name); Treeset<integer> I (number of cards); Hashmap<integer,string> HM (CARD)98 Public Static voidLookpoker (String name,treeset<integer> i,hashmap<integer,string>HM) { About //First, the name . -System.out.print (name+ "'s Card is:");101 //Next is the card, traversing102 for(Integer key:i) {103 //The treeset value is the HashMap key, so you can get the corresponding value, that is, the card104String result =Hm.get (key); the //output See the Cards106System.out.print (result+ "");107 }108System.out.println ("");109 the }111 the}
Java 18-12 simulation bucket landlord shuffle, licensing, and sorting out the cards issued