Distribution Card Algorithm Implementation (Java)

Source: Internet
Author: User
Tags rounds

 


Import Java. util. * ;

/***/ /** 
* Card Distribution Algorithm Implementation
* Requirement: Send two sub-cards, that is, 108 cards, to four people and leave 8 cards
*/

Public   Class Paipai {

Int [] Pokerpai =   New   Int [ 54 ];
Int [] Allpai =   New   Int [ 108 ];
Int [] [] Playerpai =   New   Int [ 4 ] [ 25 ];
Int [] Dipai =   New   Int [ 8 ];
Int M_turn;

Random RDM =   New Random (system. currenttimemillis ());

Int Getrandom ( Int Size)
{
Return(RDM. nextint ()& 0x7fffffff)%Size;
}

Public Paipai ()
{
Initpai ();
Fapai ();
}

Public   Void Initpai ()
{
M_turn = 0 ;
Int Randomsite;
Int Temppai;
// Initial Value assignment-General Licensing form: 1. Issue by number of points 2. Number of cards and color
// The following is the number of points
For ( Int I = 0 ; I < Pokerpai. length; I ++ )
{
Pokerpai [I]=(I+1)%55;
}
// Give two deck cards
For ( Int I = 0 ; I < 2 ; I ++ )
For ( Int J = 0 ; J < Pokerpai. length; j ++ )
{
Allpai [m_turn]=Pokerpai [J];
M_turn++;
}
// Shuffling
For ( Int I = 0 ; I < Allpai. length; I ++ )
{< br> randomsite = getrandom (allpai. length);
temppai = allpai [randomsite];
allpai [randomsite] = allpai [I];
allpai [I] = temppai;

}
}


Public   Void Fapai ()
{
// Four-person rounds, 25 rounds in total
For ( Int I = 0 ; I < 25 ; I ++ )
For ( Int J = 0 ; J < Playerpai. length; j ++ )
{
M_turn--;
Playerpai [J] [I]=Allpai [m_turn];
}
// Reserve cards
For ( Int I = 0 ; I < Dipai. length; I ++ )
{
M_turn--;
Dipai [I]=Allpai [m_turn];

}
// Show four cards
For ( Int J = 0 ; J < Playerpai. length; j ++ )
Showpai (playerpai [J]);
// Display Base card
Showpai (dipai );
}

Public   Void Showpai ( Int [] M_pai)
{
System. Out. println ( " Showpai: Start. " );
For ( Int I = 0 ; I < M_pai.length; I ++ )
{
System. Out. Print (" "+M_pai [I]);
}
System. Out. println ();
System. Out. println ( " Showpai: end. " );
}

Public   Static   Void Main (string [] ARGs)
{
NewPaipai ();
}

}

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.