Java poker licensing Algorithm Implementation and java poker Algorithm

Source: Internet
Author: User

Java poker licensing Algorithm Implementation and java poker Algorithm

Java poker licensing Algorithm Implementation Code: http://www.zuidaima.com/share/1550463274224640.htm

Two Methods: A. Poker licensing algorithm is A basic algorithm commonly used in card and board games, and also one of the basic algorithms that game developers need to be familiar. The following describes an implementation method of this algorithm. B. Store a pair of 52 cards in a Random order in the linked list of Random objects. A card is represented by A string containing A hyphen. For example, "1C" represents plum blossom A, "JD" represents square J, and so on. 4 cards are output from the stack, each with 13 cards.

First, set a number for each card in the playing card. The numbering rules implemented by the following algorithm are as follows: from small to large, the order of the 14-26 u peach is 27-39 u plum blossom. The order is 40-52 u King is 53, and the 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 the array that stores player data. The code for this function is as follows: package com. zuidaima; import Java. util. *;/*** licensing Algorithm Implementation * requirement: Send two sub-cards, that is, 108 cards, to four people, leave 6 cards * @ author www.zuidaima.com */public class Exec {public static void main (String [] args) {// store an array of 108 cards int [] total = new int [108]; // store the four player's card int [] [] player = new int [4] [25]; // store the number of remaining cards: int leftNum = 108; // Random number int ranNumber; // random object Random = new random (); // initialize the array for (int I = 0; I <total. length; I ++) {total [I] = (I + 1) % 54; // handle the size of the King number if (total [I] = 0) {total [I] = 54 ;}/// loop licensing for (int I = 0; I <25; I ++) {// authorize each user for (int j = 0; j <player. length; j ++) {// generate random subscript ranNumber = random. nextInt (leftNum); // licensed player [j] [I] = total [ranNumber]; // move the issued cards total [ranNumber] = total [leftNum-1]; // the number of licensed cards is reduced by 1 leftNum --;}} // cyclically outputs the card (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 () ;}// card (int I = 0; I <8; I ++) {System. out. print ("" + total [I]);} System. out. println ();}}

Java four-person poker licensing, teach Code better indent, in a concise point, the most important can

TIPS: Use a collection and use the shuffle method of the Collections class for licensing, which is more efficient and concise than writing by yourself.
 
In java programming poker games, random assignment is used when cards are played during shuffling. which method is used in the package?

Import java. util. HashMap;
Import java. util. Map;
Import java. util. Random;

/**
* Author: danagao
* Java licensing program,
* Do not include kingdom or kingdom
* The number of licensed persons can be set.
*/
Public class Pai {

HashMap <String, String> map = new HashMap <String, String> ();
Private static final String [] colors = {"Peach", "square", "Plum Blossom", "Black peach "};
Private static final String [] values = {"3", "4", "5", "6", "7", "8", "9 ", "10", "J", "Q", "K", "A", "2 "};

Private String [] newpai; private int len;
// Initialize 52 cards
Public Pai (){
Len = colors. length * values. length;
Newpai = new String [len];
Int k = 0;
For (int I = 0; I <colors. length; I ++ ){
For (int j = 0; j <values. length; j ++ ){
Newpai [k] = colors [I] + values [j];
K ++;
}
}
}

// Shuffling (card shuffling)
Private void getNums (){
Random r = new Random ();
Int I = r. nextInt (len );
String s;
If (I> = 0 &&! Map. containsKey (String. valueOf (I ))){
S = String. valueOf (I );
Map. put (s, newpai [I]);
} Else {
GetNums ();
}
}

// Licensing
Public void showResult (int p ){
For (int I = 0; I <len; I ++ ){
GetNums ();
}

Int l = len/p; // number of cards issued by each person
Int j = 1; // count
Int k = 0; // card count

For (Map. Entry <String, String> entry: map. entrySet ()){
If (k % l = 0 & j <= p ){
... The remaining full text>

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.