Java implementation of Poker licensing algorithm

Source: Internet
Author: User

Poker licensing algorithm is a chess game commonly used in the basic algorithm, but also the game developers need to be familiar with one of the basic algorithms. Here is a way to implement this algorithm.

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:

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) {
//Storage 108-card array
int[ Total = new int[108];        
//Storage of four player cards
int[][] player = new int[4][25];
       Stores the number of current remaining cards
int leftnum = 108;
       Random number
int rannumber;
       Random Object
Random Random = new Random ();
           Initializes the array
for (int i = 0;i < total.length;i++) {
Total[i] = (i + 1)%;
           Handling size King number
if (total[i] = = 0) {
Total[i] =;

}
//Loop licensing
for (int i = 0;i < 25;i++) {
//licensing for everyone
for (Int J               = 0;j < player.length;j++) {
//Generate random subscript
Rannumber = Random.nextint (leftnum);
              Licensing
Player[j][i] = Total[rannumber];
              Move a card that has been issued
Total[rannumber] = total[leftnum-1];
Reduction in the number of licences available 1
leftnum--;

}
///loop output 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 ();        
}
//Hole
for (int i = 0;i < 8;i++) {
System.out.print ("" + total[i]);
}
System.out.println ();
}
}

Originated from: http://blog.csdn.net/Mailbomb/archive/2006/05/14/728176.aspx

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.