判断碰牌

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

@ -23,7 +23,7 @@ public class HuNanChangSha {
public static boolean isTinChi = false;
public static boolean isTinPeng = false;
public static Logger logger;
public static Logger logger;
//湖南红中麻将手牌
private List<Integer> changShaCardInhand = new ArrayList<>();
@ -204,8 +204,8 @@ public class HuNanChangSha {
return counts;
}
public static boolean isJiangPai(int card){
if (card%100==2||card%100==5||card%100==8){
public static boolean isJiangPai(int card) {
if (card % 100 == 2 || card % 100 == 5 || card % 100 == 8) {
return true;
}
return false;
@ -218,7 +218,7 @@ public class HuNanChangSha {
}
int jiangnum = 0;
for (int key : countMap.keySet()) {
if (isJiangPai(key)&&countMap.get(key)>=2){
if (isJiangPai(key) && countMap.get(key) >= 2) {
jiangnum++;
}
}
@ -463,44 +463,116 @@ public class HuNanChangSha {
}
}
System.out.println("进入吃type:"+type1);
System.out.println("进入吃type:" + type1);
if (type1 == 2) {
List<Integer> shifoutingpai = TinHuChi.shifoutingpai(changShaCardInhand);
//目前手牌没有听牌
if (shifoutingpai.size() == 0) {
List<Integer> temphand = new ArrayList<>();
temphand.addAll(changShaCardInhand);
temphand.add(opcard);
Util.removeCard(temphand, opcard, 3);
List<Integer> checktingpai1 = TinHuChi.checktingpai(temphand);
System.out.println("checktingpai1 碰牌" + checktingpai1);
if (checktingpai1.size() > 0) {
System.out.println("===============进入听胡碰牌================== ++++ ");
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", id1);
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);
//目前手牌没有听牌
if (shifoutingpai.size() == 0) {
pongGroup.add(opcard);
pongGroup.add(opcard);
pongGroup.add(opcard);
Util.removeCard(changShaCardInhand, opcard, 2);
} else {
//判断是否满足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<>();
temphand.addAll(changShaCardInhand);
temphand.add(opcard);
Util.removeCard(temphand, opcard, 3);
List<Integer> checktingpai1 = TinHuChi.checktingpai(temphand);
System.out.println("checktingpai1 碰牌" + checktingpai1);
//碰完牌后打牌后可以听牌
if (checktingpai1.size() > 0) {
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 {
//碰之前的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.putInt("qi", 1);
params.putInt("id", 0);
}
}
}
}
//听牌的时候先不碰
if (shifoutingpai.size() > 0) {
System.out.println("听牌的时候先不碰++++++++++++++++++++++++++++++++");
params.putString("session", session + "," + token);
params.putInt("qi", 1);
params.putInt("id", 0);
}
}
//听牌的时候先不碰
if (shifoutingpai.size() > 0) {
System.out.println("听牌的时候先不碰++++++++++++++++++++++++++++++++");
params.putString("session", session + "," + token);
params.putInt("qi", 1);
params.putInt("id", 0);
}
// a = tinHuPeng.canPeng(changShaCardInhand, opcard);
// ChangShaSuanFaTest changShaSuanFaTest = new ChangShaSuanFaTest();
@ -556,11 +628,11 @@ public class HuNanChangSha {
// int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);//分析七小对
boolean isChow = changShaSuanFaTest.isAllSameSuit1(changShaCardInhand);
if (isChow){
if (isChow) {
params.putString("session", session + "," + token);
params.putInt("qi", 1);
params.putInt("id", 0);
}else {
} else {
//判断当前手牌是否已经听牌 已经听牌了就不要再吃牌了
List<Integer> shifoutingpai = TinHuChi.shifoutingpai(changShaCardInhand);
@ -596,6 +668,8 @@ public class HuNanChangSha {
index++;
System.out.println("checktingpai1 吃牌 " + checktingpai1);
}
// TODO: 2026/1/1
// 1.需要补充 没听牌也可以吃 但是吃之后要比吃之前的手牌强 也就是可听数量变多
// 2.听牌后也能吃牌,要比吃之前的牌强

View File

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

View File

@ -77,6 +77,59 @@ public class TinHuChi {
hand1.add(103);
// 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<>();
// temphand.addAll(hand1);
// temphand.add(104);
@ -85,73 +138,78 @@ public class TinHuChi {
// System.out.println("checktingpai1" + checktingpai1);
//hand1.add(101);
int addcard =203;
Map<String, Object> map = new HashMap<>();
Map<String, Object> map2 = new HashMap<>();
List<List<Integer>> lists = checkChi(hand1, addcard);
//吃之前的逻辑
int jiangnum = checkduijiang(hand1);
hand1.add(addcard);
System.out.println(hand1);
ChangshaWinSplitCard.checkNormalHu(hand1, map);
System.out.println("checkNormalHu" + map.get("cardResiue"));
System.out.println("checktingpai1" + lists);
int index = 0;
int flag = 0;
for (List<Integer> list : lists) {
List<Integer> temphand = hand1;
//temphand.add(addcard);
Util.removeCard(temphand,list.get(0),1);
Util.removeCard(temphand,list.get(1),1);
Util.removeCard(temphand,list.get(2),1);
System.out.println("temphand" + temphand);
ChangshaWinSplitCard.checkNormalHu(temphand, 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()) ){
flag=index+1;
}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" + size2);
int size1 = ((List<Integer>) map.get("cardResiue")).size();
System.out.println("size1" + size1);
if (size2 < size1){
flag=index+1;
}
//如果手里没有将,则可以吃
if (jiangnum>0) {
int chihoujiangnum = checkduijiang(temphand);
if (chihoujiangnum>0){
//吃之后还有将
flag=index+1;
}
}else{
System.out.println("没队将");
//孤章1张 差一手 不是将 而且card不是将
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;
}
// Map<String, Object> map = new HashMap<>();
// Map<String, Object> map2 = new HashMap<>();
//
// List<List<Integer>> lists = checkChi(hand1, addcard);
// //吃之前的逻辑
// int jiangnum = checkduijiang(hand1);
// hand1.add(addcard);
// System.out.println(hand1);
// ChangshaWinSplitCard.checkNormalHu(hand1, map);
//
// System.out.println("checkNormalHu" + map.get("cardResiue"));
//
// System.out.println("checktingpai1" + lists);
// int index = 0;
// int flag = 0;
// for (List<Integer> list : lists) {
// List<Integer> temphand = hand1;
// //temphand.add(addcard);
// Util.removeCard(temphand,list.get(0),1);
// Util.removeCard(temphand,list.get(1),1);
// Util.removeCard(temphand,list.get(2),1);
// System.out.println("temphand" + temphand);
// ChangshaWinSplitCard.checkNormalHu(temphand, 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()) ){
// flag=index+1;
// }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" + size2);
// int size1 = ((List<Integer>) map.get("cardResiue")).size();
// System.out.println("size1" + size1);
// if (size2 < size1){
// flag=index+1;
// }
//
// //如果手里没有将,则可以吃
// if (jiangnum>0) {
// int chihoujiangnum = checkduijiang(temphand);
// if (chihoujiangnum>0){
// //吃之后还有将
// flag=index+1;
// }
// }else{
// System.out.println("没队将");
// //孤章1张 差一手 不是将 而且card不是将
// 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;
// }
//
//
//
// }
//
// 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);
System.out.println("shifoutingpai" + shifoutingpai);
//
@ -179,7 +237,6 @@ public class TinHuChi {
System.out.println(lists);
*/
}
public static List<Integer> shifoutingpai(List<Integer> cardhand) {
List<Integer> tpcards = new ArrayList<>();