斗地主特殊牌型定义

Posted scll

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了斗地主特殊牌型定义相关的知识,希望对你有一定的参考价值。

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

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

}

以上是关于斗地主特殊牌型定义的主要内容,如果未能解决你的问题,请参考以下文章

斗地主系列之牌型判断

十三水,十三张,斗地主,牛牛的牌型搜索思考

自己实现斗地主引擎

#30. 斗地主(T1-9)

斗地主算法的设计与实现--如何比较两手牌的大小

斗地主(初级)