In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you the "Java how to achieve the landlord shuffle system", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to fight the landlord shuffle system" this article.
First, fight the landlord 1. Preface
I believe that every student who has seen the God of gamblers knows that there is a magical power similar to magic.
That's right! The amazing thing we're going to talk about today is: special powers (not?)
That is: fight the landlord's shuffle and deal system!
two。 Introduction
It is believed that many people will play the classic poker game "fighting landlords". This time, we will write a shuffling program in Java language, which requires the shuffling process to be completed in accordance with the rules of fighting landlords.
A deck of playing cards has a total of 54 cards, which are made up of designs and colors and numbers or letters. There are four colors: ♠, ♣, ♦ and ♥, which represent spades, clubs, diamonds and hearts respectively. ♛ stands for big king and ♝ for Xiao Wang.
A total of three players participate in the landlord game. first, they disrupt the order of the 54 cards, then each take turns to touch the cards, the remaining three cards are reserved as cards, and finally the three players' cards and three cards are printed on the console.
3. Graphic illustration
Prepare the cards
The following code is written in the main method!
1. Code example / / prepare Brand HashMap map=new HashMap (); ArrayList list=new ArrayList (); map.put (1, "King"); map.put (2, "Xiao Wang"); list.add (1); list.add (2) String [] numbers= {"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"}; String [] colors= {"♠", "♥", "♦", "♣"}; int index=3 For (String number: numbers) {for (String color: colors) {map.put (index,number + color); list.add (index); index++;}}
Note: here the code is written to import two packages:
Import java.util.HashMap
Import java.util.ArrayList
two。 Data presentation
Use System.out.println (map); and System.out.println (list); statements to show the data as follows:
{1 = King, 2 = Xiao Wang, 3 million 2 ♠, 4 million 2 ♥, 5 million 2 ♦, 6 million 2 ♣, 7 percent A ♠, 8 percent A ♥, 9 percent A ♦, 10 percent A ♣, 11 percent K ♠, 12 percent K ♥, 13 percent K ♦, 14 million K ♣, 15 million Q ♠, 16 million Q ♥, 17 million Q ♦, 18 million Q ♣, 19 million J ♠, 20 million J ♥, 21 million J ♦, 22 million J, 23 percent 10, 24 million 10, 25 percent 10, 2610, 279, 289, 299, 309, 31AL, 308 en29#, 338 en30#, 348 en31#, 357 en32#, 367 en33#, 377 en34#, 387 en35#, 396 en35#, 406 en35#, 6 en36# # 6, 4 en36# # 4 en36#, 435 44 ♥, 45 ♦, 46 ♣, 47 ♠, 48 ♥, 49 ♦, 50 ♣, 51 ♠, 52 ♥, 53 ♦, 54 ♣}
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54]
Sample shampoo and sorting code / / shuffle Collections.shuffle (list); / / shuffle ArrayList diPai=new ArrayList (); ArrayList player1=new ArrayList (); ArrayList player2=new ArrayList (); ArrayList player3=new ArrayList (); for (int I = 0; I
< list.size(); i++) { if(i>= 51) {diPai.add (list.get (I));} else if (I% 3 list.get (I)) {player1.add (list.get (I));} else if (I% 3) = 1) {player2.add (list.get (I));} else {player3.add (list.get (I)) }} / / sort Collections.sort (diPai); Collections.sort (player1); Collections.sort (player2); Collections.sort (player3)
Note: here the code is written to import a package:
Import java.util.Collections
Fourth, look at the cards (print to the console) 1. Code example / / look at cards look ("Chow Yun Fat", player1,map); look ("Andy Lau", player1,map); look ("Stephen Chow", player1,map); look ("cards", diPai,map)
Where, to create a look method:
Private static void look (String name, ArrayList list, HashMap map) {System.out.println (name+ ":"); for (Integer number: list) {System.out.print (map.get (number) + ");} System.out.println ();} 2. Show
Chow Yun-fat:
A ♣ K ♣ Q ♥ Q ♣ J ♠ J ♦ J ♣ 10 ♥ 10 ♦ 9 ♠ 6 ♠ 6 ♦ 5 ♦ 4 ♦ 3 ♠ 3 ♦
Andy Lau:
A ♣ K ♣ Q ♥ Q ♣ J ♠ J ♦ J ♣ 10 ♥ 10 ♦ 9 ♠ 6 ♠ 6 ♦ 5 ♦ 4 ♦ 3 ♠ 3 ♦
Stephen Chow:
A ♣ K ♣ Q ♥ Q ♣ J ♠ J ♦ J ♣ 10 ♥ 10 ♦ 9 ♠ 6 ♠ 6 ♦ 5 ♦ 4 ♦ 3 ♠ 3 ♦
Cards:
2 ♥ A ♠ 7 ♠
The above is all the contents of this article "how to realize the landlord reshuffle system in Java". Thank you for your reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.