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