A sorted version of Poker (making poker, licensing)

Source: Internet
Author: User


Import java.util.ArrayList;
Import java.util.Collections;
Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;

public class Practice01 {
public static void Main (string[] args) {
Pack poker, four colors
String[] colors={"?", "?", "?", "?"};
String[] nums={"3", "4", "5", "6", "7", "8", "9", "Ten", "J", "Q", "K", "A", "2"};
Define a map to install poker, the key is used to store 54 cards corresponding to the serial number, the value is the poker card
Map<integer,string> pokermap=new hashmap<> ();
54 Serial numbers to pack poker
List<integer> indexlist=new arraylist<> ();
int index=1;
It is used in the order of numbers, so the nums must be placed on the outer layer; If you sort by color, put colors in the outer layer.
for (String n:nums) {
for (String c:colors) {
Pokermap.put (index, c+n);
Indexlist.add (index);
index++;
}
}


Package Size King, after the previous step was completed, index=53
Pokermap.put (Index, "Xiao Wang");
Indexlist.add (index);
index++;
Pokermap.put (Index, "King");
Indexlist.add (index);
How to wash poker and assemble tools
Collections.shuffle (indexlist);
Licensing, using an array of numbers, numbered more than 51 of the three cards as cards
List<integer> user1=new arraylist<> ();
List<integer> user2=new arraylist<> ();
List<integer> user3=new arraylist<> ();
List<integer> dipai=new arraylist<> ();
Assign the player corresponding poker according to the remainder of the modulo 3
for (int i = 0; i < indexlist.size (); i++) {
if (I>=indexlist.size ()-3) {
Dipai.add (Indexlist.get (i));
}else if (i% 3==0) {
User1.add (Indexlist.get (i));
}else if (i% 3==1) {
User2.add (Indexlist.get (i));
}else if (i% 3==2) {
User3.add (Indexlist.get (i));
}
}
Sort, each player's poker is sorted separately
Collections.sort (user1);
Collections.sort (User2);
Collections.sort (USER3);
Collections.sort (Dipai);
Look at the card, the user's number as the map key to find the corresponding value
System.out.println ("Carter's Card:");
Printsee (Pokermap,user1);
System.out.println ("Galen's Cards:");
Printsee (POKERMAP,USER2);
System.out.println ("Sword Saint's Card:");
Printsee (POKERMAP,USER3);
System.out.println ("Hole Card:");
Printsee (Pokermap,dipai);
}

Write a method to see the cards and reduce the redundancy of the Code
private static void Printsee (Map<integer, string> Map, list<integer> user) {
Create a string container to stitch each player's poker
StringBuilder bul=new StringBuilder ("[");
for (int i=0;i<user.size (); i++) {
if (I<user.size ()-1) {
Bul.append (Map.get (User.get (i))). Append (",");
}else{
Bul.append (Map.get (User.get (i))). Append ("]");
}
}
Convert to String mode
System.out.println (Bul.tostring ());
}
}

A sorted version of Poker (making poker, licensing)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.