斗地主特殊牌型定义

小说:男人和女人的六个思考差异作者:卓邓更新时间:2019-03-25字数:84206

斗地主特殊牌型定义


游戏内一些牌型的定义,不做过多解释代码很详细,哪有不懂可以留言询问

public enum DDZPaiType {
HuoJian("火箭",30,"HuoJian"),
ZhaDan("炸弹",20,"ZhaDan"),
DanPai("单牌",10,"DanPai"),
DuiPai("对牌",10,"DuiPai"),
SanZhangPai("三张牌",10,"SanZhangPai"),
SanDaiYi("三带一",10,"SanDaiYi"),
SanDaiEr("三带二",10,"SanDaiEr"),
DanShun("单顺",10,"DanShun"),
ShuangShun("双顺",10,"ShuangShun"),
SanShun("三顺",10,"SanShun"),
FeiJiDaiDanPai("飞机带两单",10,"FeiJiDaiDanPai"),
FeiJiDaiDuiZi("飞机带两对",10,"FeiJiDaiDuiZi"),
SiDaiLiangDan("四带两单",10,"SiDaiLiangDan"),
SiDaiLiangDui("四带两对",10,"SiDaiLiangDui");
private String name;
private String nickName;
private int weight;
private int size;

DDZPaiType(String name, int weight,String nickName) {
this.name = name;
this.weight = weight;
this.nickName = nickName;
}

@Override
public String toString() {
return name;
}

public String getName() {
return name;
}

public int getWeight() {
return weight;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}

public String getNickName() {
return nickName;
}

public void setNickName(String nickName) {
this.nickName = nickName;
}

/**
* 获取牌的类型
*@param pokers
*@return
*@return
* 2018年1月27日
* @throws ZJHPokerException
*/
public static DDZPaiType getPaiType(DDZPai ddzPai) throws DDZPokerException{
List<DDZPoker> pokers = ddzPai.getDdzPokers();
Collections.sort(pokers);
//Collections.sort(pokers);
if(isHuoJian(pokers)){
ddzPai.setDdzPoker(pokers.get(0));
return HuoJian;
}
if(isZhaDan(pokers)){
ddzPai.setDdzPoker(pokers.get(0));
return ZhaDan;
}
if(isDanPai(pokers)){
ddzPai.setDdzPoker(pokers.get(0));
return DanPai;
}
if(isDuiZi(pokers)){
ddzPai.setDdzPoker(pokers.get(0));
return DuiPai;
}
if(isSanZhangPai(pokers)){
ddzPai.setDdzPoker(pokers.get(0));
return SanZhangPai;
}
if(isSanDaiYi(pokers,ddzPai)){
return SanDaiYi;
}
if(isSanDaiEr(pokers,ddzPai)){
return SanDaiEr;
}
if(isDanShun(pokers)){
ddzPai.setDdzPoker(pokers.get(0));
return DanShun;
}
if(isShuangShun(pokers)){
ddzPai.setDdzPoker(pokers.get(0));
return ShuangShun;
}
if(isSanShun(pokers)){
ddzPai.setDdzPoker(pokers.get(0));
return SanShun;
}
if(isFeiJiDaiLiangDan(pokers,ddzPai)){
return FeiJiDaiDanPai;
}
if(isFeiJiDaiLiangDui(pokers, ddzPai)){
return FeiJiDaiDuiZi;
}
if(isSiDaiLiangDan(pokers, ddzPai)){
return SiDaiLiangDan;
}
if(isSiDaiLiangDui(pokers, ddzPai)){
return SiDaiLiangDui;
}
return null;
}
//单顺
private static boolean isDanShun(List<DDZPoker> pokers) {
if(pokers.size()>=5){
if(pokers.get(0).getSize()>=15){
return false;
}
for (int i =0;i<pokers.size();i++) {
if(i<pokers.size()-1&&pokers.get(i).getSize()-pokers.get(i+1).getSize()!=1){
return false;
}
}

return true;
}
return false;
}
//四带两对
private static boolean isSiDaiLiangDui(List<DDZPoker> pokers,DDZPai ddzPai) {
if(pokers.size()==8){
int count1 = 0;
int count2 = 0;
DDZPoker ddzPoker = new DDZPoker();
for (int i =0;i<pokers.size();i++) {
int num = 0;
for (int j =0;j<pokers.size();j++) {
if(pokers.get(j).getPokerNum()==pokers.get(i).getPokerNum()){
num++;
}
}
if(num==4){
ddzPoker = pokers.get(i);
count1++;
}
if(num==2){
count2++;
}
}
if(count1==4 && count2==4){
ddzPai.setDdzPoker(ddzPoker);
return true;
}
}
return false;
}

//四带两单
private static boolean isSiDaiLiangDan(List<DDZPoker> pokers,DDZPai ddzPai) {
if(pokers.size()==6){
int count1 = 0;
DDZPoker ddzPoker = new DDZPoker();
for (int i =0;i<pokers.size();i++) {
int num = 0;
for (int j =0;j<pokers.size();j++) {
if(pokers.get(j).getPokerNum()==pokers.get(i).getPokerNum()){
num++;
}
}
if(num==4){
ddzPoker = pokers.get(i);
count1++;
}
}
if(count1==4){
ddzPai.setDdzPoker(ddzPoker);
return true;
}
}
return false;
}

//飞机带对子
private static boolean isFeiJiDaiLiangDui(List<DDZPoker> pokers,DDZPai ddzPai) {
if(pokers.size()>=10&&pokers.size()%5==0){
int count1 = 0;
int count2 = 0;
List<DDZPoker> ddzPokers = new ArrayList<DDZPoker>();
for (int i =0;i<pokers.size();i++) {
int num = 0;
for (int j =0;j<pokers.size();j++) {
if(pokers.get(j).getPokerNum()==pokers.get(i).getPokerNum()){
num++;
}
}
if(num==3){
count1++;
ddzPokers.add(pokers.get(i));
}
if(num==2){
count2++;
}
}
Collections.sort(ddzPokers);
if(count1==(pokers.size()/5)*3 && count2==(pokers.size()/5)*2
&&ddzPokers.get(0).getSize()<15 && 
ddzPokers.get(0).getSize()-ddzPokers.get(ddzPokers.size()-1).getSize()
== (pokers.size()/5)-1){
ddzPai.setDdzPoker(ddzPokers.get(0));
return true;
}
}
return false;
}

//飞机带单牌
private static boolean isFeiJiDaiLiangDan(List<DDZPoker> pokers,DDZPai ddzPai) {
if(pokers.size()>=8&&pokers.size()%4==0){
int count = 0;
List<DDZPoker> ddzPokers = new ArrayList<DDZPoker>();
for (int i =0;i<pokers.size();i++) {
int num = 0;
for (int j =0;j<pokers.size();j++) {
if(pokers.get(j).getPokerNum()==pokers.get(i).getPokerNum()){
num++;
}
}
if(num==3){
count++;
ddzPokers.add(pokers.get(i));
}
}
//四带两对的判定
if(ddzPokers.size() > 0 &&ddzPokers.get(0).getSize()<15){
if(count==(pokers.size()/4)*3){
Collections.sort(ddzPokers);
if(ddzPokers.get(0).getSize()-ddzPokers.get(ddzPokers.size()-1).getSize()==(pokers.size()/4-1)){
ddzPai.setDdzPoker(ddzPokers.get(0));
return true;
}else{
return false;
}
}
}
}
return false;
}

//三顺
private static boolean isSanShun(List<DDZPoker> pokers) {
if(pokers.size()%3==0&&pokers.size()>=6){
for (int i =0;i<pokers.size();i=i+3) {
if(pokers.get(i).getPokerNum()!=pokers.get(i+2).getPokerNum()){
return false;
}
}
if(pokers.get(0).getSize()>=15){
return false;
}else{
if(pokers.get(0).getSize()-pokers.get(pokers.size()-1).getSize()==(pokers.size()/3)-1){
return true;
}
}
}
return false;
}

//双顺
private static boolean isShuangShun(List<DDZPoker> pokers) {
if(pokers.size()%2==0&&pokers.size()>=6){
for (int i =0;i<pokers.size();i=i+2) {
if(pokers.get(i).getPokerNum()!=pokers.get(i+1).getPokerNum()){
return false;
}
}
if(pokers.get(0).getSize()>=15){
return false;
}else{
if(pokers.get(0).getSize()-pokers.get(pokers.size()-1).getSize()==(pokers.size()/2)-1){
return true;
}
}
}
return false;
}

//三带二
private static boolean isSanDaiEr(List<DDZPoker> pokers,DDZPai ddzPai) {
if(pokers.size()==5&&pokers.get(0).getPokerNum() ==pokers.get((pokers.size()-3)).getPokerNum()&&
pokers.get(3).getPokerNum() ==pokers.get((4)).getPokerNum()){
ddzPai.setDdzPoker(pokers.get(0));
return true;
}
if(pokers.size()==5&&pokers.get(2).getPokerNum() ==pokers.get((pokers.size()-1)).getPokerNum()&&
pokers.get(0).getPokerNum() ==pokers.get((1)).getPokerNum()){
ddzPai.setDdzPoker(pokers.get(2));
return true;
}
return false;
}

//三带一
private static boolean isSanDaiYi(List<DDZPoker> pokers,DDZPai ddzPai) {
if(pokers.size()==4&&pokers.get(0).getPokerNum() ==pokers.get((pokers.size()-2)).getPokerNum()){
ddzPai.setDdzPoker(pokers.get(0));
return true;
}
if(pokers.size()==4&&pokers.get(1).getPokerNum() ==pokers.get((pokers.size()-1)).getPokerNum()){
ddzPai.setDdzPoker(pokers.get(1));
return true;
}
return false;
}

//三张牌
private static boolean isSanZhangPai(List<DDZPoker> pokers) {
if(pokers.size()==3&&pokers.get(0).getPokerNum() ==pokers.get((pokers.size()-1)).getPokerNum() ){
return true;
}
return false;
}

//对子
private static boolean isDuiZi(List<DDZPoker> pokers) {
if(pokers.size()==2&&pokers.get(0).getPokerNum() ==pokers.get((pokers.size()-1)).getPokerNum() ){
return true;
}
return false;
}
//单牌
private static boolean isDanPai(List<DDZPoker> pokers) {
if(pokers.size()==1){
return true;
}
return false;
}
//炸弹
private static boolean isZhaDan(List<DDZPoker> pokers) {
if(pokers.size()==4&&pokers.get(0).getPokerNum() ==pokers.get((pokers.size()-1)).getPokerNum() ){
return true;
}
return false;
}
//王炸
private static boolean isHuoJian(List<DDZPoker> pokers) {
if(pokers.size()==2&&pokers.get(0).getPokerNum() ==PokerNum.P_DAWANG &&pokers.get(pokers.size() - 1).getPokerNum() ==PokerNum.P_XIAOWANG ){
return true;
}
return false;
}
//测试方法
public static void main(String [] args ){
List<DDZPoker> pokers = new ArrayList<DDZPoker>();
// pokers.add(new DDZPoker(new Poker(PokerColorType.FANG_KUAI, PokerNum.P_J)));
// pokers.add(new DDZPoker(new Poker(PokerColorType.FANG_KUAI, PokerNum.P_Q)));
// pokers.add(new DDZPoker(new Poker(PokerColorType.FANG_KUAI, PokerNum.P_10)));
// pokers.add(new DDZPoker(new Poker(PokerColorType.FANG_KUAI, PokerNum.P_A)));
// pokers.add(new DDZPoker(new Poker(PokerColorType.FANG_KUAI, PokerNum.P_K)));

// pokers.add(new DDZPoker(new Poker(PokerColorType.WANG, PokerNum.P_DAWANG)));
// pokers.add(new DDZPoker(new Poker(PokerColorType.WANG, PokerNum.P_XIAOWANG)));

pokers.add(new DDZPoker(new Poker(PokerColorType.MEI_HUA, PokerNum.P_4)));
pokers.add(new DDZPoker(new Poker(PokerColorType.MEI_HUA, PokerNum.P_5)));
pokers.add(new DDZPoker(new Poker(PokerColorType.FANG_KUAI, PokerNum.P_6)));
pokers.add(new DDZPoker(new Poker(PokerColorType.MEI_HUA, PokerNum.P_7)));
pokers.add(new DDZPoker(new Poker(PokerColorType.FANG_KUAI, PokerNum.P_8)));

Collections.sort(pokers);
DDZPai ddzPai = new DDZPai();
boolean flage = isDanShun(pokers);
System.out.println(ddzPai.toString());
for(int i = 0 ; i < pokers.size(); i++){
DDZPoker poker = pokers.get(i);
System.out.println(poker.getSize());

}
System.out.println(flage);
}

}

