Two-dimensional array---simulated bucket landlord

Source: Internet
Author: User
Tags shuffle

 PackageCom.pb.demo;Importjava.util.Arrays;ImportJava.util.Random;/*** Poker Random licensing ♠♥♣♦ two-dimensional array implementation **/ Public classPuker { Public Static voidMain (string[] args) {//Defining Arraysstring[][] Puker =NewString[5][]; puker[0] =NewString[] {"♠a", "♠2", "♠3", "♠4", "♠5", "♠6", "♠7",                "♠8", "♠9", "♠10", "♠j", "♠q", "♠k" }; puker[1] =NewString[] {"♥a", "♥2", "♥3", "♥4", "♥5", "♥6", "♥7",                "♥8", "♥9", "♥10", "♥j", "♥q", "♥k" }; puker[2] =NewString[] {"♣a", "♣2", "♣3", "♣4", "♣5", "♣6", "♣7",                "♣8", "♣9", "♣10", "♣j", "♣q", "♣k" }; puker[3] =NewString[] {"♦a", "♦2", "♦3", "♦4", "♦5", "♦6", "♦7",                "♦8", "♦9", "♦10", "♦j", "♦q", "♦k" }; puker[4] =NewString[] {"King", "Xiao Wang" }; //define 3 players and cardsstring[] Player1 =NewString[17]; String[] Player2=NewString[17]; String[] Player3=NewString[17]; String[] Temp=NewString[3]; //Two-dimensional data shufflingRandom random =NewRandom (); intI1 = 0, i2 = 0, J1 = 0, J2 = 0;//define 4 variables to hold the subscript of the array//Shuffle 1000 times         for(inti = 0; i < 1000; i++) {            //Subscript i1 equals, random 0~4 integer One-dimensional subscriptI1 = Random.nextint (5);//between 0~4            if(I1 = = 4) {                //if a one-dimensional subscript is 4, then the 2-dimensional element has only 2 kings and a small king, and only 2 elementsJ1 = Random.nextint (2); } Else {                //if not 4, there are 13 cardsJ1 = Random.nextint (13);//0~12 total of 13 elements            }            //because the shortest array is 2 elements, so 2 times, if it is more than multipleI2 = Random.nextint (5); if(I2 = = 4) {J2= Random.nextint (2); } Else{J2= Random.nextint (13); }            //Start shufflingString tmp =Puker[i1][j1]; PUKER[I1][J1]= Puker[i2][j2];//Shuffle method, swap, scramble orderPUKER[I2][J2] =tmp; }        //Shuffle the cards afterSystem.out.println ("=========== Shuffle after the order ============");  for(inti = 0; i < puker.length; i++) {             for(intj = 0; J < Puker[i].length; J + +) {System.out.print (Puker[i][j]+ "  "); }        }        //Start Licensing         for(inti = 0; I < 54; i++) {            intp = i% 3;//define which player to send to            intK = I/3-1;//Define Round            if(I < 3) {                //three cards first .Temp[i] = puker[i/13][i% 13];//Fetch 3 cards from the front, and estimate the cards.}Else if(p = = 0) {Player1[k]= puker[i/13][i% 13]; } Else if(p = = 1) {Player2[k]= puker[i/13][i% 13]; } Else if(p = = 2) {Player3[k]= puker[i/13][i% 13]; }} System.out.println ("\n========== Licensing completed ============="); //Player OneSystem.out.println ("Player One" +arrays.tostring (player1)); //player twoSystem.out.println ("Player II" +arrays.tostring (player2)); //player threeSystem.out.println ("player three" +arrays.tostring (Player3)); //Hole CardsSystem.out.println ("Hole card" +arrays.tostring (temp)); }}

Two-dimensional array---simulated bucket landlord

Related Article

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.