斗地主特殊牌型定义

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

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);
}

}

原文地址:https://www.cnblogs.com/scll/p/8366697.html

时间: 2024-10-09 17:47:49

斗地主特殊牌型定义的相关文章

斗地主基本牌型判断

/** * Created by xujw on 2017/10/16. * 斗地主 * 单副扑克 * 没有癞子玩法 * 牌对象为{grade:3,face:1} * grade 牌面点数(3-13:3-K, 14:A, 15:2, 16:小王 17:大王) * face 牌面花色(1:黑桃.2:红桃.3:梅花.4:方块) */ var CARD_TYPE_INVALID = -1; // 无效手牌 var CARD_TYPE_SINGLE = 1; // 单张 var CARD_TYPE_DO

斗地主牌型基本算法升级版本

斗地主牌型基本算法升级版本 好久没更新博客了,前段时间和朋友一起开了一个公司 做APP,最后失败了.现在又开始做棋牌游戏了,最近在看网狐的源码,发现里面斗地主的基本算法太强大了,现在想想我原来的算法简直是弱爆了,分享一下 希望能对你有一点点帮助.以下主要涉及到判断牌型,牌型大小比较2块,如果你想了解更多关于棋牌游戏的东西请访问我的 棋牌游戏专栏. 一.判断牌型 定义一个结构来表示每张相同牌的信息. //分析结构 structtagAnalyseResult { BYTE cbFourCount;

斗地主算法判断牌型

由于近年来网络棋牌游戏的火爆导致个各个地区的特色棋牌游戏开发进入红火时期,也有越来越多的团队个人开始研究棋牌游戏的开发,所以本文主旨在于各个开发人员之间的交流. 每个游戏都有属于自己的规则,当然斗地主也不例外,常斗地主的朋友可能知道在斗地主里面一共有13种牌型,你所出的牌必须符合13种的一种才能够出得了牌,这个就叫地主的规则.那么我们下面可以通过一个枚举结构来表示每一种的牌型,在这里我们把错误的牌型也当成是一种牌型. 那么在编程中我们该怎么来判断一组牌到底该属于哪一种牌型了?? ?这就是接下来我

棋牌游戏开发之地主算法判断牌型

棋牌游戏开发疑问交流 QQ:325131039(勿发广告) 棋牌游戏开发技术交流群: 490287966(勿发广告) ps: 本文转载自博主 wojiushi3344 每个游戏都有属于自己的规则,当然地主也不例外,常斗地主的朋友可能知道在斗地主里面一共有13种牌型,你所出的牌必须符合13种的一种才能够出得了牌,这个就叫地主的规则.那么我们下面可以通过一个枚举结构来表示每一种的牌型,在这里我们把错误的牌型也当成是一种牌型. [cpp] view plaincopy enum  CARD_TYPE

模拟斗地主洗牌、发牌(含有排序和不排序的)

不排序的: package cn.idcast5; import java.util.ArrayList; import java.util.Collections; //模拟斗地主洗牌发牌 //分析 //A 创建一个牌盒 //B 装牌 //C 洗牌 //D 发牌 //E 看牌 public class Shiyue31 { public static void main(String[] args) { // 创建一个牌盒 ArrayList<String> array = new Arra

斗地主洗牌发牌测试类

1 package com.hxl; 2 3 import java.util.ArrayList; 4 import java.util.Collections; 5 import java.util.HashMap; 6 import java.util.TreeSet; 7 8 /** 9 * 这是一个斗地主洗牌发牌的测试类 10 * 11 * @author Schiller_Hu 12 * @version v1.0 13 * @since 2018.2.20 14 * 15 */ 1

蓝桥杯历届试题:牌型种数

小明被劫持到X赌城,被迫与其他3人玩牌.一副扑克牌(去掉大小王牌,共52张),均匀发给4个人,每个人13张.这时,小明脑子里突然冒出一个问题:如果不考虑花色,只考虑点数,也不考虑自己得到的牌的先后顺序,自己手里能拿到的初始牌型组合一共有多少种呢? 请填写该整数,不要填写任何多余的内容或说明文字. 最容易想到的方法是dfs暴力枚举,但刚上手很容易写成这样,即标记每种牌出现次数枚举所有情况可能的牌的出现情况: 错误的解法: #include<cstring> #include<cstdio&

代码实现:模拟斗地主洗牌和发牌并对牌进行排序的代码实现

package com.loaderman.test; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.TreeSet; public class Test{ /** * * A:案例演示 * 模拟斗地主洗牌和发牌并对牌进行排序的代码实现 * * 分析: * 1,买一副扑克,其实就是自己创建一个集合对象,将扑克牌存储进去 * 2,洗牌 * 3,

2015 蓝桥杯:7.牌型种数

*/--> pre.src {background-color: Black; color: White;} pre.src {background-color: Black; color: White;} pre.src {background-color: Black; color: White;} pre.src {background-color: Black; color: White;} pre.src {background-color: Black; color: White;}