斗地主发牌算法
2016-08-11 22:15
246 查看
写着玩
package poker; import java.util.Random; /** * Created by 小林未郁 on 2016/8/11. */ public class dealCards { static String[] flowerColor = {"黑桃", "红桃", "方片", "梅花"}; static String[] number = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}; static String[] cards = new String[54]; public static void main(String[] args) { new dealCards_fuck(flowerColor, number, cards); new Upset(cards); new DistributeCards(cards); } } //排序,像新牌一样 class dealCards_fuck { dealCards_fuck(String[] flowerColor, String[] number, String[] cards) { cards[52] = "小王"; cards[53] = "大王"; for (int i = 0; i < 52; i++) { cards[i] = flowerColor[i % 4] + number[i / 4]; } } } //洗牌 class Upset { Upset(String[] fuck) { for (int t = 0; t < 50; t++) { Random rand = new Random(); for (int i = 0; i < fuck.length; i++) { int bitch = 0; for (; ; ) { bitch = i + rand.nextInt(54 - i); break; } String temp = fuck[bitch]; fuck[bitch] = fuck[i]; fuck[i] = temp; } } } } //发牌 class DistributeCards { String[] p1 = new String[17]; String[] p2 = new String[17]; String[] p3 = new String[17]; DistributeCards(String[] fuck) { for (int i = 0; i < 17; i++) { p1[i] = fuck[i]; } for (int i = 17, t = 0; i < 34; i++, t++) { p2[t] = fuck[i]; } for (int i = 34, t = 0; i < 51; i++, t++) { p3[t] = fuck[i]; } System.out.println("玩家1:"); new show(p1); System.out.println(); System.out.println("玩家2:"); new show(p2); System.out.println(); System.out.println("玩家3:"); new show(p3); System.out.println(); System.out.println("三张底牌"); for (int i = 51; i < 54; i++) { System.out.println(fuck[i]); } } } //打印牌 class show { show(String[] fuck) { for (int i = 0; i < fuck.length; i++) { System.out.println(fuck[i]); } } }
相关文章推荐
- LNMP(linux+nginx+mysql+php)环境搭建_1
- 不会马拉车的煞笔要学pam
- 中介者模式
- 华为在线训练(6)
- springMVC注解方式返回json
- 【OVS2.5.0源码分析】ofpbuf数据结构分析
- Sqli-labs less 33
- 编写的一个矩阵类(C++描述)
- MAC OSX mpi安装
- JAVA中的并发工具类(三)---CountDownLatch
- Sqli-labs less 34
- 苹果电脑的快捷键介绍
- Python模块之ConfigParser - 读写配置文件
- ef操作类
- eclipse配置Android环境
- thinking in java test4.8练习(8)(9)(10)吸血鬼数字
- Cookie/Session机制详解
- java基础之常用类的方法
- ACM文献citation批量下载
- Sqli-labs less 35