ShowHand
实验目的:
- Github基本源代码控制方法
- 利用Junit4进行程序模块的测试,回归测试
- 编码规范的考量
- C/Java等基本程序设计语言的运用。
实验过程:
import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; import java.util.Scanner; import java.util.TreeSet;
public class ShowHand { private List<String> pukeList = new ArrayList<String>(); private Map<String,TreeSet<String>> map = new HashMap<String,TreeSet<String>>(); private Map<String,Double> sorceMap = new HashMap<String,Double>(); private boolean flag = true; //1、创建扑克牌 private void createPuke(){ String[] point = {"7","8","9","10","J","Q","K"}; String[] type = {"黑桃","红桃","梅花","方块"}; for(int i=0;i<type.length;i++){ for(int j=0;j<point.length;j++){ this.pukeList.add(type[i]+point[j]); } } } //2、对扑克牌进行洗牌 private void sortedPuke(){ Random rand = new Random(); for(int i=0;i<100;i++){ int index1 = rand.nextInt(this.pukeList.size()); int index2 = rand.nextInt(this.pukeList.size()); String temp = this.pukeList.get(index1); this.pukeList.set(index1, this.pukeList.get(index2)); this.pukeList.set(index2, temp); } System.out.println(this.pukeList); } //3、创建参加游戏的人 private void createPlayer(){ System.out.println("请输入参与游戏的玩家的名称,中间使用空格隔开:"); Scanner scan = new Scanner(System.in); String players = scan.nextLine(); String[] data = players.split(" "); if(data.length<2 || data.length>5){ System.out.println("参与游戏的玩家人数不符合要求,程序终止执行!"); flag = false; return; } Comparator<String> comp = new Comparator<String>() { @Override public int compare(String str1, String str2) { int point1 = getPoint(str1.substring(2)); int point2 = getPoint(str2.substring(2)); if(point1>point2){ return 1; }else if(point1<point2){ return -1; }else{ int type1 = getType(str1.substring(0, 2)); int type2 = getType(str2.substring(0, 2)); if(type1>type2){ return 1; }else{ return -1; } } } }; for(int i=0;i<data.length;i++){ map.put(data[i], new TreeSet<String>(comp)); } } private int getPoint(String point){ if("J".equals(point)){ return 11; }else if("Q".equals(point)){ return 12; }else if("K".equals(point)){ return 13; }else{ return Integer.parseInt(point); } } private int getType(String type){ if("黑桃".equals(type)){ return 1; }else if("红桃".equals(type)){ return 2; }else if("梅花".equals(type)){ return 3; }else{ return 4; } } //4、给玩家发牌 private void showPuke(){ for(int i=0;i<5;i++){ for(String key : map.keySet()){ String puke = this.pukeList.remove(0); map.get(key).add(puke); } } } //5、计算玩家的分数 private void getSorce(){ String winner = null; double winnerSorce = 0; for(String key : map.keySet()){ TreeSet<String> set = map.get(key); String[] pukes = set.toArray(new String[set.size()]); double sorce = this.sorce(set); this.sorceMap.put(key, sorce); System.out.println("玩家"+key+"的牌为:"+this.map.get(key)+"分值为:"+sorce); for(String key1:sorceMap.keySet()){ if(sorceMap.get(key1)>winnerSorce){ winnerSorce=sorceMap.get(key1); winner=key1; } } } System.out.println("获胜者是: "+winner+" 分数是:"+winnerSorce); } private double sorce(TreeSet<String> set){ double sorce = 0; boolean flag = true; String[] pukes = set.toArray(new String[set.size()]); for(int i=0;i<pukes.length-1;i++){ int point1 = this.getPoint(pukes[i].substring(2)); int point2 = this.getPoint(pukes[i+1].substring(2)); if(point1-point2!=-1){ flag = false; break; } } if(flag){ sorce = 5.0 + this.getPoint(pukes[4].substring(2)) * 0.01; return sorce; } int point1 = this.getPoint(pukes[0].substring(2)); int point2 = this.getPoint(pukes[1].substring(2)); int point3 = this.getPoint(pukes[2].substring(2)); int point4 = this.getPoint(pukes[3].substring(2)); int point5 = this.getPoint(pukes[4].substring(2)); if (point1==point4||point2==point5) { sorce=4.0+point4*0.01; return sorce; } if (point1==point3||point2==point4||point3==point5) { sorce=3.0+point3*0.01; return sorce; } if (point1==point2&&point3==point4) { sorce=2.0+point3*0.01+point1*0.0001+point5*0.000001; return sorce; } if (point2==point3&&point4==point5) { sorce=2.0+point5*0.01+point2*0.0001+point1*0.000001; return sorce; } if (point1==point2&&point4==point5) { sorce=2.0+point5*0.01+point1*0.0001+point3*0.000001; return sorce; } if (point1==point2) { sorce=1.0+point1*0.01+point5*0.0001+point4*0.000001+point3*0.00000001; return sorce; } if (point2==point3) { sorce=1.0+point2*0.01+point5*0.0001+point4*0.000001+point1*0.00000001; return sorce; } if (point3==point4) { sorce=1.0+point3*0.01+point5*0.0001+point2*0.000001+point1*0.00000001; return sorce; } if (point4==point5) { sorce=1.0+point4*0.01+point3*0.0001+point2*0.000001+point1*0.00000001; return sorce; } return sorce=point5*0.01+point4*0.0001+point3*0.000001+point2*0.000001+point1*0.00000001; } public void init(){ this.createPuke(); this.sortedPuke(); this.createPlayer(); if(flag){ this.showPuke(); this.getSorce(); } } public static void main(String[] args) { new ShowHand().init(); } }
GitHub地址:https://github.com/y415562509/Text/blob/master/ShowHand
实验结果:
心得体会:
我感觉我收获颇丰23333333
ShowHand的更多相关文章
- Java中List、Collections实现梭哈游戏
package ch8; import java.util.*; /** * Created by Jiqing on 2016/11/27. */ public class ShowHand { / ...
- 使用ML.NET实现德州扑克牌型分类器
导读:ML.NET系列文章 本文将基于ML.NET v0.2预览版,重点介绍提取特征的思路和方法,实现德州扑克牌型分类器. 先介绍一下德州扑克的基本牌型,一手完整的牌共有五张扑克,10种牌型分别是: ...
- 软件工程实践作业2 --梭哈游戏(java) 实践报告
一,题目简介: 1.创建一副扑克牌 7------k 加入到集合对象中2.对扑克牌洗牌3.定义参与游戏的玩家的人,通过键盘输入,限定人数2-54.人数符合要求继续执行,不符合退出5.对玩家发牌,每个人 ...
- Java 集合补充
集合大致可以分List,Set,Queue,Map四种体系. 集合和数组不一样,数组元素可以是基本类型的值,也可以是对象(的引用变量),集合里只能保存对象(的引用变量). 访问:如果访问List集合中 ...
- 第八章.Java集合
Java集合类是一种特别有用的工具类,可用于存储数量不等的对象.Java集合大致可分为Set.List.Queue和Map四种体系 Set代表无序.不可重复的集合 List代表有序.重复的集合 Map ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 对博弈活动中蕴含的信息论原理的讨论,以及从熵角度看不同词素抽象方式在WEBSHELL文本检测中的效果区别
1. 从赛马说起 0x1:赛马问题场景介绍 假设在一场赛马中有m匹马参赛,令第i匹参赛马获胜的概率为pi,如果第i匹马获胜,那么机会收益为oi比1,即在第i匹马上每投资一美元,如果赢了,会得到oi美元 ...
随机推荐
- Kafka设计原理
一.入门 1.简介 Apache Kafka是一个分布式消息发布订阅系统.它最初由LinkedIn公司基于独特的设计实现为一个分布式的提交日志系统( a distributed commit log) ...
- 使用requests模块post payload请求
import json import requests import datetime postUrl = 'https://sellercentral.amazon.com/fba/profitab ...
- Reflection 反射
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/A__17/article/details/30571923 1.概念:所谓的反射.能够理解为在运行时 ...
- Color the ball HDU - 1556 (非线段树做法)
题意:在1到n的气球中,在不同的区域中涂颜色,问每个气球涂几次. #include<cstdio>int num[100010];int main(){ int n, x, y;; whi ...
- 解惑 ["1", "2", "3"].map(parseInt) 为何返回[1,NaN,NaN]
javascript中的parseInt与map函数都是常用的函数,可是 ["1", "2", "3"].map(parseInt) 为何返 ...
- M100 (1) 运行
软件环境设置指南 本指南详细介绍了使用Onboard SDK所需的软件环境. https://developer.dji.com/onboard-sdk/documentation/developme ...
- windows下手动安装 Apache+php+mysql
PHP 为什么先说php,因为apache的配置要写入php的一些路径 http://php.net/downloads.php 选择windows donwload 选择Thread Safe的版 ...
- 为什么express中打开服务端只用listen即可
为什么express中打开服务端只用listen即可:http.createServer(app).listen()与app.listen()的区别 写法一: var app = r ...
- Java实现对象的序列化
什么是对象的序列化? 序列化:把对象转化成字节序列的过程就是对象的序列化:反序列化:把字节序列转化成对象的过程就是对象的反序列化.单看概念比较抽象,但是看代码就会明白. 对象序列化的用途 1.Java ...
- 洛谷 P1396 营救
题目链接 https://www.luogu.org/problemnew/show/P1396 题目描述 “咚咚咚……”“查水表!”原来是查水表来了,现在哪里找这么热心上门的查表员啊!小明感动的热泪 ...