Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize the game of fighting landlords with ArrayList+Collections

Shulou Source: shulou.com Published: 2022-06-01 11:33:11 10月01日 Update

This article mainly explains "how to realize the game of fighting landlords in ArrayList+Collections". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "how to fight landlords in ArrayList+Collections"!

A deck of poker has 54 cards: big and small Wang + 4x13. Next, let's simulate the dealing process of fighting landlords.

First of all, we need to buy cards, the newly bought cards are placed in order, so the next step is to shuffle, and finally is to deal, but when dealing, we should pay attention to leave three cards at the end.

The main classes used are ArrayList: to store cards and Collections to shuffle cards.

Import java.util.ArrayList

Import java.util.Collections

/ *

* A total of 54 cards are issued by simulated landlords.

* buying cards

* shuffle

* Licensing

*

, /

Public class DouDIZhuDemo {

Public static void main (String [] args) {

/ / pattern array

String [] arr = {"spades", "hearts", "clubs", "square"}

String [] arr2 = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}

/ / buying cards

ArrayList box = new ArrayList ()

/ / add cards

/ / get design and color

For (int I = 0; I < arr.length; iTunes +)

/ / get the value

For (int j = 0; j < arr2.length; jacks +)

Box.add (ARR [I] + arr2 [j])

/ / Big and small King

Box.add ("King")

Box.add (Xiao Wang)

/ / shuffle

Collections.shuffle (box)

/ / deal three cards to the landlord, leaving 51 cards, 17 cards each

/ / three players who play cards

ArrayList Qibao = new ArrayList ()

ArrayList Babao = new ArrayList ()

ArrayList Nine Treasures = new ArrayList ()

For (int I = 0; I < box.size ()-3; iTunes +) {

If (I% 3 percent 0)

Add (box.get (I))

Else if (I% 3 percent 1)

Add (box.get (I))

Else if (I% 3 percent 2)

Add (box.get (I))

}

System.out.println ("Qibao:" + Qibao)

System.out.println ("Babao:" + Babao)

System.out.println ("Jiubao:" + Jiubao)

/ / bottom card

For (int i=box.size ()-3TX I

Tags: Fighting landlords eight treasures nine treasures seven treasures cards content size poker design and color learning practical deeper next three interests landlords kings practicality practicality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS NVidia Xiaomi vpn Huawei