修改出牌卡住

master
fpgajie 2026-01-10 21:47:12 +08:00
parent 57d4a95603
commit 0d678a354d
2 changed files with 94 additions and 127 deletions

View File

@ -136,6 +136,10 @@ public class ChangShaSuanFaTest {
List<Integer> pinghuhandCards = new ArrayList<>(cardInhand);
List<Integer> pinghuhandCards1 = new ArrayList<>(cardInhand);
chuguodepai.addAll(resultList);
handCards.addAll(chowGroup);
@ -156,6 +160,7 @@ public class ChangShaSuanFaTest {
//特殊牌型处理
String tscard = teshuXuanPai(cardInhand, pengCard, chowGroup, gangdepai);
if (tscard!=null){
System.out.printf("特殊牌型处理111 +++++++++++++++++++++++++++++++++++");
return tscard;
}
@ -181,6 +186,7 @@ public class ChangShaSuanFaTest {
}
}
//
System.out.printf("特殊牌型处理222 +++++++++++++++++++++++++++++++++++");
return String.valueOf(xuanzecard);
}
@ -247,6 +253,8 @@ public class ChangShaSuanFaTest {
Integer maxCard = maxCards.isEmpty() ? null : maxCards.get(0);
System.out.println("maxCard++++++++++++++++++++++++++++++" + maxCard);
System.out.printf("特殊牌型处理333 +++++++++++++++++++++++++++++++++++");
return String.valueOf(maxCard);
}
@ -401,14 +409,17 @@ public class ChangShaSuanFaTest {
if (jiangHu && chowGroup.size() == 0) {
logInfo("将将胡");
int outcard = selectCardToDiscardJiangHu(pinghuhandCards);
System.out.printf("特殊牌型处理444 +++++++++++++++++++++++++++++++++++");
return String.valueOf(outcard);
}
if (hasBigSuit) {
logInfo("执行清一色策略,尝试优化花色分布");
// 调用清一色特定出牌策略
int outcard = selectCardToDiscardForAllSameSuit(handCards, chowGroup, pengCard);
int outcard = selectCardToDiscardForAllSameSuit(pinghuhandCards, chowGroup, pengCard);
if (outcard != -1) {
System.out.printf("特殊牌型处理555 +++++++++++++++++++++++++++++++++++");
return String.valueOf(outcard);
}
@ -421,6 +432,7 @@ public class ChangShaSuanFaTest {
//大胡出牌逻辑 - 七小对
int outcard = selectCardToDiscardBig(handCards, pisCardsCount);
System.out.printf("特殊牌型处理666 +++++++++++++++++++++++++++++++++++");
return String.valueOf(outcard);
}
@ -456,6 +468,7 @@ public class ChangShaSuanFaTest {
.collect(Collectors.toList());
Integer maxCard = maxCards.isEmpty() ? null : maxCards.get(0);
System.out.printf("特殊牌型处理777 +++++++++++++++++++++++++++++++++++");
return String.valueOf(maxCard);
@ -474,6 +487,8 @@ public class ChangShaSuanFaTest {
String discardCard = selectCardToDiscardAllSameSuitQiXiaoDuiBySuit(handCards);
if (discardCard != null) {
System.out.printf("特殊牌型处理888 +++++++++++++++++++++++++++++++++++");
return discardCard;
}
}
@ -483,16 +498,15 @@ public class ChangShaSuanFaTest {
logInfo("清一色碰碰胡");
String discardCard = selectCardToDiscardPengPeng(pinghuhandCards);
if (discardCard != null) {
System.out.printf("特殊牌型处理999 +++++++++++++++++++++++++++++++++++");
return discardCard;
}
}
//调平胡递归
List<Integer> integers = ChangshaWinSplitCard.analyzeBestDiscard(pinghuhandCards);
if(integers.size()>0) {
int integer = 0;
integer = selectBestCardByPriority(integers);
@ -500,24 +514,24 @@ public class ChangShaSuanFaTest {
System.out.println(pinghuhandCards);
int duijiangnum = checkduijiang(pinghuhandCards);
System.out.println("mapduijiang:"+duijiangnum);
System.out.println("mapduijiang:" + duijiangnum);
if (integers.size()>1&&duijiangnum==0){
if (integers.size() > 1 && duijiangnum == 0) {
integer = selectBestCardRemove258(integers);
}
//判断是否可以开杠
int cardnum = 0;
if (integer>0){
cardnum = Util.cardNum(integer,cardInhand);
if (integer > 0) {
cardnum = Util.cardNum(integer, cardInhand);
}
if (integers.size() > 0&&cardnum<4) {
if (integers.size() > 0 && cardnum < 4) {
System.out.println("平胡最新出牌策略=============================================== 666 " + integer);
return String.valueOf(integer);
}
}
//先拆对子
@ -525,28 +539,28 @@ public class ChangShaSuanFaTest {
//再拆门子
ai ai1 = new ai();
// ChangshaMahjongAI ai = new ChangshaMahjongAI();
PlayerState playerState = new PlayerState();
playerState.handCards = pinghuhandCards;
System.out.println("chowGroup +++++++++++++++++++++++" + chowGroup);
System.out.println("pengCard +++++++++++++++++++++++" + pengCard);
for (int j = 0; j < chowGroup.size(); j += 3) {
List<Integer> chigroup = new ArrayList<>(chowGroup.subList(j, Math.min(j + 3, chowGroup.size())));
if (chigroup.size() == 3) {
playerState.addChiGroup(chigroup);
}
}
System.out.println("playerState.chiGroups +++++++++++++++++++ " + playerState.chiGroups);
System.out.println("最新 ai出牌--------------------================");
for (int h = 0; h < pengCard.size(); h += 3) {
List<Integer> penggroup = new ArrayList<>(pengCard.subList(h, Math.min(h + 3, pengCard.size())));
if (penggroup.size() == 3) {
playerState.addPongGroup(penggroup);
}
}
// ai ai1 = new ai();
//// ChangshaMahjongAI ai = new ChangshaMahjongAI();
// PlayerState playerState = new PlayerState();
// playerState.handCards = pinghuhandCards;
// System.out.println("chowGroup +++++++++++++++++++++++" + chowGroup);
// System.out.println("pengCard +++++++++++++++++++++++" + pengCard);
//
// for (int j = 0; j < chowGroup.size(); j += 3) {
// List<Integer> chigroup = new ArrayList<>(chowGroup.subList(j, Math.min(j + 3, chowGroup.size())));
// if (chigroup.size() == 3) {
// playerState.addChiGroup(chigroup);
// }
// }
//
// System.out.println("playerState.chiGroups +++++++++++++++++++ " + playerState.chiGroups);
// System.out.println("最新 ai出牌--------------------================");
// for (int h = 0; h < pengCard.size(); h += 3) {
// List<Integer> penggroup = new ArrayList<>(pengCard.subList(h, Math.min(h + 3, pengCard.size())));
// if (penggroup.size() == 3) {
// playerState.addPongGroup(penggroup);
// }
// }
//int bestDiscard = ai1.findBestDiscard(playerState);
@ -565,10 +579,10 @@ public class ChangShaSuanFaTest {
// 1. 手牌分析 - 识别刻子、顺子、对子等牌型
HandAnalysis analysis = analyzeHand(handCards);
HandAnalysis analysis = analyzeHand(pinghuhandCards1);
//最终出的牌
int outcard = selectCardToDiscard(handCards, analysis);
int outcard = selectCardToDiscard(pinghuhandCards1, analysis);
logInfo("\n===== 手牌分析结果 =====");
@ -4025,7 +4039,7 @@ public class ChangShaSuanFaTest {
dangqianid = entry.getKey();
}
}
if (dangqianfen>5){
if (dangqianfen>6){
return dangqianid;
}else{
dangqianid = 0;
@ -4252,14 +4266,18 @@ public class ChangShaSuanFaTest {
}
//检测是否有4对
int duizi = countPairs(yupanhandcard);
if (duizi>=4&&pengGrop.size()==0){
System.out.println("duizi:"+duizi);
System.out.println(pengGrop);
if (duizi>=4&&pengGrop.size()>=0){
chiob.putInt("teshu",5);
}
if (duizi>=3&&pengGrop.size()==1){
if (duizi>=3&&pengGrop.size()>=2){
chiob.putInt("teshu",8);
}
if (duizi>=2&&pengGrop.size()==2){
chiob.putInt("teshu",10);
System.out.println(pengGrop.size());
if (duizi>=2&&pengGrop.size()>=6){
chiob.putInt("teshu",12);
}
@ -4597,22 +4615,22 @@ public class ChangShaSuanFaTest {
// 测试用例没有258将牌的情况
List<Integer> test1 = new ArrayList<Integer>();
test1.add(208);
test1.add(208);
test1.add(202);
test1.add(202);
test1.add(202);
test1.add(109);
test1.add(109);
test1.add(107);
test1.add(106);
test1.add(105);
test1.add(107);
test1.add(108);
test1.add(108);
test1.add(104);
test1.add(103);
test1.add(102);
test1.add(109);
test1.add(109);
test1.add(201);
test1.add(201);
test1.add(203);
test1.add(203);
test1.add(204);
test1.add(204);
test1.add(206);
int lg = countPairs(test1);
System.out.println(lg);
@ -4645,7 +4663,7 @@ public class ChangShaSuanFaTest {
//gangguopai.add(206);
//gangguopai.add(206);
int card = 101;
int card = 105;
List<Integer>pengCard = new ArrayList<>();
// pengCard.add(102);
//出牌求优
@ -4658,14 +4676,14 @@ public class ChangShaSuanFaTest {
// pingguChi(false,card,opcard,test1,0,allcard,chipai,changShachuguopai);
//测试碰
/* int card = 109;
// int card = 102;
ITArray opcardpeng = TArray.newInstance();
opcardpeng.addInt(109);
opcardpeng.addInt(102);
List<Integer> pengpai = new ArrayList<>();
List<Integer> gangpai = new ArrayList<>();
pingguPeng(false,card,opcardpeng,test1,0,allcard,chipai,pengpai,gangpai,changShachuguopai);
//pingguPeng(true,card,opcardpeng,test1,0,allcard,chipai,pengpai,gangpai,changShachuguopai);
/*
//List<Integer>tf = handscardshifoutingpai(test1);
// System.out.println(tf);

View File

@ -121,6 +121,9 @@ public class ChangshaWinSplitCard {
}
}
List<Integer> cardResiue = (List<Integer>) map.get("cardResiue");
for (int i = 0; i < cardResiue.size() - 1; i++) {
@ -582,60 +585,6 @@ public class ChangshaWinSplitCard {
if (zuizhongchupai.isEmpty()) {
return new ArrayList<>();
}
// //牌桌上出过的牌 未实现 这里听牌zuizhongchupai 对比 牌桌上出过的牌
// ChangShaSuanFaTest changShaSuanFaTest = new ChangShaSuanFaTest();
// List<Integer> chuguodepai = changShaSuanFaTest.chuguodepai();
// if (chuguodepai.size() > 0 && checktingpai.size() > 0) {
// System.out.println("递归内牌桌上出过的牌 ============ ===============" + chuguodepai);
// Map<Integer, Integer> tinCardCountMap = new HashMap<>();
//
// // 初始化听牌组中所有牌的出现次数为0
// for (Integer card : checktingpai) {
// tinCardCountMap.put(card, 0);
// }
//
// // 统计听牌组中每张牌在牌桌上的实际出现次数
// for (Integer card : checktingpai) {
// if (tinCardCountMap.containsKey(card)) {
// tinCardCountMap.put(card, tinCardCountMap.get(card) + 1);
// }
// }
//
// // 找到最大的出现次数
// Integer maxCount = tinCardCountMap.values().stream()
// .max(Integer::compareTo)
// .orElse(0);
//
// // 判断所有听牌是否都大于等于3次
// boolean allGreaterOrEqualThree = !tinCardCountMap.isEmpty() &&
// tinCardCountMap.values().stream().allMatch(count -> count >= 3);
//
// if (allGreaterOrEqualThree) {
// List<Integer> result = new ArrayList<>();
// // 如果所有听牌都出现大于等于3次则随机出一张听牌
// Integer randomCard = checktingpai.get(new Random().nextInt(checktingpai.size()));
// System.out.println("递归内 -----所有听牌出现次数都>=3随机出牌: " + randomCard);
// result.add(randomCard);
// return result;
// }
//
// if (maxCount > 0 && maxCount < 3) {
// // 出现次数大于0但小于3也直接出次数最多的牌
// List<Integer> maxCards = tinCardCountMap.entrySet().stream()
// .filter(entry -> entry.getValue().equals(maxCount))
// .map(Map.Entry::getKey)
// .collect(Collectors.toList());
//
// if (!maxCards.isEmpty()) {
// List<Integer> result = new ArrayList<>();
// Integer maxCard = Collections.max(maxCards);
// result.add(maxCard);
// return result;
// }
//
// }
// }
return zuizhongchupai;
}