调整跑得快机器人出牌逻辑
parent
44e38446c7
commit
5ea1ce67d0
|
|
@ -13,6 +13,7 @@ import taurus.client.TaurusClient;
|
|||
import taurus.util.CardObj;
|
||||
import taurus.util.CardUtil;
|
||||
import taurus.util.test;
|
||||
import taurus.util.test_smart;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
|
@ -261,7 +262,7 @@ public class HuNanPaoDeKuai {
|
|||
System.out.println("当前card_list: " + card_list);
|
||||
|
||||
ITArray itArray = null;
|
||||
itArray = test.intelligentPaoDeKuaiOutCard(this, paoDekuaiCardInhand, card_list, seatRemainHistory);
|
||||
itArray = test_smart.intelligentPaoDeKuaiOutCard(this, paoDekuaiCardInhand, card_list, seatRemainHistory);
|
||||
System.out.println("itArray-----" + itArray);
|
||||
|
||||
//无法跟牌且不是下家只剩一张牌的情况 则pass
|
||||
|
|
@ -329,35 +330,72 @@ public class HuNanPaoDeKuai {
|
|||
* @return
|
||||
*/
|
||||
public String paoDekuaiChupaiGuangBo(ITObject param) {
|
||||
System.out.println("=== 出牌广播调试信息 ===");
|
||||
System.out.println("原始param: " + param);
|
||||
System.out.println("seat字段: " + param.getInt("seat"));
|
||||
System.out.println("player字段: " + param.getInt("player"));
|
||||
|
||||
//正确获取座位号
|
||||
Integer broadcastSeat = param.getInt("seat");//从seat字段获取座位号
|
||||
if (broadcastSeat != null) {
|
||||
guangboseat = broadcastSeat;
|
||||
System.out.println("使用seat字段设置guangboseat: " + guangboseat);
|
||||
} else {
|
||||
//从player字段获取座位号
|
||||
guangboseat = param.getInt("player");
|
||||
System.out.println("使用player字段设置guangboseat: " + guangboseat);
|
||||
}
|
||||
|
||||
//更新出牌信息
|
||||
ITObject cardObj = param.getTObject("card_obj");
|
||||
if (cardObj != null) {
|
||||
card_list = cardObj;
|
||||
System.out.println("更新card_list为: " + card_list);
|
||||
|
||||
// 创建新的card_list对象,确保包含所有必要字段
|
||||
card_list = TObject.newInstance();
|
||||
|
||||
// 复制card_obj中的所有字段
|
||||
if (cardObj.containsKey("card_list")) {
|
||||
card_list.putTArray("card_list", cardObj.getTArray("card_list"));
|
||||
}
|
||||
|
||||
// 确保必要的字段存在
|
||||
if (cardObj.containsKey("min_card")) {
|
||||
card_list.putInt("min_card", cardObj.getInt("min_card"));
|
||||
}
|
||||
if (cardObj.containsKey("type")) {
|
||||
card_list.putInt("type", cardObj.getInt("type"));
|
||||
}
|
||||
if (cardObj.containsKey("len")) {
|
||||
card_list.putInt("len", cardObj.getInt("len"));
|
||||
}
|
||||
|
||||
// 关键修复:根据实际牌数校验和修正type字段
|
||||
if (card_list.containsKey("card_list") && card_list.containsKey("type")) {
|
||||
int actualLen = card_list.getTArray("card_list").size();
|
||||
int reportedType = card_list.getInt("type");
|
||||
int reportedLen = card_list.getInt("len");
|
||||
|
||||
|
||||
// 根据实际牌数推断正确类型
|
||||
int inferredType = inferCorrectType(actualLen);
|
||||
if (inferredType != reportedType) {
|
||||
System.out.println("[警告] 检测到类型不匹配! 报告类型:" + getCardTypeName(reportedType) + ", 推断类型:" + getCardTypeName(inferredType));
|
||||
card_list.putInt("type", inferredType);
|
||||
}
|
||||
|
||||
// 修正长度字段
|
||||
if (reportedLen != actualLen) {
|
||||
System.out.println("[警告] 长度字段不匹配! 报告:" + reportedLen + ", 实际:" + actualLen);
|
||||
card_list.putInt("len", actualLen);
|
||||
}
|
||||
}
|
||||
// 如果len字段缺失或为0,根据实际牌数计算
|
||||
else if (card_list.containsKey("card_list")) {
|
||||
int actualLen = card_list.getTArray("card_list").size();
|
||||
card_list.putInt("len", actualLen);
|
||||
|
||||
// 同时推断类型
|
||||
int inferredType = inferCorrectType(actualLen);
|
||||
card_list.putInt("type", inferredType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
remain = param.getInt("remain"); //剩余牌数量
|
||||
saveRemainHistory(guangboseat, remain);
|
||||
System.out.println("座位号和手牌数量记录 " + seatRemainHistory);
|
||||
System.out.println("广播手牌数量" + "座位号 " + guangboseat + "手牌数量 " + remain);
|
||||
System.out.println("座位号:" + guangboseat + "的用户出牌广播:" + card_list);
|
||||
System.out.println("=======================");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -368,5 +406,47 @@ public class HuNanPaoDeKuai {
|
|||
seatRemainHistory.get(guangboseat).add(remain);
|
||||
}
|
||||
|
||||
/** 根据牌数推断正确的牌型 */
|
||||
private int inferCorrectType(int len) {
|
||||
switch (len) {
|
||||
case 1: return 1; // 单牌
|
||||
case 2: return 2; // 对子
|
||||
case 3: return 5; // 三张
|
||||
case 4: return 8; // 炸弹
|
||||
case 5: return 7; // 三带二
|
||||
case 6: return 4; // 连对(2连对=4张,3连对=6张)
|
||||
case 8: return 4; // 连对(4连对=8张)
|
||||
case 10: return 4; // 连对(5连对=10张)
|
||||
case 12: return 10; // 飞机带牌(333444+55+66)
|
||||
default:
|
||||
// 连对(偶数张牌)
|
||||
if (len >= 4 && len % 2 == 0) return 4;
|
||||
// 飞机带牌(5的倍数)
|
||||
if (len >= 10 && len % 5 == 0) return 10;
|
||||
// 顺子(5张及以上连续单牌)
|
||||
if (len >= 5) return 3;
|
||||
// 默认返回单牌
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/** 牌型数字转名称 */
|
||||
private String getCardTypeName(int type) {
|
||||
switch (type) {
|
||||
case 1: return "单牌";
|
||||
case 2: return "对子";
|
||||
case 3: return "顺子";
|
||||
case 4: return "连对";
|
||||
case 5: return "三张";
|
||||
case 7: return "三带二";
|
||||
case 8: return "炸弹";
|
||||
case 9: return "飞机";
|
||||
case 10: return "飞机带牌";
|
||||
case 11: return "四带二";
|
||||
case 12: return "四带两对";
|
||||
default: return "未知(" + type + ")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -36,12 +36,12 @@ public class test {
|
|||
int len = card_list.getInt("len");
|
||||
int type = card_list.getInt("type");
|
||||
|
||||
|
||||
|
||||
if (huNanPaoDeKuai.seat == huNanPaoDeKuai.guangboseat) {
|
||||
System.out.println("=== 座位号匹配错误检测 ===");
|
||||
System.out.println("seat=" + huNanPaoDeKuai.seat + ", guangboseat=" + huNanPaoDeKuai.guangboseat);
|
||||
System.out.println("检测到seat与guangboseat相同,可能存在状态同步问题");
|
||||
|
||||
|
||||
Map<Integer, Integer> otherSeatsLastRemain = getOtherSeatsLastRemain(seat, seatRemainHistory);
|
||||
boolean hasAnyEqualOne = otherSeatsLastRemain.values().stream().anyMatch(value -> value == 1);
|
||||
if (hasAnyEqualOne) {
|
||||
|
|
@ -2336,14 +2336,13 @@ public class test {
|
|||
/**
|
||||
* 选择最优选项(考虑出牌后手牌)
|
||||
*/
|
||||
private static PlayOptionWithRemain selectBestOptionWithRemain(List<PlayOptionWithRemain> options,
|
||||
int handSize, boolean isFirstPlay) {
|
||||
private static PlayOptionWithRemain selectBestOptionWithRemain(List<PlayOptionWithRemain> options, int handSize, boolean isFirstPlay) {
|
||||
if (options == null || options.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return options.stream()
|
||||
.max(Comparator.comparingInt(option -> option.totalScore))
|
||||
.orElse(null);
|
||||
.orElse(options.isEmpty() ? null : options.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3346,4 +3345,4 @@ public class test {
|
|||
return analysis.estimatedTurns;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue