按斗地主的模式,模拟随机发牌,实现步骤,
创建List集合将54张扑克放入集合中,将List 打乱后,
轮流给三个玩家发牌(每次发一张),并存入各自的集合中
最后三张作为一份底牌
输出 每个玩家的牌以及底牌
如:
底牌为:[小王, ♠6, ♦2]
玩家一:[♦8, ♣2, ♣4, ♦J, ♣10, ♦4, ♠8, ♣A, ♥3, ♠4, ♠9, ♠K, ♥J, ♣8, ♥Q, ♦K, ♠Q]
玩家二:[♥8, ♣Q, ♠A, ♥7, ♣6, ♥2, ♣9, ♠10, ♦3, ♦A, ♣5, ♥10, ♦ 7, ♠5, ♠3, ♥6, ♠2]
玩家三:[♣J, ♣3, ♥4, ♠J, ♥5, ♦10, ♦5, ♥K, ♥9, ♦9, ♣K, ♦Q, 大王, ♥A, ♠7, ♦6, ♣7]
package zuoe;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class dizhu {
public static void main(String[] args) {
ArrayList<String> p = new ArrayList<String>();
String[] s = new String[13];
String[] f = new String[] {"♦","♠","♥","♣"};
for(int i=2;i<=10;i++) {
s[i-2]=i+"";
}
s[11]="J";s[12]="Q";s[9]="K";s[10]="A";
System.out.println(Arrays.toString(f));
for(int d=0;d<f.length;d++) {
for(int x=0;x<s.length;x++) {
String h =f[d]+s[x];
p.add(h);
}
}
p.add("大王");
p.add("小王");
Collections.shuffle(p);
ArrayList<String> p1 = new ArrayList<String>();
ArrayList<String> p2 = new ArrayList<String>();
ArrayList<String> p3 = new ArrayList<String>();
ArrayList<String> p4 = new ArrayList<String>();
for(int y=0;y<17;y++) {
p1.add(p.get(y));
}
for(int y=17;y<34;y++) {
p2.add(p.get(y));
}for(int y=34;y<51;y++) {
p3.add(p.get(y));
}for(int y=51;y<54;y++) {
p4.add(p.get(y));
}
System.out.println("玩家一:"+p1);
System.out.println("玩家二:"+p2);
System.out.println("玩家三"+p3);
System.out.println("底牌:"+p4);
}
}