feyerobot/libs/robot_common/src/main/java/hunan/HuNanChangSha.java

1925 lines
76 KiB
Java
Raw Normal View History

2026-01-01 07:54:30 +08:00
package hunan;
import com.game.Util;
import com.taurus.core.entity.ITArray;
import com.taurus.core.entity.ITObject;
2026-01-05 19:40:49 +08:00
import com.taurus.core.entity.TArray;
2026-01-01 07:54:30 +08:00
import com.taurus.core.entity.TObject;
import com.taurus.core.plugin.database.DataBase;
2026-01-30 16:04:50 +08:00
import com.taurus.core.plugin.redis.Redis;
2026-01-01 07:54:30 +08:00
import com.taurus.core.util.Logger;
import com.taurus.core.util.StringUtil;
2026-01-30 16:04:50 +08:00
import redis.clients.jedis.Jedis;
2026-01-01 07:54:30 +08:00
import taurus.client.Message;
import taurus.client.TaurusClient;
import taurus.util.*;
import java.sql.SQLException;
import java.util.*;
2026-01-01 22:27:34 +08:00
2026-01-01 07:54:30 +08:00
public class HuNanChangSha {
public static int changShaCard = 0;
public static boolean isTinChi = false;
public static boolean isTinPeng = false;
2026-01-30 16:04:50 +08:00
// private static final Logger log = Logger.getLogger(DoTest.class);
2026-01-01 22:27:34 +08:00
2026-01-01 07:54:30 +08:00
private List<Integer> changShaCardInhandgang = new ArrayList<>();
2026-01-05 19:40:49 +08:00
//长沙麻将出过的牌
2026-01-01 07:54:30 +08:00
private List<Integer> changShachuguopai = new ArrayList<>();
2026-01-30 16:04:50 +08:00
private List<Integer> changShaCardInhand = new ArrayList<>();
private Map<Integer, Integer> chuGuoPainum = new HashMap<>();
2026-01-01 07:54:30 +08:00
2026-01-05 19:40:49 +08:00
//杠的牌
2026-01-01 07:54:30 +08:00
private List<Integer> gangdepai = new ArrayList<>();
//碰牌
private List<Integer> pongGroup = new ArrayList<>();
//吃牌
private List<Integer> chowGroup = new ArrayList<>();
// 玩家座位号
public static int seat = 0;
// 会话标识
public static String session = "";
// 访问令牌
public static String token = "";
2026-01-30 16:04:50 +08:00
2026-01-01 07:54:30 +08:00
private static ChangShaSuanFaTest changShaSuanFaTest = new ChangShaSuanFaTest();
// 公共的getter和setter方法
public List<Integer> getgangdepai() {
return gangdepai;
}
public List<Integer> getchangShaCardInhandgang() {
return changShaCardInhandgang;
}
// 公共的getter和setter方法
public List<Integer> getpongGroup() {
return pongGroup;
}
public List<Integer> getchowGroup() {
return chowGroup;
}
2026-01-30 16:04:50 +08:00
public List<Integer> getChangShaCardInhand() {
return changShaCardInhand;
}
2026-01-01 07:54:30 +08:00
public List<Integer> getChuGuoCardInhand() {
return changShachuguopai;
}
2026-01-30 16:04:50 +08:00
public Map<Integer, Integer> getChuGuoPainum() {
2026-01-05 19:40:49 +08:00
return chuGuoPainum;
}
2026-01-01 07:54:30 +08:00
/**
* 广 812
*
* @param command
* @param message
* @return
*/
public static String drawCard(String command, Message message) {
if (command.equalsIgnoreCase("812")) {
ITObject param = message.param;
if (param == null) {
return null;
}
changShaCard = param.getInt("card");
}
return null;
}
/**
* 819
*
* @param command
* @param message
* @return
*/
2026-01-30 16:04:50 +08:00
public String getCard(String command, Message message, TaurusClient client, Map<String, Object> mapclient) {
2026-01-01 07:54:30 +08:00
if (command.equalsIgnoreCase("819")) {
ITObject param = message.param;
if (param == null) {
return null;
}
2026-01-30 16:04:50 +08:00
Jedis jedis222 = Redis.use("group1_db2").getJedis();
2026-01-01 07:54:30 +08:00
if (param.getInt("player") != null) {
2026-01-30 16:04:50 +08:00
Integer player = param.getInt("player");
2026-01-01 07:54:30 +08:00
int drawnCard = param.getInt("card");
changShaSuanFaTest.drawnCards = drawnCard;//存储摸到的牌
changShaCardInhand.add(drawnCard);
2026-01-30 16:04:50 +08:00
if (jedis222.hget("{robortInfo}:" + player, "circleId") != null && jedis222.hget("{robortInfo}:" + player, "pid") != null) {
String circleId = jedis222.hget("{robortInfo}:" + player, "circleId");
String pid = jedis222.hget("{robortInfo}:" + player, "pid");
String getStart = "g{" + circleId + "}:play:" + pid;
if (!pid.equals("0")) {
2026-01-31 06:21:58 +08:00
// jedis222.hset(getStart, String.valueOf(player), "2");
2026-01-30 16:04:50 +08:00
}
}
2026-01-01 07:54:30 +08:00
}
2026-01-30 16:04:50 +08:00
jedis222.close();
2026-01-01 07:54:30 +08:00
}
return null;
}
/**
*
*
* @param proposedCard
* @return
*/
public boolean shouldPong(int proposedCard) {
// 直接调用hongZhongSuanFaTest中的shouldPong方法它已经包含了所有需要的规则
return changShaSuanFaTest.shouldPong(proposedCard, changShaCardInhand);
}
public boolean shouldChow(int proposedCard) {
return changShaSuanFaTest.shouldChow(proposedCard, changShaCardInhand);
}
/**
* 811
*
* @param command
* @param message
* @return
*/
public String cardInHead(String command, Message message, TaurusClient client) {
if (command.equalsIgnoreCase("811")) {
ITObject param = message.param;
if (param == null) {
return null;
}
// {bank_seat=1, laiziCard=0, laiziCard2=0, laiziCard2Before=0, jing=0, laiziCardBefore=0, card_list=[101, 103, 104, 201, 204, 207, 208, 209, 307, 309, 501, 502, 503]}
ITArray cardList = param.getTArray("card_list");
2026-01-30 16:04:50 +08:00
List<Integer> handCards = new ArrayList<>();
for (int i = 0; i < cardList.size(); i++) {
handCards.add(cardList.getInt(i));
}
2026-01-01 07:54:30 +08:00
for (int i = 0; i < cardList.size(); i++) {
changShaCardInhand.add(cardList.getInt(i));
}
2026-01-30 16:04:50 +08:00
System.out.println("changShaCardInhand" + changShaCardInhand);
2026-01-01 07:54:30 +08:00
}
return null;
}
2026-01-01 22:27:34 +08:00
public static int[][] countTiles(List<Integer> cardInHand) {
int[][] counts = new int[5][10]; // 类型×值
for (Integer card : cardInHand) {
if (card == 0) {
continue;
}
counts[card / 100 - 1][card % 100]++;
}
return counts;
}
2026-01-02 02:19:59 +08:00
public static boolean isJiangPai(int card) {
if (card % 100 == 2 || card % 100 == 5 || card % 100 == 8) {
2026-01-01 22:27:34 +08:00
return true;
}
return false;
}
public static int checkduijiang(List<Integer> cardInHand) {
Map<Integer, Integer> countMap = new HashMap<>();
for (Integer item : cardInHand) {
countMap.put(item, countMap.getOrDefault(item, 0) + 1);
}
int jiangnum = 0;
for (int key : countMap.keySet()) {
2026-01-02 02:19:59 +08:00
if (isJiangPai(key) && countMap.get(key) >= 2) {
2026-01-01 22:27:34 +08:00
jiangnum++;
}
}
return jiangnum;
}
2026-01-05 19:40:49 +08:00
/**
*
2026-01-30 16:04:50 +08:00
*
2026-01-05 19:40:49 +08:00
* @param param
* @param client
2026-01-30 16:04:50 +08:00
* @return
* [TCP->814] data:{"tip_list":[{"type":1,"id":1,"opcard":[108,109],"weight":1,"card":107}]}
*
* {"tip_list":[{"type":1,"id":1,"opcard":[206,205],"weight":1,"card":207},{"type":2,"id":2,"opcard":[207],"weight":2,"card":207}]}
*
* {"tip_list":[{"type":2,"id":1,"opcard":[101],"weight":2,"card":101},{"type":3,"id":2,"opcard":[101],"weight":3,"card":101}]}
*
* [TCP->814] data:{"tip_list":[{"type":5,"id":1,"opcard":[101],"weight":3,"card":101}]}
*
* {"tip_list":[{"type":1,"id":1,"opcard":[206,204],"weight":1,"card":205},{"type":1,"id":2,"opcard":[206,207],"weight":1,"card":205},{"type":2,"id":3,"opcard":[205],"weight":2,"card":205},{"type":3,"id":4,"opcard":[205],"weight":3,"card":205},{"type":3,"id":5,"opcard":[205],"weight":4,"card":205}]}
*
* {"tip_list":[{"type":2,"id":1,"opcard":[207],"weight":2,"card":207}]}
*
* {"tip_list":[{"type":5,"id":1,"opcard":[207],"weight":3,"card":207},{"type":5,"id":2,"opcard":[207],"weight":4,"card":207}]}
* <p>
* //拟定:
* 1
* boolean isTing
* boolean canTing
* int tingNum
* int isDaHu
* int guzhang
* int lastHands
* int id tiplist id
* List<Integer> opcard
* int weight tiplist weight
* int card tiplist card
* int type tiplist type
* 2
*
* ---> 40
* ---> 20
* ---> -50
* ---> 3
* ----> -3
* ----> -5
* ----> 10
* -----> -10
* <p>
* 107
* {"tip_list":[{"type":5,"id":1,"opcard":[107],"weight":3,"card":107},{"type":5,"id":2,"opcard":[107],"weight":4,"card":107}]}
* <p>
* 3204
* {"tip_list":[{"type":4,"id":1,"opcard":[204],"weight":3,"card":204},{"type":4,"id":2,"opcard":[204],"weight":4,"card":204}]}
* <p>
* 3206
* {"tip_list":[{"type":3,"id":1,"opcard":[206],"weight":3,"card":206}]}
2026-01-05 19:40:49 +08:00
*/
2026-01-30 16:04:50 +08:00
public String actionCard(ITObject param, TaurusClient client) {
2026-01-05 19:40:49 +08:00
ITArray tipList = param.getTArray("tip_list");
2026-01-30 16:04:50 +08:00
// log.info("tipList" +tipList);
2026-01-05 19:40:49 +08:00
ITObject params = TObject.newInstance();
int card = 0;
//循环
List<Integer> yupanhandcard = new ArrayList<>();
yupanhandcard.addAll(changShaCardInhand);
//进行操作之前能否下听
2026-01-22 18:16:18 +08:00
2026-01-30 16:04:50 +08:00
List<Integer> shifoutingpai = changShaSuanFaTest.handscardshifoutingpai(changShaCardInhand, chowGroup, pongGroup, gangdepai);
2026-01-05 19:40:49 +08:00
boolean beforelisten = false;//记录操作之前的下听状态
2026-01-30 16:04:50 +08:00
System.out.println("shifoutingpai" + shifoutingpai);
2026-01-05 19:40:49 +08:00
if (shifoutingpai.size() > 0) {
beforelisten = true;
}
2026-01-30 16:04:50 +08:00
System.out.println("beforelisten" + beforelisten);
2026-01-05 19:40:49 +08:00
//如果杠了之后还能继续听牌则杠
2026-01-08 19:43:31 +08:00
2026-01-22 18:16:18 +08:00
//优先处理胡牌
2026-01-30 16:04:50 +08:00
for (int i = 0; i < tipList.size(); i++) {
2026-01-22 18:16:18 +08:00
TObject firstTip1 = (TObject) tipList.get(i).getObject();
int type = firstTip1.getInt("type");
int id = firstTip1.getInt("id");
2026-01-30 16:04:50 +08:00
if (type == 6) {
2026-01-08 19:43:31 +08:00
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", id);
client.send("612", params, response -> {
});
return "胡牌";
}
2026-01-22 18:16:18 +08:00
}
//如果下听了,可以杠
for (int i = 0; i < tipList.size(); i++) {
TObject firstTip = (TObject) tipList.get(i).getObject();
int type = firstTip.getInt("type");
int id = firstTip.getInt("id");
int weight = firstTip.getInt("weight");
card = firstTip.getInt("card");
2026-01-30 16:04:50 +08:00
if ((type == 5 || type == 3 || type == 4) && weight == 4) {
2026-01-05 19:40:49 +08:00
//判断开杠后是否能下听
List<Integer> gangusecars = new ArrayList<>();
gangusecars.addAll(changShaCardInhand);
2026-01-06 20:42:55 +08:00
2026-01-05 19:40:49 +08:00
if (type == 3) {
2026-01-30 16:04:50 +08:00
Util.removeCard(gangusecars, card, 3);
List<Integer> shifoutingpai3 = changShaSuanFaTest.handscardshifoutingpai(gangusecars, chowGroup, pongGroup, gangdepai);
2026-01-06 20:42:55 +08:00
System.out.println(shifoutingpai3);
2026-01-05 19:40:49 +08:00
if (shifoutingpai3.size() > 0) {
//开杠
2026-01-08 19:43:31 +08:00
//判断是否杠了之后没有牌可以听
List<Integer> allList = new ArrayList<>();
allList.addAll(changShaCardInhand);
allList.addAll(changShachuguopai);
2026-01-30 16:04:50 +08:00
int jutingnum = changShaSuanFaTest.getTingPainum(shifoutingpai3, allList);
if (jutingnum == 0) {
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
client.send("612", params, response -> {
});
return "不开杠";
}
Util.removeCard(changShaCardInhand, card, 3);
2026-01-05 19:40:49 +08:00
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", id);
client.send("612", params, response -> {
});
return "开杠";
2026-01-30 16:04:50 +08:00
} else {
2026-01-05 19:40:49 +08:00
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
client.send("612", params, response -> {
});
return "不开杠";
}
}
if (type == 4) {
2026-01-08 19:43:31 +08:00
2026-01-30 16:04:50 +08:00
// Util.removeCard(changShaCardInhand,card,4);
Util.removeCard(gangusecars, card, 4);
List<Integer> shifoutingpai4 = changShaSuanFaTest.handscardshifoutingpai(gangusecars, chowGroup, pongGroup, gangdepai);
2026-01-05 19:40:49 +08:00
if (shifoutingpai4.size() > 0) {
//开杠
2026-01-08 19:43:31 +08:00
//判断是否杠了之后没有牌可以听
List<Integer> allList = new ArrayList<>();
allList.addAll(changShaCardInhand);
allList.addAll(changShachuguopai);
2026-01-30 16:04:50 +08:00
int jutingnum = changShaSuanFaTest.getTingPainum(shifoutingpai4, allList);
if (jutingnum == 0) {
2026-01-08 19:43:31 +08:00
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
client.send("612", params, response -> {
});
return "不开杠";
}
2026-01-30 16:04:50 +08:00
Util.removeCard(changShaCardInhand, card, 4);
2026-01-05 19:40:49 +08:00
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", id);
client.send("612", params, response -> {
});
return "开杠";
2026-01-30 16:04:50 +08:00
} else {
2026-01-05 19:40:49 +08:00
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
client.send("612", params, response -> {
});
return "不开杠";
}
}
if (type == 5) {
//Util.removeCard(changShaCardInhand,card,1);
2026-01-30 16:04:50 +08:00
Util.removeCard(gangusecars, card, 1);
List<Integer> shifoutingpai5 = changShaSuanFaTest.handscardshifoutingpai(gangusecars, chowGroup, pongGroup, gangdepai);
2026-01-05 19:40:49 +08:00
if (shifoutingpai5.size() > 0) {
//开杠
2026-01-08 19:43:31 +08:00
//判断是否杠了之后没有牌可以听
List<Integer> allList = new ArrayList<>();
allList.addAll(changShaCardInhand);
allList.addAll(changShachuguopai);
2026-01-30 16:04:50 +08:00
int jutingnum = changShaSuanFaTest.getTingPainum(shifoutingpai5, allList);
if (jutingnum == 0) {
2026-01-08 19:43:31 +08:00
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
client.send("612", params, response -> {
});
return "不开杠";
}
2026-01-30 16:04:50 +08:00
Util.removeCard(changShaCardInhand, card, 1);
2026-01-05 19:40:49 +08:00
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", id);
client.send("612", params, response -> {
});
return "开杠";
2026-01-30 16:04:50 +08:00
} else {
2026-01-05 19:40:49 +08:00
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
client.send("612", params, response -> {
});
return "不开杠";
}
}
}
}
//判断是否是大胡
int beforeIsDahu = 0;
2026-01-22 18:16:18 +08:00
2026-01-30 16:04:50 +08:00
beforeIsDahu = changShaSuanFaTest.checkDahu(yupanhandcard, chowGroup, pongGroup, gangdepai);
System.out.println("bef:" + beforeIsDahu);
2026-01-05 19:40:49 +08:00
//5、门清
2026-01-30 16:04:50 +08:00
if (yupanhandcard.size() == 13 && beforelisten) {
2026-01-05 19:40:49 +08:00
beforeIsDahu = 5;//门清
}
//操作之前出现的牌
List<Integer> allSeeCard = new ArrayList<>();
2026-01-30 16:04:50 +08:00
Map<Integer, ITObject> pingfenResult = new HashMap<>();
Map<Integer, ITObject> idObject = new HashMap<>();
2026-01-22 18:16:18 +08:00
2026-01-05 19:40:49 +08:00
//int bupaiid = 0;//补牌id
for (int i = 0; i < tipList.size(); i++) {
TObject firstTip = (TObject) tipList.get(i).getObject();
int type = firstTip.getInt("type");
int id = firstTip.getInt("id");
int weight = firstTip.getInt("weight");
card = firstTip.getInt("card");
ITArray opcard = TArray.newInstance();
opcard = firstTip.getTArray("opcard");
2026-01-30 16:04:50 +08:00
if (type == 6) {
2026-01-05 19:40:49 +08:00
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", id);
client.send("612", params, response -> {
});
return "胡牌";
}
//if((type==4||type==5||type==6)&&weight==3){
2026-01-30 16:04:50 +08:00
// bupaiid = id;
// }
2026-01-05 19:40:49 +08:00
//对应的数据
ITObject tmp = new TObject();
//处理听的结果
switch (type) {
case 1:
//吃
2026-01-30 16:04:50 +08:00
tmp = changShaSuanFaTest.pingguChi(beforelisten, card, opcard, yupanhandcard, beforeIsDahu, allSeeCard, chowGroup, pongGroup, gangdepai, changShachuguopai);
2026-01-05 19:40:49 +08:00
break;
case 2:
//碰
2026-01-30 16:04:50 +08:00
tmp = changShaSuanFaTest.pingguPeng(beforelisten, card, opcard, yupanhandcard, beforeIsDahu, allSeeCard, chowGroup, pongGroup, gangdepai, changShachuguopai);
2026-01-05 19:40:49 +08:00
break;
default:
break;
}
//记录下来事件
2026-01-30 16:04:50 +08:00
if (tmp.size() > 0) {
pingfenResult.put(id, tmp);
2026-01-05 19:40:49 +08:00
}
ITObject sj = new TObject();
sj.putInt("weight", weight);
2026-01-22 18:16:18 +08:00
sj.putInt("type", type);
2026-01-05 19:40:49 +08:00
sj.putTArray("opcard", opcard);
2026-01-30 16:04:50 +08:00
idObject.put(id, sj);
2026-01-05 19:40:49 +08:00
}
//计算分数
System.out.println(pingfenResult);
2026-01-30 16:04:50 +08:00
if (pingfenResult.size() > 0) {
int changeid = changShaSuanFaTest.suanfen(pingfenResult);
System.out.println("changeid:" + changeid);
2026-01-05 19:40:49 +08:00
//选择最优的分数
2026-01-30 16:04:50 +08:00
if (changeid == 0) {
2026-01-05 19:40:49 +08:00
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
client.send("612", params, response -> {
});
return null;
2026-01-30 16:04:50 +08:00
} else {
2026-01-05 19:40:49 +08:00
//获取
2026-01-30 16:04:50 +08:00
for (Map.Entry<Integer, ITObject> entry : idObject.entrySet()) {
if (entry.getKey() == changeid) {
2026-01-05 19:40:49 +08:00
ITObject tmp = entry.getValue();
2026-01-22 18:16:18 +08:00
System.out.println("tmp ++++++++++= " + tmp);
2026-01-30 16:04:50 +08:00
if (tmp.getInt("type") == 2) {
2026-01-05 19:40:49 +08:00
//碰
ITArray outcards = tmp.getTArray("opcard");
for (int i = 0; i < outcards.size(); i++) {
2026-01-30 16:04:50 +08:00
Util.removeCard(changShaCardInhand, outcards.getInt(0), 2);
2026-01-05 19:40:49 +08:00
}
2026-01-22 18:16:18 +08:00
pongGroup.add(outcards.getInt(0));
pongGroup.add(outcards.getInt(0));
pongGroup.add(outcards.getInt(0));
2026-01-30 16:04:50 +08:00
} else if (tmp.getInt("type") == 1) {
2026-01-05 19:40:49 +08:00
//吃
ITArray outcards = tmp.getTArray("opcard");
for (int i = 0; i < outcards.size(); i++) {
2026-01-30 16:04:50 +08:00
Util.removeCard(changShaCardInhand, outcards.getInt(i), 1);
2026-01-05 19:40:49 +08:00
}
2026-01-22 18:16:18 +08:00
System.out.println("判断吃 +++++++++" + card);
System.out.println("判断吃 ==========" + outcards);
chowGroup.add(card);
chowGroup.add(outcards.getInt(0));
chowGroup.add(outcards.getInt(1));
2026-01-05 19:40:49 +08:00
}
}
}
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", changeid);
client.send("612", params, response -> {
});
return null;
}
}
//计算牌数
//如果 不吃,不碰,而且差三手牌情况,则补
//if (bupaiid>0) {
for (int i = 0; i < tipList.size(); i++) {
TObject firstTip = (TObject) tipList.get(i).getObject();
int type = firstTip.getInt("type");
int id = firstTip.getInt("id");
int weight = firstTip.getInt("weight");
card = firstTip.getInt("card");
Map<String, Object> map = new HashMap<>();
List<Integer> tmpChangSch = new ArrayList<>();
tmpChangSch.addAll(yupanhandcard);
ChangshaWinSplitCard.checkNormalHu(tmpChangSch, map);
2026-01-22 18:16:18 +08:00
System.out.println("要不要补map:" + map);
Map<String, Object> map2 = new HashMap<>();
List<Integer> tmpChangSch2 = new ArrayList<>();
tmpChangSch2.addAll(yupanhandcard);
if (type == 3) {
2026-01-30 16:04:50 +08:00
Util.removeCard(tmpChangSch2, card, 3);
} else if (type == 4) {
Util.removeCard(tmpChangSch2, card, 3);
} else if (type == 5) {
Util.removeCard(tmpChangSch2, card, 4);
2026-01-22 18:16:18 +08:00
}
ChangshaWinSplitCard.checkNormalHu(tmpChangSch2, map2);
System.out.println("要不要补map2:" + map2);
System.out.println(yupanhandcard);
//假设补牌
//如果下听不能不能补牌
2026-01-30 16:04:50 +08:00
if (beforelisten) {
2026-01-22 18:16:18 +08:00
System.out.println("b补");
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
client.send("612", params, response -> {
});
return null;
}
2026-01-27 16:17:47 +08:00
//去一张下听?
2026-01-30 16:04:50 +08:00
Map<Integer, List<Integer>> afterDahuOpbg = changShaSuanFaTest.quyizhangDahuTingPai(yupanhandcard, chowGroup, pongGroup, gangdepai);
Map<Integer, List<Integer>> afterOpbg = changShaSuanFaTest.quyizhangTingPai(yupanhandcard);
if (type == 4) {
2026-01-27 16:17:47 +08:00
if (afterDahuOpbg.size() > 0 || afterOpbg.size() > 0) {
System.out.println("bs补");
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
client.send("612", params, response -> {
});
return null;
}
}
2026-01-05 19:40:49 +08:00
2026-01-30 16:04:50 +08:00
if (map.size() > 0 && weight == 3) {
2026-01-05 19:40:49 +08:00
2026-01-22 18:16:18 +08:00
if (map2.size() > 0) {
//判断补牌后
2026-01-30 16:04:50 +08:00
if (Integer.parseInt(map2.get("remainingMelds").toString()) > Integer.parseInt(map.get("remainingMelds").toString()) && Integer.parseInt(map.get("remainingMelds").toString()) <= 2) {
2026-01-22 18:16:18 +08:00
System.out.println("b补");
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
client.send("612", params, response -> {
});
return null;
2026-01-30 16:04:50 +08:00
} else {
2026-01-24 18:44:34 +08:00
//判断七对
2026-01-30 16:04:50 +08:00
int dh = changShaSuanFaTest.checkDahu(yupanhandcard, chowGroup, pongGroup, gangdepai);
if (dh > 0) {
2026-01-24 18:44:34 +08:00
System.out.println("不补");
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
client.send("612", params, response -> {
});
return null;
}
2026-01-22 18:16:18 +08:00
System.out.println("补");
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", id);
if (type == 3) {
Util.removeCard(changShaCardInhand, card, 3);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
}
if (type == 4) {
Util.removeCard(changShaCardInhand, card, 4);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
}
if (type == 5) {
Util.removeCard(changShaCardInhand, card, 1);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
}
client.send("612", params, response -> {
});
return null;
}
/*if (Integer.parseInt(map.get("remainingMelds").toString()) > 2) {
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", id);
if (type == 3) {
Util.removeCard(changShaCardInhand, card, 3);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
}
if (type == 4) {
Util.removeCard(changShaCardInhand, card, 4);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
}
if (type == 5) {
Util.removeCard(changShaCardInhand, card, 1);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
}
client.send("612", params, response -> {
});
return null;
} else {
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
client.send("612", params, response -> {
});
return null;
}
*/
2026-01-30 16:04:50 +08:00
} else {
2026-01-05 19:40:49 +08:00
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", id);
if (type == 3) {
2026-01-22 18:16:18 +08:00
Util.removeCard(changShaCardInhand, card, 3);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
2026-01-05 19:40:49 +08:00
}
if (type == 4) {
2026-01-22 18:16:18 +08:00
Util.removeCard(changShaCardInhand, card, 4);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
2026-01-05 19:40:49 +08:00
}
if (type == 5) {
2026-01-22 18:16:18 +08:00
Util.removeCard(changShaCardInhand, card, 1);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
gangdepai.add(card);
2026-01-05 19:40:49 +08:00
}
client.send("612", params, response -> {
});
return null;
}
}
}
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
client.send("612", params, response -> {
});
return null;
}
public String actionCardBak2(ITObject param, TaurusClient client) {
ITArray tipList = param.getTArray("tip_list");
2026-01-30 16:04:50 +08:00
// log.info("tipList" +tipList);
2026-01-05 19:40:49 +08:00
//tipList[{opcard=[207, 208], weight=1, id=1, type=1, card=206}]
boolean chiflag = false;//吃
boolean pengflag = false; //碰
boolean bupai = false; //补
boolean minggang = false; //杠
boolean angang = false; //暗杠
boolean penggang = false; //开杠
int card = 0;//当前 消息的牌
ITObject params = TObject.newInstance();
for (int i = 0; i < tipList.size(); i++) {
TObject firstTip = (TObject) tipList.get(i).getObject();
int type = firstTip.getInt("type");
int id = firstTip.getInt("id");
int weight = firstTip.getInt("weight");
card = firstTip.getInt("card");
2026-01-30 16:04:50 +08:00
if (type == 6) {
2026-01-05 19:40:49 +08:00
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", id);
client.send("612", params, response -> {
});
return "胡牌";
}
2026-01-30 16:04:50 +08:00
if (type == 1) {
2026-01-05 19:40:49 +08:00
chiflag = true;
}
2026-01-30 16:04:50 +08:00
if (type == 2) {
2026-01-05 19:40:49 +08:00
pengflag = true;
}
2026-01-30 16:04:50 +08:00
if (type == 3 && weight == 3) {
2026-01-05 19:40:49 +08:00
//补
bupai = true;
}
2026-01-30 16:04:50 +08:00
if (type == 3 && weight == 4) {
2026-01-05 19:40:49 +08:00
//杠
minggang = true;
}
2026-01-30 16:04:50 +08:00
if (type == 5) {
2026-01-05 19:40:49 +08:00
penggang = true;
}
}
2026-01-22 18:16:18 +08:00
/*
2026-01-05 19:40:49 +08:00
//如果吃,没有碰
if (chiflag&&!pengflag){
chiNoPeng(tipList,card,client);
}
//如果有吃有碰
if (chiflag&&pengflag&&!minggang&&!penggang){
chiOrPeng(tipList,card,client);
}
//没有吃,有碰
if (!chiflag&&penggang&&!minggang&&!angang){
pengNoChi(tipList,card,client);
}
if (bupai&&!penggang&&!angang){
//补
}
//杠
if (minggang||bupai||penggang){
gangNoChiPeng(tipList,card,client);
2026-01-22 18:16:18 +08:00
}*/
2026-01-05 19:40:49 +08:00
return null;
}
/**
*
* @param tipList
* @param client
*/
2026-01-22 18:16:18 +08:00
/*
2026-01-05 19:40:49 +08:00
public int chiNoPeng(ITArray tipList,int card,TaurusClient client){
ITObject params = TObject.newInstance();
params.putString("session", session + "," + token);
//判断是否能吃
//1、吃之后能否下听
List<Integer> shifoutingpai = TinHuChi.shifoutingpai(changShaCardInhand);
if (shifoutingpai.size() == 0) {
//没下听
//如果吃了可以立马下听,则吃
int chitingpaiid = changShaSuanFaTest.checkChiTingAction(card,changShaCardInhand);
if (chitingpaiid>0){
//处理吃后的数据
params.putInt("qi", 0);
params.putInt("id", chitingpaiid-1);
//记录吃掉的牌
List<List<Integer>> lists = new ArrayList<>();
lists.addAll(TinHuChi.checkChi(changShaCardInhand, card));
List<Integer> integers = lists.get(chitingpaiid-1);
List<Integer> result1 = getOtherCards1(integers, card);
chowGroup.add(card);
chowGroup.add(result1.get(0));
chowGroup.add(result1.get(1));
changShaCardInhand.add(card);
Util.removeCard(changShaCardInhand,result1.get(0),1);
Util.removeCard(changShaCardInhand,result1.get(1),1);
Util.removeCard(changShaCardInhand,card,1);
client.send("612", params, response -> {});
return chitingpaiid;
}
//2、吃之后是否没了大胡
//判断是否满足7对
int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);
if (pisCardsCount>=4){
params.putInt("qi", 0);
params.putInt("id", 0);
}else{
//判断是否可以执行 清一色操作
boolean isChow = changShaSuanFaTest.checkAllSameSuitAll(card,changShaCardInhand,pongGroup,chowGroup,gangdepai);
if (isChow){
//判断是否可以吃
//判断吃之后是否会破坏下听
//3、吃之后是否破坏牌型
int canchiId = changShaSuanFaTest.checkCanChiAction(card,changShaCardInhand);
if (canchiId>0){
params.putInt("qi", 0);
params.putInt("id", canchiId-1);
//记录吃掉的牌
List<List<Integer>> lists = new ArrayList<>();
lists.addAll(TinHuChi.checkChi(changShaCardInhand, card));
List<Integer> integers2 = lists.get(canchiId-1);
List<Integer> result2 = getOtherCards1(integers2, card);
chowGroup.add(card);
chowGroup.add(result2.get(0));
chowGroup.add(result2.get(1));
changShaCardInhand.add(card);
Util.removeCard(changShaCardInhand,result2.get(0),1);
Util.removeCard(changShaCardInhand,result2.get(1),1);
Util.removeCard(changShaCardInhand,card,1);
client.send("612", params, response -> {});
return chitingpaiid;
}else{
params.putInt("qi", 0);
params.putInt("id", 0);
}
}else{
//不可以吃
params.putInt("qi", 0);
params.putInt("id", 0);
}
}
}else{
//不吃
//吃之后没有下听
params.putInt("qi", 0);
params.putInt("id", 0);
}
client.send("612", params, response -> {});
return 0;
}
2026-01-22 18:16:18 +08:00
*/
2026-01-05 19:40:49 +08:00
/**
*
* @param tipList
* @param client
*/
2026-01-22 18:16:18 +08:00
/*
2026-01-05 19:40:49 +08:00
public void chiOrPeng(ITArray tipList,int card,TaurusClient client){
ITObject params = TObject.newInstance();
//判断碰和吃
//判断牌型是否下听
params.putString("session", session + "," + token);
List<Integer> shifoutingpai = TinHuChi.shifoutingpai(changShaCardInhand);
if (shifoutingpai.size() == 0) {
//1、先判断是否碰之后破坏听牌
//2、如果能碰则进入判断吃逻辑对比吃、碰那个会更优
//3、判断吃或者碰之后都会破坏听牌不能吃和碰
}else{
//有下听 先不做操作,后续判断换牌
params.putInt("qi", 0);
params.putInt("id", 0);
}
client.send("612", params, response -> {});
}
/**
*
* @param tipList
* @param client
*/
2026-01-22 18:16:18 +08:00
/*
2026-01-05 19:40:49 +08:00
public void pengNoChi(ITArray tipList,int card,TaurusClient client){
ITObject params = TObject.newInstance();
client.send("612", params, response -> {});
2026-01-22 18:16:18 +08:00
}*/
2026-01-05 19:40:49 +08:00
/**
*
* @param tipList
* @param client
*/
2026-01-22 18:16:18 +08:00
/*
2026-01-05 19:40:49 +08:00
public void gangNoChiPeng(ITArray tipList,int card,TaurusClient client){
ITObject params = TObject.newInstance();
client.send("612", params, response -> {});
}
2026-01-22 18:16:18 +08:00
*/
2026-01-30 16:04:50 +08:00
2026-01-01 07:54:30 +08:00
/**
*
*
2026-01-30 16:04:50 +08:00
* @param
2026-01-01 07:54:30 +08:00
* @return
*/
2026-01-22 18:16:18 +08:00
/*
2026-01-05 19:40:49 +08:00
public String actionCardbak(ITObject param, TaurusClient client) {
2026-01-01 07:54:30 +08:00
TinHuPeng tinHuPeng = new TinHuPeng();
//获取碰杠胡参数 type 和id 后续算法接入,是否能让碰和杠
ITArray tipList = param.getTArray("tip_list");
2026-01-05 19:40:49 +08:00
2026-01-01 07:54:30 +08:00
int id = 0;
int type = 0;
int opcard = 0;
int opcard1 = 0;
int card = 0;
//胡牌
ITObject params = TObject.newInstance();
for (int i = 0; i < tipList.size(); i++) {
TObject firstTip = (TObject) tipList.get(i).getObject();
id = firstTip.getInt("id");
type = firstTip.getInt("type");
ITArray opcard2 = firstTip.getTArray("opcard");
if (type == 6) {
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", id);
client.send("612", params, response -> {
});
return "胡牌";
}
}
//吃杠
int type2 = 0;
int opcard3 = 0;
int id3 = 0;
List<Integer> gangCardInhand = new ArrayList<>();
gangCardInhand.addAll(changShaCardInhand);
gangCardInhand.addAll(chowGroup);
gangCardInhand.addAll(pongGroup);
TingPaiChecker.TingResult tingResult = TingPaiChecker.checkTingPai(gangCardInhand);
if (tingResult.isTingPai()) { //听牌状态
for (int i = 0; i < tipList.size(); i++) {
TObject firstTip = (TObject) tipList.get(i).getObject();
type2 = firstTip.getInt("type");
opcard3 = firstTip.getTArray("opcard").getInt(0);
id3 = firstTip.getInt("id");
boolean b = TinHuGang.canGang(gangCardInhand, opcard3, true); //杠牌后是否还能听牌
if (type2 == 3) {
// int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);
// boolean gang = isAllSameSuitgang(changShaCardInhand, opcard3);
if (b) {
System.out.println("听牌 +++进入吃杠===============================------------------------------------------------");
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", id3);
Util.removeCard(changShaCardInhand, opcard3, 3);
client.send("612", params, response -> {
});
return "吃杠";
} else {
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
client.send("612", params, response -> {
});
}
}
}
} else {
for (int i = 0; i < tipList.size(); i++) {
TObject firstTip = (TObject) tipList.get(i).getObject();
type2 = firstTip.getInt("type");
opcard3 = firstTip.getTArray("opcard").getInt(0);
id3 = firstTip.getInt("id");
if (type2 == 3) {
// int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);
// boolean gang = isAllSameSuitgang(changShaCardInhand, opcard3);
// if (pisCardsCount < 5 && gang) { //不是七小对和清一色的情况下 才允许杠
// System.out.println("没有 +++ 听牌 +++进入吃杠===============================------------------------------------------------");
//
// params.putString("session", session + "," + token);
// params.putInt("qi", 0);
// params.putInt("id", id3);
// Util.removeCard(changShaCardInhand, opcard3, 3);
//
// client.send("612", params, response -> {
//
// });
// return "吃杠";
// } else {
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
client.send("612", params, response -> {
});
}
}
}
TingPaiChecker.TingResult tingResult1 = TingPaiChecker.checkTingPai(gangCardInhand);
if (tingResult1.isTingPai()) {
for (int i = 0; i < tipList.size(); i++) {
TObject firstTip = (TObject) tipList.get(i).getObject();
type2 = firstTip.getInt("type");
opcard3 = firstTip.getTArray("opcard").getInt(0);
id3 = firstTip.getInt("id");
boolean c = TinHuGang.canGang(gangCardInhand, opcard3, false); //杠牌后是否还能听牌
if (type2 == 4) {
System.out.println("最新自杠 还没进入下面但是类型为4自杠了===========================");
if (c) {
System.out.println("听牌 +++进入自杠===============================------------------------------------------------");
System.out.println("opcard3 ++++++++++++++++++ ++++++++++888 " + opcard3);
System.out.println("id3 ++++++++++++++++++ ++++++++++7777 " + id3);
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", id3);
Util.removeCard(changShaCardInhand, opcard3, 4);
client.send("612", params, response -> {
});
return "自杠";
} else {
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
client.send("612", params, response -> {
});
}
}
}
} else {
for (int i = 0; i < tipList.size(); i++) {
TObject firstTip = (TObject) tipList.get(i).getObject();
type2 = firstTip.getInt("type");
if (type2 == 4) {
System.out.println("放弃自杠111=======================================");
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
client.send("612", params, response -> {
});
}
}
}
// for (int i = 0; i < tipList.size(); i++) {
// TObject firstTip = (TObject) tipList.get(i).getObject();
// type2 = firstTip.getInt("type");
// opcard3 = firstTip.getTArray("opcard").getInt(0);
// id3 = firstTip.getInt("id");
//
// if (type2 == 3) {
// int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);
// boolean gang = isAllSameSuitgang(changShaCardInhand, opcard3);
// if (pisCardsCount < 5 && gang) { //不是七小对和清一色的情况下 才允许杠
// params.putString("session", session + "," + token);
// params.putInt("qi", 0);
// params.putInt("id", id3);
// Util.removeCard(changShaCardInhand, opcard3, 3);
//
// client.send("612", params, response -> {
//
// });
// return "吃杠";
// } else {
// params.putString("session", session + "," + token);
// params.putInt("qi", 0);
// params.putInt("id", 0);
// client.send("612", params, response -> {
//
// });
//
// }
// }
// }
int id1 = 0;
int type1 = 0;
//吃牌判断
boolean b = false;
//碰牌判断
boolean a = false;
if (tipList.size() > 0) {
TObject firstTip = (TObject) tipList.get(0).getObject();
id1 = firstTip.getInt("id");
type1 = firstTip.getInt("type");
ITArray opcard2 = firstTip.getTArray("opcard");
card = firstTip.getInt("card");
b = TinHuChi.canChi(changShaCardInhand, card);
List<List<Integer>> lists = TinHuChi.checkChi(changShaCardInhand, card);
opcard = firstTip.getTArray("opcard").getInt(0);
if (type1 == 1) {
opcard1 = firstTip.getTArray("opcard").getInt(1);
}
}
2026-01-02 02:19:59 +08:00
System.out.println("进入吃type:" + type1);
2026-01-01 07:54:30 +08:00
if (type1 == 2) {
2026-01-02 02:19:59 +08:00
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) {
//判断是否满足7对
int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);
if (pisCardsCount >= 5) {
2026-01-01 07:54:30 +08:00
2026-01-02 02:19:59 +08:00
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("听牌的时候先不碰++++++++++++++++++++++++++++++++");
2026-01-01 07:54:30 +08:00
params.putString("session", session + "," + token);
params.putInt("qi", 1);
params.putInt("id", 0);
}
}
// a = tinHuPeng.canPeng(changShaCardInhand, opcard);
// ChangShaSuanFaTest changShaSuanFaTest = new ChangShaSuanFaTest();
// int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);//分析七小对
// boolean peng = changShaSuanFaTest.isAllSameSuit1(changShaCardInhand);
// if (a && !ChangShaSuanFaTest.isTin) {
// 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 (shouldPong(opcard) && pisCardsCount < 5 && !peng && !isTinPeng) {
// 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 {
// params.putString("session", session + "," + token);
// params.putInt("qi", 1); // 放弃碰牌
// params.putInt("id", 0);
//
// }
// }
} else if (type1 == 3) {
2026-01-01 22:27:34 +08:00
2026-01-01 07:54:30 +08:00
int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);//分析七小对
boolean gang = changShaSuanFaTest.isAllSameSuit1(changShaCardInhand);
if (pisCardsCount < 5 && !gang) {
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", id1);
Util.removeCard(changShaCardInhand, opcard, 3);
} else {
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
}
} else if (type1 == 1) {
// int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);//分析七小对
2026-01-01 22:27:34 +08:00
boolean isChow = changShaSuanFaTest.isAllSameSuit1(changShaCardInhand);
2026-01-02 02:19:59 +08:00
if (isChow) {
2026-01-01 22:27:34 +08:00
params.putString("session", session + "," + token);
params.putInt("qi", 1);
params.putInt("id", 0);
2026-01-02 02:19:59 +08:00
} else {
2026-01-01 07:54:30 +08:00
2026-01-01 22:27:34 +08:00
//判断当前手牌是否已经听牌 已经听牌了就不要再吃牌了
List<Integer> shifoutingpai = TinHuChi.shifoutingpai(changShaCardInhand);
2026-01-01 07:54:30 +08:00
2026-01-01 22:27:34 +08:00
//目前手牌没有听牌
if (shifoutingpai.size() == 0) {
2026-01-01 07:54:30 +08:00
2026-01-01 22:27:34 +08:00
//判断是否满足7对
int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);
if (pisCardsCount >= 5) {
2026-01-01 07:54:30 +08:00
2026-01-01 22:27:34 +08:00
params.putString("session", session + "," + token);
params.putInt("qi", 1);
params.putInt("id", 0);
2026-01-01 07:54:30 +08:00
2026-01-01 22:27:34 +08:00
} else {
List<List<Integer>> lists = new ArrayList<>();
lists.addAll(TinHuChi.checkChi(changShaCardInhand, card));
int index = 0;
int flag = 0;
for (List<Integer> list : lists) {
List<Integer> temphand = new ArrayList<>();
temphand.addAll(changShaCardInhand);
temphand.add(card);
Util.removeCard(temphand, list.get(0), 1);
Util.removeCard(temphand, list.get(1), 1);
Util.removeCard(temphand, list.get(2), 1);
List<Integer> checktingpai1 = TinHuChi.checktingpai(temphand);
if (checktingpai1.size() > 0) {
flag = index + 1;
2026-01-01 07:54:30 +08:00
}
2026-01-01 22:27:34 +08:00
index++;
System.out.println("checktingpai1 吃牌 " + checktingpai1);
2026-01-01 07:54:30 +08:00
}
2026-01-02 02:19:59 +08:00
2026-01-01 22:27:34 +08:00
// TODO: 2026/1/1
// 1.需要补充 没听牌也可以吃 但是吃之后要比吃之前的手牌强 也就是可听数量变多
// 2.听牌后也能吃牌,要比吃之前的牌强
// 3.碰也一样要加
if (flag > 0) {
System.out.println("===============进入听胡吃牌================== ++++ " + flag);
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", flag);
int index1 = flag - 1;
List<Integer> integers = lists.get(index1);
List<Integer> result1 = getOtherCards1(integers, card);
chowGroup.add(card);
chowGroup.add(result1.get(0));
chowGroup.add(result1.get(1));
changShaCardInhand.add(card);
Util.removeCard(changShaCardInhand, integers.get(0), 1);
Util.removeCard(changShaCardInhand, integers.get(1), 1);
Util.removeCard(changShaCardInhand, integers.get(2), 1);
} else {
Map<String, Object> map = new HashMap<>();
Map<String, Object> map2 = new HashMap<>();
//吃之前的逻辑
List<List<Integer>> lists1 = TinHuChi.checkChi(changShaCardInhand, card);
int jiangnum = checkduijiang(changShaCardInhand);
List<Integer> tmpChangSch = new ArrayList<>();
tmpChangSch.addAll(changShaCardInhand);
tmpChangSch.add(card);
ChangshaWinSplitCard.checkNormalHu(tmpChangSch, map);
System.out.println("checkNormalHu" + map.get("cardResiue"));
System.out.println("checktingpai1" + lists1);
int index1 = 0;
int flag1 = 0;
for (List<Integer> list : lists1) {
List<Integer> temphand = new ArrayList<>();
temphand.addAll(tmpChangSch);
Util.removeCard(temphand, list.get(0), 1);
Util.removeCard(temphand, list.get(1), 1);
Util.removeCard(temphand, list.get(2), 1);
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())) {
flag1 = index1 + 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) {
flag1 = index1 + 1;
}
//如果手里没有将,则可以吃
if (jiangnum > 0) {
int chihoujiangnum = checkduijiang(temphand);
if (chihoujiangnum > 0) {
//吃之后还有将
flag1 = index1 + 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(card)) {
//吃
break;
}
flag1 = index1 + 1;
// break;
}
}
index1++;
}
2026-01-01 07:54:30 +08:00
2026-01-01 22:27:34 +08:00
if (flag1 > 0) {
System.out.println("flag1:" + flag1);
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", flag1);
int index2 = flag1 - 1;
if (index2 >= lists.size()) {
index2 = 0;
}
System.out.println("index2:" + index2);
System.out.println("lists:" + lists);
List<Integer> integers = new ArrayList<>();
integers.addAll(lists.get(index2));
List<Integer> result2 = getOtherCards1(integers, card);
chowGroup.add(card);
chowGroup.add(result2.get(0));
chowGroup.add(result2.get(1));
changShaCardInhand.add(card);
Util.removeCard(changShaCardInhand, integers.get(0), 1);
Util.removeCard(changShaCardInhand, integers.get(1), 1);
Util.removeCard(changShaCardInhand, integers.get(2), 1);
} else {
params.putString("session", session + "," + token);
params.putInt("qi", 1);
params.putInt("id", 0);
}
}
2026-01-01 07:54:30 +08:00
}
}
2026-01-01 22:27:34 +08:00
//听牌的时候先不吃
if (shifoutingpai.size() > 0) {
System.out.println("听牌的时候先不吃++++++++++++++++++++++++++++++++");
params.putString("session", session + "," + token);
params.putInt("qi", 1);
params.putInt("id", 0);
}
2026-01-01 07:54:30 +08:00
// if (b && TinHuChi.isMoreThanLast() && !ChangShaSuanFaTest.isTin) {
//
// System.out.println("===============进入听胡吃牌==================");
// params.putString("session", session + "," + token);
// params.putInt("qi", 0);
// params.putInt("id", 1);
//
// chowGroup.add(card);
// chowGroup.add(opcard);
// chowGroup.add(opcard1);
//// changShachuguopai.add(card);
// Util.removeCard(changShaCardInhand, opcard, 1);
// Util.removeCard(changShaCardInhand, opcard1, 1);
//// }else {
//// params.putString("session", session + "," + token);
//// params.putInt("qi", 1);
//// params.putInt("id", 0);
//// }
// } else {
// System.out.println("isTin ++++++++++++++++++++++++++++++++++++" + isTinChi);
// if (shouldChow(card) && pisCardsCount < 5 && !isChow && !isTinChi) {
// params.putString("session", session + "," + token);
// params.putInt("qi", 0);
// params.putInt("id", 1);
// chowGroup.add(card);
// chowGroup.add(opcard);
// chowGroup.add(opcard1);
//
// Util.removeCard(changShaCardInhand, opcard, 1);
// Util.removeCard(changShaCardInhand, opcard1, 1);
// } else {
// params.putString("session", session + "," + token);
// params.putInt("qi", 1);
// params.putInt("id", 0);
// }
// }
2026-01-01 22:27:34 +08:00
//自杠
2026-01-01 07:54:30 +08:00
// } else if (type1 == 4) {
//// TingPaiChecker.TingResult tingResult1 = TingPaiChecker.checkTingPai(gangCardInhand);
//
// if (tingResult1.isTingPai()) {
// boolean c = TinHuGang.canGang(gangCardInhand, opcard, false); //杠牌后是否还能听牌
// if (c) {
// System.out.println("听牌 +++进入自杠===============================------------------------------------------------");
//
// params.putString("session", session + "," + token);
// params.putInt("qi", 0);
// params.putInt("id", 1);
// Util.removeCard(changShaCardInhand, opcard, 4);
//
// } else {
// params.putString("session", session + "," + token);
// params.putInt("qi", 0);
// params.putInt("id", 0);
// }
// } else {
//// int pisCardsCount = changShaSuanFaTest.countPairs(changShaCardInhand);//分析七小对
//// boolean gang = changShaSuanFaTest.isAllSameSuit1(changShaCardInhand);
//// if (pisCardsCount < 5 && !gang) {
// System.out.println("没有 +++ 听牌 +++进入自杠===============================------------------------------------------------");
////
//// params.putString("session", session + "," + token);
//// params.putInt("qi", 0);
//// params.putInt("id", 1);
//// Util.removeCard(changShaCardInhand, opcard, 4);
//// } else {
// params.putString("session", session + "," + token);
// params.putInt("qi", 0);
// params.putInt("id", 0);
//// }
//
// }
//
//
// // 碰后补杠
// }
2026-01-01 22:27:34 +08:00
}
2026-01-01 07:54:30 +08:00
} else if (type1 == 5) {
params.putString("session", session + "," + token);
params.putInt("qi", 0);
params.putInt("id", 0);
// Util.removeCard(changShaCardInhand, opcard, 1);
// }
}
client.send("612", params, response -> {
});
return null;
}
2026-01-22 18:16:18 +08:00
*/
2026-01-01 07:54:30 +08:00
public static List<Integer> getOtherCards1(List<Integer> integers, int card) {
List<Integer> result = new ArrayList<>();
for (Integer num : integers) {
if (num != card) {
result.add(num);
}
}
return result;
}
public static boolean isAllSameSuitgang(List<Integer> handCards, int opcard3) {
// 统计各花色的牌数量
Map<Integer, Integer> suitCountMap = new HashMap<>();
for (Integer card : handCards) {
int suit = card / 100; // 获取花色100=万200=筒300=条
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) {
// 检查杠牌的花色是否与当前花色一致
int gangSuit = opcard3 / 100;
if (suit == gangSuit) {
return true;
} else {
return false;
}
}
}
return true;
}
public static String changePlayer(String command, Message message) {
if (command.equalsIgnoreCase("820")) {
ITObject param = message.param;
if (param == null) {
return null;
}
}
return null;
}
/**
*
*/
// public String outCard(TaurusClient client, List<Integer> list) {
public String outCard(TaurusClient client, Map<Integer, List<Integer>> playerOutcardsMap, Map<Integer, List<Integer>> playerchisMap, Map<Integer,
List<Integer>> playerpengsMap, Map<Integer, List<Integer>> playermingsMap, Map<Integer, List<Integer>> playerzisMap) {
// playerOutcardsMap + playerchisMap 传到 outCardSuanFa
//对出牌进行整合
List<Integer> resultList = new ArrayList<>();
for (List<Integer> cards : playerOutcardsMap.values()) {
resultList.addAll(cards);
}
for (List<Integer> chis : playerchisMap.values()) {
resultList.addAll(chis);
}
for (List<Integer> pengs : playerpengsMap.values()) {
resultList.addAll(pengs);
}
for (List<Integer> minggangs : playermingsMap.values()) {
resultList.addAll(minggangs);
}
for (List<Integer> zigang : playerzisMap.values()) {
resultList.addAll(zigang);
}
2026-01-05 19:40:49 +08:00
// 长沙麻将出牌
2026-01-22 18:16:18 +08:00
String changShaOutCard = changShaSuanFaTest.outCardSuanFa(changShaCardInhand, pongGroup, chowGroup, gangdepai, resultList);
2026-01-01 07:54:30 +08:00
// String changShaOutCard = changShaSuanFaTest.outCardSuanFa(list, changShaCard,pongGroup);
ITObject params = TObject.newInstance();
int cardToOut;
if (StringUtil.isNotEmpty(changShaOutCard)) {
cardToOut = Integer.parseInt(changShaOutCard);
} else {
cardToOut = changShaCardInhand.get(0);
}
params.putInt("card", cardToOut);
int outCountBefore = changShachuguopai.size(); // 当前历史出牌数量
// 第n次出牌时发送前n-1张出牌
if (outCountBefore >= 1) {
// 发送前n-1张所有历史出牌
List<Integer> cardsToSend = changShachuguopai.subList(0, outCountBefore);
params.putTArray("outcard_list", CardUtil.maJiangToTArray(cardsToSend));
}
params.putTArray("card_list", CardUtil.maJiangToTArray(changShaCardInhand));
// 将当前出的牌添加到历史出牌列表
changShachuguopai.add(cardToOut);
// 从手牌中移除
changShaCardInhand.remove(Integer.valueOf(cardToOut));
params.putString("session", session + "," + token);
client.send("611", params, response -> {
});
2026-01-30 16:04:50 +08:00
2026-01-01 07:54:30 +08:00
return null;
}
/**
*
*
* @param param
* @return
*/
public String shanchuchuguopai(ITObject param) {
if (param == null) {
return null;
}
Integer card = param.getInt("card"); // 操作牌值
Integer type = param.getInt("type"); // 操作类型
Integer from_seat = param.getInt("from_seat"); // 牌来源座位
Integer playerid = param.getInt("playerid");
String sql2 = String.format("SELECT id FROM `account` WHERE jiqiren=9998");
try {
ITArray robotId2 = DataBase.use().executeQueryByTArray(sql2);
List<Integer> robotIdsList = new ArrayList<>();
for (int j = 0; j < robotId2.size(); j++) {
robotIdsList.add(robotId2.getTObject(j).getInt("id"));
}
if (!robotIdsList.contains(playerid)) {
if (type == 2 || type == 3 || type == 5 || type == 1) { // 碰,杠
getChuGuoCardInhand().remove(Integer.valueOf(card));
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
2026-01-05 19:40:49 +08:00
public static void main(String[] args) {
HuNanChangSha huNanChangSha = new HuNanChangSha();
ITObject params = TObject.newInstance();
2026-01-30 20:06:56 +08:00
TaurusClient tc = new TaurusClient("8.138.242.190", "10", TaurusClient.ConnectionProtocol.Tcp);
2026-01-05 19:40:49 +08:00
List<Integer> hands1 = new ArrayList<>();
2026-01-24 18:44:34 +08:00
hands1.add(209);
2026-01-27 16:17:47 +08:00
hands1.add(209);
hands1.add(209);
2026-01-24 18:44:34 +08:00
hands1.add(208);
2026-01-05 19:40:49 +08:00
2026-01-27 16:17:47 +08:00
hands1.add(208);
hands1.add(207);
hands1.add(207);
2026-01-11 03:00:52 +08:00
2026-01-27 16:17:47 +08:00
hands1.add(206);
hands1.add(205);
2026-01-24 18:44:34 +08:00
hands1.add(104);
2026-01-22 18:16:18 +08:00
2026-01-27 16:17:47 +08:00
hands1.add(104);
2026-01-30 16:04:50 +08:00
// hands1.add(105);
2026-01-27 16:17:47 +08:00
//hands1.add(103);
//hands1.add(102);
2026-01-05 19:40:49 +08:00
2026-01-30 16:04:50 +08:00
int card = 203;
2026-01-05 19:40:49 +08:00
huNanChangSha.changShaCardInhand.addAll(hands1);
2026-01-30 16:04:50 +08:00
TArray tiplist = new TArray();
2026-01-05 19:40:49 +08:00
ITArray opcard = TArray.newInstance();
2026-01-27 16:17:47 +08:00
opcard.addInt(102);
2026-01-30 16:04:50 +08:00
// opcard.addInt(205);
2026-01-07 20:07:36 +08:00
2026-01-30 16:04:50 +08:00
// opcard.addInt(203);
2026-01-05 19:40:49 +08:00
TObject tob = new TObject();
2026-01-30 16:04:50 +08:00
tob.putInt("weight", 3);
tob.putInt("id", 1);
tob.putInt("type", 4);
tob.putInt("card", card);
2026-01-05 19:40:49 +08:00
tob.putTArray("opcard", opcard);
2026-01-27 16:17:47 +08:00
//tiplist.addTObject(tob);
2026-01-05 19:40:49 +08:00
ITArray opcard2 = TArray.newInstance();
2026-01-30 16:04:50 +08:00
// opcard2.addInt(106);
2026-01-24 18:44:34 +08:00
opcard2.addInt(107);
2026-01-05 19:40:49 +08:00
TObject tob2 = new TObject();
2026-01-30 16:04:50 +08:00
tob2.putInt("weight", 5);
tob2.putInt("id", 2);
tob2.putInt("type", 5);
tob2.putInt("card", card);
2026-01-05 19:40:49 +08:00
tob2.putTArray("opcard", opcard2);
2026-01-30 16:04:50 +08:00
// tiplist.addTObject(tob2);
2026-01-05 19:40:49 +08:00
2026-01-07 20:07:36 +08:00
ITArray opcard3 = TArray.newInstance();
2026-01-27 16:17:47 +08:00
opcard3.addInt(204);
opcard3.addInt(205);
2026-01-07 20:07:36 +08:00
TObject tob3 = new TObject();
2026-01-30 16:04:50 +08:00
tob3.putInt("weight", 1);
tob3.putInt("id", 1);
tob3.putInt("type", 1);
tob3.putInt("card", card);
2026-01-11 03:00:52 +08:00
tob3.putTArray("opcard", opcard3);
2026-01-24 18:44:34 +08:00
tiplist.addTObject(tob3);
2026-01-07 20:07:36 +08:00
2026-01-22 18:16:18 +08:00
2026-01-30 16:04:50 +08:00
params.putTArray("tip_list", tiplist);
2026-01-05 19:40:49 +08:00
System.out.println(params);
//已经吃掉数据
2026-01-30 16:04:50 +08:00
// huNanChangSha.chowGroup.add(205);
2026-01-05 19:40:49 +08:00
//huNanChangSha.chowGroup.add(204);
2026-01-30 16:04:50 +08:00
// huNanChangSha.chowGroup.add(206);
2026-01-05 19:40:49 +08:00
//huNanChangSha.chowGroup.add(201);
2026-01-30 16:04:50 +08:00
// huNanChangSha.chowGroup.add(202);
// huNanChangSha.chowGroup.add(203);
// huNanChangSha.chowGroup.add(206);
2026-01-22 18:16:18 +08:00
//huNanChangSha.chowGroup.add(204);
//huNanChangSha.chowGroup.add(205);
2026-01-30 16:04:50 +08:00
String res = huNanChangSha.actionCard(params, tc);
2026-01-06 20:42:55 +08:00
System.out.println(res);
2026-01-05 19:40:49 +08:00
}
2026-01-01 07:54:30 +08:00
}