Compare commits

..

No commits in common. "852e4e78227f1da19a5fb67dfcc9eba967fe0d3a" and "57d4a95603eae3bf082dcca025ae1421b8536aa2" have entirely different histories.

5 changed files with 146 additions and 120 deletions

Binary file not shown.

View File

@ -1665,26 +1665,26 @@ public class HuNanChangSha {
hands1.add(209); hands1.add(209);
hands1.add(209); hands1.add(209);
hands1.add(207); hands1.add(207);
hands1.add(207); hands1.add(206);
hands1.add(207);
hands1.add(205); hands1.add(205);
hands1.add(202); hands1.add(109);
hands1.add(109);
hands1.add(107);
hands1.add(106);
hands1.add(105);
hands1.add(203);
hands1.add(202); hands1.add(202);
hands1.add(201); hands1.add(201);
hands1.add(107);
hands1.add(107); int card= 109;
hands1.add(103);
hands1.add(103);
int card= 209;
huNanChangSha.changShaCardInhand.addAll(hands1); huNanChangSha.changShaCardInhand.addAll(hands1);
TArray tiplist= new TArray(); TArray tiplist= new TArray();
ITArray opcard = TArray.newInstance(); ITArray opcard = TArray.newInstance();
opcard.addInt(206);
opcard.addInt(207); opcard.addInt(207);
opcard.addInt(206);
// opcard.addInt(203); // opcard.addInt(203);
TObject tob = new TObject(); TObject tob = new TObject();
@ -1696,8 +1696,8 @@ public class HuNanChangSha {
//tiplist.addTObject(tob); //tiplist.addTObject(tob);
ITArray opcard2 = TArray.newInstance(); ITArray opcard2 = TArray.newInstance();
opcard2.addInt(209); opcard2.addInt(109);
// opcard2.addInt(207); // opcard2.addInt(206);
TObject tob2 = new TObject(); TObject tob2 = new TObject();
tob2.putInt("weight",1); tob2.putInt("weight",1);
tob2.putInt("id",1); tob2.putInt("id",1);
@ -1707,14 +1707,14 @@ public class HuNanChangSha {
tiplist.addTObject(tob2); tiplist.addTObject(tob2);
ITArray opcard3 = TArray.newInstance(); ITArray opcard3 = TArray.newInstance();
opcard3.addInt(202); opcard2.addInt(202);
// opcard2.addInt(206); // opcard2.addInt(206);
TObject tob3 = new TObject(); TObject tob3 = new TObject();
tob3.putInt("weight",3); tob3.putInt("weight",3);
tob3.putInt("id",2); tob3.putInt("id",2);
tob3.putInt("type",3); tob3.putInt("type",3);
tob3.putInt("card",card); tob3.putInt("card",card);
tob3.putTArray("opcard", opcard3); tob3.putTArray("opcard", opcard2);
// tiplist.addTObject(tob3); // tiplist.addTObject(tob3);
params.putTArray("tip_list",tiplist); params.putTArray("tip_list",tiplist);

View File

@ -136,10 +136,6 @@ public class ChangShaSuanFaTest {
List<Integer> pinghuhandCards = new ArrayList<>(cardInhand); List<Integer> pinghuhandCards = new ArrayList<>(cardInhand);
List<Integer> pinghuhandCards1 = new ArrayList<>(cardInhand);
chuguodepai.addAll(resultList); chuguodepai.addAll(resultList);
handCards.addAll(chowGroup); handCards.addAll(chowGroup);
@ -160,7 +156,6 @@ public class ChangShaSuanFaTest {
//特殊牌型处理 //特殊牌型处理
String tscard = teshuXuanPai(cardInhand, pengCard, chowGroup, gangdepai); String tscard = teshuXuanPai(cardInhand, pengCard, chowGroup, gangdepai);
if (tscard!=null){ if (tscard!=null){
System.out.printf("特殊牌型处理111 +++++++++++++++++++++++++++++++++++");
return tscard; return tscard;
} }
@ -186,7 +181,6 @@ public class ChangShaSuanFaTest {
} }
} }
// //
System.out.printf("特殊牌型处理222 +++++++++++++++++++++++++++++++++++");
return String.valueOf(xuanzecard); return String.valueOf(xuanzecard);
} }
@ -253,8 +247,6 @@ public class ChangShaSuanFaTest {
Integer maxCard = maxCards.isEmpty() ? null : maxCards.get(0); Integer maxCard = maxCards.isEmpty() ? null : maxCards.get(0);
System.out.println("maxCard++++++++++++++++++++++++++++++" + maxCard); System.out.println("maxCard++++++++++++++++++++++++++++++" + maxCard);
System.out.printf("特殊牌型处理333 +++++++++++++++++++++++++++++++++++");
return String.valueOf(maxCard); return String.valueOf(maxCard);
} }
@ -409,29 +401,14 @@ public class ChangShaSuanFaTest {
if (jiangHu && chowGroup.size() == 0) { if (jiangHu && chowGroup.size() == 0) {
logInfo("将将胡"); logInfo("将将胡");
int outcard = selectCardToDiscardJiangHu(pinghuhandCards); int outcard = selectCardToDiscardJiangHu(pinghuhandCards);
System.out.printf("特殊牌型处理444 +++++++++++++++++++++++++++++++++++");
return String.valueOf(outcard); return String.valueOf(outcard);
} }
if (pisCardsCount >= 5 && pengCard.size() == 0 && chowGroup.size() == 0) {
//大胡出牌逻辑 - 七小对
int outcard = selectCardToDiscardBig(handCards, pisCardsCount);
System.out.printf("特殊牌型处理666 +++++++++++++++++++++++++++++++++++");
return String.valueOf(outcard);
}
System.out.println(hasBigSuit);
if (hasBigSuit) { if (hasBigSuit) {
logInfo("执行清一色策略,尝试优化花色分布"); logInfo("执行清一色策略,尝试优化花色分布");
// 调用清一色特定出牌策略 // 调用清一色特定出牌策略
int outcard = selectCardToDiscardForAllSameSuit(pinghuhandCards, chowGroup, pengCard); int outcard = selectCardToDiscardForAllSameSuit(handCards, chowGroup, pengCard);
if (outcard != -1) { if (outcard != -1) {
System.out.printf("特殊牌型处理555 +++++++++++++++++++++++++++++++++++");
return String.valueOf(outcard); return String.valueOf(outcard);
} }
@ -440,7 +417,13 @@ public class ChangShaSuanFaTest {
// List<Integer> checktingpai = TinHuChi.checktingpai(cardInhand); // List<Integer> checktingpai = TinHuChi.checktingpai(cardInhand);
if (pisCardsCount >= 5 && pengCard.size() == 0 && chowGroup.size() == 0) {
//大胡出牌逻辑 - 七小对
int outcard = selectCardToDiscardBig(handCards, pisCardsCount);
return String.valueOf(outcard);
}
//碰碰胡 //碰碰胡
@ -473,7 +456,6 @@ public class ChangShaSuanFaTest {
.collect(Collectors.toList()); .collect(Collectors.toList());
Integer maxCard = maxCards.isEmpty() ? null : maxCards.get(0); Integer maxCard = maxCards.isEmpty() ? null : maxCards.get(0);
System.out.printf("特殊牌型处理777 +++++++++++++++++++++++++++++++++++");
return String.valueOf(maxCard); return String.valueOf(maxCard);
@ -492,8 +474,6 @@ public class ChangShaSuanFaTest {
String discardCard = selectCardToDiscardAllSameSuitQiXiaoDuiBySuit(handCards); String discardCard = selectCardToDiscardAllSameSuitQiXiaoDuiBySuit(handCards);
if (discardCard != null) { if (discardCard != null) {
System.out.printf("特殊牌型处理888 +++++++++++++++++++++++++++++++++++");
return discardCard; return discardCard;
} }
} }
@ -503,69 +483,70 @@ public class ChangShaSuanFaTest {
logInfo("清一色碰碰胡"); logInfo("清一色碰碰胡");
String discardCard = selectCardToDiscardPengPeng(pinghuhandCards); String discardCard = selectCardToDiscardPengPeng(pinghuhandCards);
if (discardCard != null) { if (discardCard != null) {
System.out.printf("特殊牌型处理999 +++++++++++++++++++++++++++++++++++");
return discardCard; return discardCard;
} }
} }
//调平胡递归 //调平胡递归
List<Integer> integers = ChangshaWinSplitCard.analyzeBestDiscard(pinghuhandCards); List<Integer> integers = ChangshaWinSplitCard.analyzeBestDiscard(pinghuhandCards);
if(integers.size()>0) { int integer = 0;
int integer = 0;
integer = selectBestCardByPriority(integers); integer = selectBestCardByPriority(integers);
Map<String, List<Integer>> mapduijiang = new HashMap<>(); Map<String, List<Integer>> mapduijiang = new HashMap<>();
System.out.println(pinghuhandCards); System.out.println(pinghuhandCards);
int duijiangnum = checkduijiang(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); integer = selectBestCardRemove258(integers);
}
//判断是否可以开杠
int cardnum = 0;
if (integer > 0) {
cardnum = Util.cardNum(integer, cardInhand);
}
if (integers.size() > 0 && cardnum < 4) {
System.out.println("平胡最新出牌策略=============================================== 666 " + integer);
return String.valueOf(integer);
}
} }
//判断是否可以开杠
int cardnum = 0;
if (integer>0){
cardnum = Util.cardNum(integer,cardInhand);
}
if (integers.size() > 0&&cardnum<4) {
System.out.println("平胡最新出牌策略=============================================== 666 " + integer);
return String.valueOf(integer);
}
//先拆对子 //先拆对子
//再拆门子 //再拆门子
// ai ai1 = new ai(); ai ai1 = new ai();
//// ChangshaMahjongAI ai = new ChangshaMahjongAI(); // ChangshaMahjongAI ai = new ChangshaMahjongAI();
// PlayerState playerState = new PlayerState(); PlayerState playerState = new PlayerState();
// playerState.handCards = pinghuhandCards; playerState.handCards = pinghuhandCards;
// System.out.println("chowGroup +++++++++++++++++++++++" + chowGroup); System.out.println("chowGroup +++++++++++++++++++++++" + chowGroup);
// System.out.println("pengCard +++++++++++++++++++++++" + pengCard); System.out.println("pengCard +++++++++++++++++++++++" + pengCard);
//
// for (int j = 0; j < chowGroup.size(); j += 3) { for (int j = 0; j < chowGroup.size(); j += 3) {
// List<Integer> chigroup = new ArrayList<>(chowGroup.subList(j, Math.min(j + 3, chowGroup.size()))); List<Integer> chigroup = new ArrayList<>(chowGroup.subList(j, Math.min(j + 3, chowGroup.size())));
// if (chigroup.size() == 3) { if (chigroup.size() == 3) {
// playerState.addChiGroup(chigroup); playerState.addChiGroup(chigroup);
// } }
// } }
//
// System.out.println("playerState.chiGroups +++++++++++++++++++ " + playerState.chiGroups); System.out.println("playerState.chiGroups +++++++++++++++++++ " + playerState.chiGroups);
// System.out.println("最新 ai出牌--------------------================"); System.out.println("最新 ai出牌--------------------================");
// for (int h = 0; h < pengCard.size(); h += 3) { for (int h = 0; h < pengCard.size(); h += 3) {
// List<Integer> penggroup = new ArrayList<>(pengCard.subList(h, Math.min(h + 3, pengCard.size()))); List<Integer> penggroup = new ArrayList<>(pengCard.subList(h, Math.min(h + 3, pengCard.size())));
// if (penggroup.size() == 3) { if (penggroup.size() == 3) {
// playerState.addPongGroup(penggroup); playerState.addPongGroup(penggroup);
// } }
// } }
//int bestDiscard = ai1.findBestDiscard(playerState); //int bestDiscard = ai1.findBestDiscard(playerState);
@ -584,10 +565,10 @@ public class ChangShaSuanFaTest {
// 1. 手牌分析 - 识别刻子、顺子、对子等牌型 // 1. 手牌分析 - 识别刻子、顺子、对子等牌型
HandAnalysis analysis = analyzeHand(pinghuhandCards1); HandAnalysis analysis = analyzeHand(handCards);
//最终出的牌 //最终出的牌
int outcard = selectCardToDiscard(pinghuhandCards1, analysis); int outcard = selectCardToDiscard(handCards, analysis);
logInfo("\n===== 手牌分析结果 ====="); logInfo("\n===== 手牌分析结果 =====");
@ -4044,7 +4025,7 @@ public class ChangShaSuanFaTest {
dangqianid = entry.getKey(); dangqianid = entry.getKey();
} }
} }
if (dangqianfen>6){ if (dangqianfen>5){
return dangqianid; return dangqianid;
}else{ }else{
dangqianid = 0; dangqianid = 0;
@ -4090,7 +4071,7 @@ public class ChangShaSuanFaTest {
chiob.putInt("isDaHu",beforeIsDahu); chiob.putInt("isDaHu",beforeIsDahu);
List checkCards = new ArrayList(); List checkCards = new ArrayList();
checkCards.addAll(yupanhandcard); checkCards.addAll(yupanhandcard);
System.out.println("checkCards"+checkCards);
//去掉三张牌是否还能听牌 //去掉三张牌是否还能听牌
for (int i=0;i<opcard.size();i++){ for (int i=0;i<opcard.size();i++){
Util.removeCard(checkCards,opcard.getInt(i),2); Util.removeCard(checkCards,opcard.getInt(i),2);
@ -4101,7 +4082,6 @@ public class ChangShaSuanFaTest {
System.out.println("beforedj:"+beforedj); System.out.println("beforedj:"+beforedj);
if (beforedj>=1){ if (beforedj>=1){
int afterdj = checkduijiang(checkCards); int afterdj = checkduijiang(checkCards);
System.out.println(checkCards);
if (afterdj==0){ if (afterdj==0){
chiob.putBoolean("xiaoJiang",true); chiob.putBoolean("xiaoJiang",true);
}else{ }else{
@ -4128,11 +4108,10 @@ public class ChangShaSuanFaTest {
//循环之后还能是大胡吗1,清一色27小对3碰碰胡4将将胡5门清 //循环之后还能是大胡吗1,清一色27小对3碰碰胡4将将胡5门清
if(beforeIsDahu>0){ if(beforeIsDahu>0){
/* if (beforeIsDahu==2){ if (beforeIsDahu==2){
chiob.putBoolean("xiaoDahu",true); chiob.putBoolean("xiaoDahu",true);
chiob.putInt("teshu",0); chiob.putInt("teshu",0);
}*/ }else if (beforeIsDahu==3){
if (beforeIsDahu==3||beforeIsDahu==2){
//碰碰胡 //碰碰胡
chiob.putBoolean("xiaoDahu",false); chiob.putBoolean("xiaoDahu",false);
chiob.putInt("teshu",10); chiob.putInt("teshu",10);
@ -4273,18 +4252,14 @@ public class ChangShaSuanFaTest {
} }
//检测是否有4对 //检测是否有4对
int duizi = countPairs(yupanhandcard); int duizi = countPairs(yupanhandcard);
System.out.println("duizi:"+duizi); if (duizi>=4&&pengGrop.size()==0){
System.out.println(pengGrop);
if (duizi==4&&pengGrop.size()>=0){
chiob.putInt("teshu",5); chiob.putInt("teshu",5);
} }
if (duizi==3&&pengGrop.size()>=2){ if (duizi>=3&&pengGrop.size()==1){
chiob.putInt("teshu",8); chiob.putInt("teshu",8);
} }
System.out.println(pengGrop.size()); if (duizi>=2&&pengGrop.size()==2){
if (duizi>=2&&pengGrop.size()>=6){ chiob.putInt("teshu",10);
chiob.putInt("teshu",12);
} }
@ -4622,22 +4597,22 @@ public class ChangShaSuanFaTest {
// 测试用例没有258将牌的情况 // 测试用例没有258将牌的情况
List<Integer> test1 = new ArrayList<Integer>(); List<Integer> test1 = new ArrayList<Integer>();
test1.add(209); test1.add(208);
test1.add(207); test1.add(208);
test1.add(207); test1.add(202);
test1.add(206); test1.add(202);
test1.add(205);
test1.add(204);
test1.add(203);
test1.add(202); test1.add(202);
test1.add(108); test1.add(109);
test1.add(107); test1.add(109);
test1.add(107);
test1.add(106); test1.add(106);
test1.add(105);
test1.add(104); test1.add(104);
test1.add(103); test1.add(103);
test1.add(102);
int lg = countPairs(test1); int lg = countPairs(test1);
System.out.println(lg); System.out.println(lg);
@ -4670,7 +4645,7 @@ public class ChangShaSuanFaTest {
//gangguopai.add(206); //gangguopai.add(206);
//gangguopai.add(206); //gangguopai.add(206);
int card = 105; int card = 101;
List<Integer>pengCard = new ArrayList<>(); List<Integer>pengCard = new ArrayList<>();
// pengCard.add(102); // pengCard.add(102);
//出牌求优 //出牌求优
@ -4683,14 +4658,14 @@ public class ChangShaSuanFaTest {
// pingguChi(false,card,opcard,test1,0,allcard,chipai,changShachuguopai); // pingguChi(false,card,opcard,test1,0,allcard,chipai,changShachuguopai);
//测试碰 //测试碰
// int card = 102; /* int card = 109;
ITArray opcardpeng = TArray.newInstance(); ITArray opcardpeng = TArray.newInstance();
opcardpeng.addInt(102); opcardpeng.addInt(109);
List<Integer> pengpai = new ArrayList<>(); List<Integer> pengpai = new ArrayList<>();
List<Integer> gangpai = new ArrayList<>(); List<Integer> gangpai = new ArrayList<>();
//pingguPeng(true,card,opcardpeng,test1,0,allcard,chipai,pengpai,gangpai,changShachuguopai); pingguPeng(false,card,opcardpeng,test1,0,allcard,chipai,pengpai,gangpai,changShachuguopai);
/* /*
//List<Integer>tf = handscardshifoutingpai(test1); //List<Integer>tf = handscardshifoutingpai(test1);
// System.out.println(tf); // System.out.println(tf);

View File

@ -121,9 +121,6 @@ public class ChangshaWinSplitCard {
} }
} }
List<Integer> cardResiue = (List<Integer>) map.get("cardResiue"); List<Integer> cardResiue = (List<Integer>) map.get("cardResiue");
for (int i = 0; i < cardResiue.size() - 1; i++) { for (int i = 0; i < cardResiue.size() - 1; i++) {
@ -585,6 +582,60 @@ public class ChangshaWinSplitCard {
if (zuizhongchupai.isEmpty()) { if (zuizhongchupai.isEmpty()) {
return new ArrayList<>(); 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; return zuizhongchupai;
} }