当前文章:http://0477auto.com/array/wlma8pkyxx.html

发布时间:2019-03-25 03:10:25

将男人挂在树枝上 爱得长久,因为懂得 董洁为何被“丑的人神共愤”的王大治搞定 电影《新步步惊心》是对电视版的升华吗? 不要怕青春期孩子 也不要让孩子怕你! 不离不弃,是对你最深情的告白 为什么在美国体育生比学霸更受欢迎? 恰似生活于巧克力 看《芈月传》,你需要先知道的历史知识 【情感问答】未来丈母娘反对我们交往

穿衣搭配的讲究 游完泳回到家还会溺死? 幼师对儿童心理成长的重要作用(详) 感冒药该不该“限购” 打造鼠目寸光的幸福女人 如何在爱情、婚姻生活中跨越“不踏实感” 罗李华:双鱼座2016年运势 为了我,婆婆要和老公断绝关系 经典原创禅诗:【禅.十字回文诗】 鸡肋般相亲男友,该不该分手? 年轻人,不要把时间浪费在股市上 恐惧的形成和消除 为什么说大部分人的勤奋是完全无效的 我该怎么面对一个人的孤独? 老婆怀上了二胎,已经作为奶爸的你要还是不要? 孩子为什么一定要上大学 为喜欢的事早起一个小时 秋季养生小常识 你相信这超凡脱俗的爱情吗?

编辑:文马龙

我要说两句: (0人参与)

发布