"Algorithm" poker licensing algorithm to achieve _JSP programming

Source: Internet
Author: User
First, set a number for each card in the card, the following algorithm to achieve the number of rules are as follows:
U hearts in descending order from small to large: 1-13
U square in order from small to large: 14-26
U spades in descending order from small to large: 27-39
U plum in order from small to large: 40-52
U Xiao Wang is 53, King is 54
The algorithm is implemented as follows:
You first initialize an array of 108 digits according to the number sequence above
Every time you randomly extract a number from the array, assign it to the array that holds the player's data.
The code that implements this feature is as follows:
Copy Code code as follows:

Import java.util.*;
/**
* Implementation of the licensing algorithm
* Requirements: 2 deck cards, that is 108, to 4 people, leaving 6 cards
*/
public class exec{
public static void Main (string[] args) {
An array of 108 cards stored
int[] Total = new int[108];
Store four players ' cards
int[][] player = new INT[4][25];
Stores the number of current remaining cards
int leftnum = 108;
Random numbers
int rannumber;
Random objects
Random Random = new Random ();

Initializing an array
for (int i = 0;i < total.length;i++) {
Total[i] = (i + 1)% 54;
Handling Size King number
if (total[i] = = 0) {
Total[i] = 54;
}

}

Circular Licensing
for (int i = 0;i < 25;i++) {
A license for everyone.
for (int j = 0;j < player.length;j++) {
Generate random subscript
Rannumber = Random.nextint (leftnum);
Licensing
Player[j][i] = Total[rannumber];
Move the cards that have been sent
Total[rannumber] = total[leftnum-1];
1 reduction in the number of licences to be licensed
leftnum--;
}
}

Loop out the cards in the player's hands
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 ();
}
Cards
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.