[Algorithm] poker licensing Algorithm Implementation

Source: Internet
Author: User

First, set a number for each card in the playing card. Algorithm The numbering rules are as follows:
In ascending order: 1-13
From small to large, the U square is: 14-26
In ascending order: 27-39
U plum blossom is: 40-52 in ascending order
U King is 53, King is 54
The algorithm is implemented as follows:
U first initializes an array containing 108 numbers according to the above numbering rules
U randomly extracts a number from the array each time and assigns it to an array that stores player data.
To achieve this function Code As follows: Copy code The Code is as follows: Import java. util .*;
/**
* Licensing Algorithm Implementation
* Requirement: Send two sub-cards, that is, 108 cards, to four people and leave six cards
*/
Public class exec {
Public static void main (string [] ARGs ){
// Store an array of 108 cards
Int [] Total = new int [108];
// Store the cards of four players
Int [] [] Player = new int [4] [25];
// Store the number of remaining cards
Int leftnum = 108;
// Random Number
Int rannumber;
// Random object
Random random = new random ();

// Initialize the Array
For (INT I = 0; I <total. length; I ++ ){
Total [I] = (I + 1) % 54;
// Process the King number
If (total [I] = 0 ){
Total [I] = 54;
}

}

// Loop Licensing
For (INT I = 0; I <25; I ++ ){
// Authorize everyone
For (Int J = 0; j <player. length; j ++ ){
// Generate random subscript
Rannumber = random. nextint (leftnum );
// Licensing
Player [J] [I] = total [rannumber];
// Move the issued card
Total [rannumber] = total [leftnum-1];
// Decrease the number of licenses by 1
Leftnum --;
}
}

// Outputs the cards in the player's hands in a loop
For (INT I = 0; I <player. length; I ++ ){
For (Int J = 0; j <player [I]. length; j ++ ){
System. Out. Print ("" + player [I] [J]);
}
System. Out. println ();
}
// Base card
For (INT I = 0; I <8; I ++ ){
System. Out. Print ("" + total [I]);
}
System. Out. println ();
}
}

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.