判断碰牌

master
fy 2026-01-02 02:19:59 +08:00
parent c076e9f149
commit 2ba7c82c92
3 changed files with 230 additions and 99 deletions

View File

@ -467,15 +467,31 @@ public class HuNanChangSha {
if (type1 == 2) { if (type1 == 2) {
boolean isChow = changShaSuanFaTest.isAllSameSuit1(changShaCardInhand);
if (isChow) {
params.putString("session", session + "," + token);
params.putInt("qi", 1);
params.putInt("id", 0);
} else {
List<Integer> shifoutingpai = TinHuChi.shifoutingpai(changShaCardInhand); List<Integer> shifoutingpai = TinHuChi.shifoutingpai(changShaCardInhand);
//目前手牌没有听牌 //目前手牌没有听牌
if (shifoutingpai.size() == 0) { if (shifoutingpai.size() == 0) {
//判断是否满足7对
int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);
if (pisCardsCount >= 5) {
params.putString("session", session + "," + token);
params.putInt("qi", 1);
params.putInt("id", 0);
} else {
List<Integer> temphand = new ArrayList<>(); List<Integer> temphand = new ArrayList<>();
temphand.addAll(changShaCardInhand); temphand.addAll(changShaCardInhand);
temphand.add(opcard); temphand.add(opcard);
Util.removeCard(temphand, opcard, 3); Util.removeCard(temphand, opcard, 3);
List<Integer> checktingpai1 = TinHuChi.checktingpai(temphand); List<Integer> checktingpai1 = TinHuChi.checktingpai(temphand);
System.out.println("checktingpai1 碰牌" + checktingpai1); System.out.println("checktingpai1 碰牌" + checktingpai1);
//碰完牌后打牌后可以听牌
if (checktingpai1.size() > 0) { if (checktingpai1.size() > 0) {
System.out.println("===============进入听胡碰牌================== ++++ "); System.out.println("===============进入听胡碰牌================== ++++ ");
params.putString("session", session + "," + token); params.putString("session", session + "," + token);
@ -487,11 +503,66 @@ public class HuNanChangSha {
pongGroup.add(opcard); pongGroup.add(opcard);
Util.removeCard(changShaCardInhand, opcard, 2); Util.removeCard(changShaCardInhand, opcard, 2);
} else { } else {
//碰之前的map
Map<String, Object> map = new HashMap<>();
//碰之后的map
Map<String, Object> map2 = new HashMap<>();
//先判断碰之前还需要几手牌,以及孤章
// int jiangnum = checkduijiang(changShaCardInhand);
List<Integer> tmpChangSch = new ArrayList<>();
tmpChangSch.addAll(changShaCardInhand);
tmpChangSch.add(opcard);
ChangshaWinSplitCard.checkNormalHu(tmpChangSch, map);
//碰之后
List<Integer> pengtemphand = new ArrayList<>();
pengtemphand.addAll(tmpChangSch);
Util.removeCard(pengtemphand, opcard, 3);
ChangshaWinSplitCard.checkNormalHu(pengtemphand, map2);
//判断两个map是否找到更优
System.out.println("碰之前 map1:" + Integer.parseInt(map.get("remainingMelds").toString()));
System.out.println("碰之后 map2:" + Integer.parseInt(map2.get("remainingMelds").toString()));
//碰之后的手数小于碰之前的手数,可以碰
if (Integer.parseInt(map2.get("remainingMelds").toString()) < Integer.parseInt(map.get("remainingMelds").toString())) {
System.out.println("===============碰之后的手数小于碰之前的手数,可以碰 决定碰牌================== ++++ ");
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", id1);
pongGroup.add(opcard);
pongGroup.add(opcard);
pongGroup.add(opcard);
Util.removeCard(changShaCardInhand, opcard, 2);
} else if (Integer.parseInt(map2.get("remainingMelds").toString()) == Integer.parseInt(map.get("remainingMelds").toString())) { //碰完后和碰之前手数相等,需要判断孤章数量
//碰之后的数量
int size2 = ((List<Integer>) map2.get("cardResiue")).size();
System.out.println("碰之后的孤章数量 size" + size2);
int size1 = ((List<Integer>) map.get("cardResiue")).size();
System.out.println("碰之前的孤章数量 size" + size1);
if (size2 < size1) {
System.out.println("===============碰之后的孤章数量 小于 碰之前的孤章数量可以碰 ================== ++++ ");
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", id1);
pongGroup.add(opcard);
pongGroup.add(opcard);
pongGroup.add(opcard);
Util.removeCard(changShaCardInhand, opcard, 2);
}
//碰之后的手数大于碰之前的手数,或者碰之后的孤章数量大于碰之前的孤章数量不能碰
} else if (Integer.parseInt(map2.get("remainingMelds").toString()) > Integer.parseInt(map.get("remainingMelds").toString()) || ((List<Integer>) map2.get("cardResiue")).size() > ((List<Integer>) map.get("cardResiue")).size()) {
params.putString("session", session + "," + token); params.putString("session", session + "," + token);
params.putInt("qi", 1); params.putInt("qi", 1);
params.putInt("id", 0); params.putInt("id", 0);
} }
} }
}
}
//听牌的时候先不碰 //听牌的时候先不碰
if (shifoutingpai.size() > 0) { if (shifoutingpai.size() > 0) {
@ -500,6 +571,7 @@ public class HuNanChangSha {
params.putInt("qi", 1); params.putInt("qi", 1);
params.putInt("id", 0); params.putInt("id", 0);
} }
}
// a = tinHuPeng.canPeng(changShaCardInhand, opcard); // a = tinHuPeng.canPeng(changShaCardInhand, opcard);
@ -596,6 +668,8 @@ public class HuNanChangSha {
index++; index++;
System.out.println("checktingpai1 吃牌 " + checktingpai1); System.out.println("checktingpai1 吃牌 " + checktingpai1);
} }
// TODO: 2026/1/1 // TODO: 2026/1/1
// 1.需要补充 没听牌也可以吃 但是吃之后要比吃之前的手牌强 也就是可听数量变多 // 1.需要补充 没听牌也可以吃 但是吃之后要比吃之前的手牌强 也就是可听数量变多
// 2.听牌后也能吃牌,要比吃之前的牌强 // 2.听牌后也能吃牌,要比吃之前的牌强

View File

@ -2049,14 +2049,14 @@ public class ChangShaSuanFaTest {
suitCountMap.put(suit, suitCountMap.getOrDefault(suit, 0) + 1); suitCountMap.put(suit, suitCountMap.getOrDefault(suit, 0) + 1);
} }
// 检查是否有花色的牌数量超过8张
for (Map.Entry<Integer, Integer> entry : suitCountMap.entrySet()) { for (Map.Entry<Integer, Integer> entry : suitCountMap.entrySet()) {
int suit = entry.getKey(); int suit = entry.getKey();
int count = entry.getValue(); int count = entry.getValue();
if (count >= 9) { if (count >= 11) {
String suitName = getSuitName(suit); String suitName = getSuitName(suit);
logInfo("检测到可能的清一色花色: " + suitName + ", 数量: " + count); logInfo("检测到可能的清一色花色: " + suitName + ", 数量: " + count);
return true; return true;

View File

@ -77,6 +77,59 @@ public class TinHuChi {
hand1.add(103); hand1.add(103);
// hand1.add(102); // hand1.add(102);
int addcard =203;
Map<String, Object> map = new HashMap<>();
//碰之后的map
Map<String, Object> map2 = new HashMap<>();
//先判断碰之前还需要几手牌,以及孤章
// int jiangnum = checkduijiang(changShaCardInhand);
List<Integer> tmpChangSch = new ArrayList<>();
tmpChangSch.addAll(hand1);
tmpChangSch.add(addcard);
ChangshaWinSplitCard.checkNormalHu(tmpChangSch, map);
System.out.println("checkNormalHu 孤章数量 " + ((List<Integer>) map.get("cardResiue")).size());
System.out.println("checkNormalHu 手数 " + map.get("remainingMelds"));
//碰之后
List<Integer> pengtemphand = new ArrayList<>();
pengtemphand.addAll(tmpChangSch);
Util.removeCard(pengtemphand, addcard, 3);
ChangshaWinSplitCard.checkNormalHu(pengtemphand, map2);
//判断两个map是否找到更优
System.out.println("碰之前 map1: 手数" + Integer.parseInt(map.get("remainingMelds").toString()));
System.out.println("碰之后 map2 手数:" + Integer.parseInt(map2.get("remainingMelds").toString()));
//碰之后的手数小于碰之前的手数,可以碰
if (Integer.parseInt(map2.get("remainingMelds").toString()) < Integer.parseInt(map.get("remainingMelds").toString())) {
System.out.println("===============碰之后的手数小于碰之前的手数,可以碰 决定碰牌================== ++++ ");
} else if (Integer.parseInt(map2.get("remainingMelds").toString()) == Integer.parseInt(map.get("remainingMelds").toString())) { //碰完后和碰之前手数相等,需要判断孤章数量
//碰之后的数量
int size2 = ((List<Integer>) map2.get("cardResiue")).size();
System.out.println("碰之后的孤章数量 " + size2);
int size1 = ((List<Integer>) map.get("cardResiue")).size();
System.out.println("碰之前的孤章数量 " + size1);
if (size2 < size1) {
System.out.println("===============碰之后的孤章数量 小于 碰之前的孤章数量可以碰 ================== ++++ ");
}
//碰之后的手数大于碰之前的手数,或者碰之后的孤章数量大于碰之前的孤章数量不能碰
} else if (Integer.parseInt(map2.get("remainingMelds").toString()) > Integer.parseInt(map.get("remainingMelds").toString()) || ((List<Integer>) map2.get("cardResiue")).size() > ((List<Integer>) map.get("cardResiue")).size()) {
System.out.println("碰之后的手数大于碰之前的手数,或者碰之后的孤章数量大于碰之前的孤章数量不能碰");
}
}
// List<Integer> temphand = new ArrayList<>(); // List<Integer> temphand = new ArrayList<>();
// temphand.addAll(hand1); // temphand.addAll(hand1);
// temphand.add(104); // temphand.add(104);
@ -85,73 +138,78 @@ public class TinHuChi {
// System.out.println("checktingpai1" + checktingpai1); // System.out.println("checktingpai1" + checktingpai1);
//hand1.add(101); //hand1.add(101);
int addcard =203;
Map<String, Object> map = new HashMap<>(); // Map<String, Object> map = new HashMap<>();
Map<String, Object> map2 = new HashMap<>(); // Map<String, Object> map2 = new HashMap<>();
//
List<List<Integer>> lists = checkChi(hand1, addcard); // List<List<Integer>> lists = checkChi(hand1, addcard);
//吃之前的逻辑 // //吃之前的逻辑
int jiangnum = checkduijiang(hand1); // int jiangnum = checkduijiang(hand1);
hand1.add(addcard); // hand1.add(addcard);
System.out.println(hand1); // System.out.println(hand1);
ChangshaWinSplitCard.checkNormalHu(hand1, map); // ChangshaWinSplitCard.checkNormalHu(hand1, map);
//
System.out.println("checkNormalHu" + map.get("cardResiue")); // System.out.println("checkNormalHu" + map.get("cardResiue"));
//
System.out.println("checktingpai1" + lists); // System.out.println("checktingpai1" + lists);
int index = 0; // int index = 0;
int flag = 0; // int flag = 0;
for (List<Integer> list : lists) { // for (List<Integer> list : lists) {
List<Integer> temphand = hand1; // List<Integer> temphand = hand1;
//temphand.add(addcard); // //temphand.add(addcard);
Util.removeCard(temphand,list.get(0),1); // Util.removeCard(temphand,list.get(0),1);
Util.removeCard(temphand,list.get(1),1); // Util.removeCard(temphand,list.get(1),1);
Util.removeCard(temphand,list.get(2),1); // Util.removeCard(temphand,list.get(2),1);
System.out.println("temphand" + temphand); // System.out.println("temphand" + temphand);
ChangshaWinSplitCard.checkNormalHu(temphand, map2); // ChangshaWinSplitCard.checkNormalHu(temphand, map2);
//判断两个map是否找到更优 // //判断两个map是否找到更优
System.out.println("map1:"+Integer.parseInt(map.get("remainingMelds").toString())); // System.out.println("map1:"+Integer.parseInt(map.get("remainingMelds").toString()));
System.out.println("map2:"+Integer.parseInt(map2.get("remainingMelds").toString())); // System.out.println("map2:"+Integer.parseInt(map2.get("remainingMelds").toString()));
//
//
if (Integer.parseInt(map2.get("remainingMelds").toString()) < Integer.parseInt(map.get("remainingMelds").toString()) ){ // if (Integer.parseInt(map2.get("remainingMelds").toString()) < Integer.parseInt(map.get("remainingMelds").toString()) ){
flag=index+1; // flag=index+1;
}else if (Integer.parseInt(map2.get("remainingMelds").toString()) == Integer.parseInt(map.get("remainingMelds").toString())){ // }else if (Integer.parseInt(map2.get("remainingMelds").toString()) == Integer.parseInt(map.get("remainingMelds").toString())){
int size2 = ((List<Integer>) map2.get("cardResiue")).size(); // int size2 = ((List<Integer>) map2.get("cardResiue")).size();
System.out.println("size2" + size2); // System.out.println("size2" + size2);
int size1 = ((List<Integer>) map.get("cardResiue")).size(); // int size1 = ((List<Integer>) map.get("cardResiue")).size();
System.out.println("size1" + size1); // System.out.println("size1" + size1);
if (size2 < size1){ // if (size2 < size1){
flag=index+1; // flag=index+1;
} // }
//
//如果手里没有将,则可以吃 // //如果手里没有将,则可以吃
if (jiangnum>0) { // if (jiangnum>0) {
int chihoujiangnum = checkduijiang(temphand); // int chihoujiangnum = checkduijiang(temphand);
if (chihoujiangnum>0){ // if (chihoujiangnum>0){
//吃之后还有将 // //吃之后还有将
flag=index+1; // flag=index+1;
} // }
}else{ // }else{
System.out.println("没队将"); // System.out.println("没队将");
//孤章1张 差一手 不是将 而且card不是将 // //孤章1张 差一手 不是将 而且card不是将
if (Integer.parseInt(map.get("remainingMelds").toString())==1&&size1==1&&!isJiangPai(((List<Integer>) map.get("cardResiue")).get(0))&&!isJiangPai(addcard)){ // if (Integer.parseInt(map.get("remainingMelds").toString())==1&&size1==1&&!isJiangPai(((List<Integer>) map.get("cardResiue")).get(0))&&!isJiangPai(addcard)){
//吃 // //吃
break;
}
flag=index+1;
// break; // break;
} // }
// flag=index+1;
// // break;
// }
//
//
//
// }
//
// index ++ ;
// System.out.println("checkNormalHu2" + map2);
// }
// System.out.println("flag" + flag);
}
index ++ ;
System.out.println("checkNormalHu2" + map2);
}
System.out.println("flag" + flag);
/*List<Integer> shifoutingpai = shifoutingpai(hand1); /*List<Integer> shifoutingpai = shifoutingpai(hand1);
System.out.println("shifoutingpai" + shifoutingpai); System.out.println("shifoutingpai" + shifoutingpai);
// //
@ -179,7 +237,6 @@ public class TinHuChi {
System.out.println(lists); System.out.println(lists);
*/ */
}
public static List<Integer> shifoutingpai(List<Integer> cardhand) { public static List<Integer> shifoutingpai(List<Integer> cardhand) {
List<Integer> tpcards = new ArrayList<>(); List<Integer> tpcards = new ArrayList<>();