修改三带二逻辑
parent
5ea1ce67d0
commit
6976e90e9d
|
|
@ -1557,12 +1557,13 @@ public class test_smart {
|
|||
}
|
||||
|
||||
private static List<CardObj> findConsecutivePairResponse(List<CardObj> handCards, int minCard, int len) {
|
||||
int pairCount = len / 2;
|
||||
// 修正:len表示连对的数量,不是总牌数
|
||||
int pairCount = len; // len=2表示2连对(4张牌),len=3表示3连对(6张牌)
|
||||
|
||||
System.out.println("[连对响应] 寻找" + pairCount + "连对,最小起始牌:" + getCardName(minCard));
|
||||
System.out.println("[连对响应] 寻找" + pairCount + "连对(共" + (pairCount*2) + "张牌),最小起始牌:" + getCardName(minCard));
|
||||
|
||||
if (pairCount < MIN_CONSECUTIVE_PAIR_COUNT) {
|
||||
System.out.println("对手连对数<" + MIN_CONSECUTIVE_PAIR_COUNT + ",不符合规则,无法响应");
|
||||
System.out.println("对手连对数" + pairCount + "<" + MIN_CONSECUTIVE_PAIR_COUNT + ",不符合规则,无法响应");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
|
@ -1577,7 +1578,7 @@ public class test_smart {
|
|||
|
||||
if (!validPairs.isEmpty()) {
|
||||
List<CardObj> chosenPair = validPairs.get(0);
|
||||
System.out.println("[连对响应] 选择出牌:" + chosenPair.stream().map(c -> getCardName(c.cardMod)).collect(Collectors.joining(",")));
|
||||
System.out.println("[连对响应] 选择出牌:" + chosenPair.stream().map(c -> getCardName(c.cardMod)).collect(Collectors.joining("")));
|
||||
return chosenPair;
|
||||
}
|
||||
|
||||
|
|
@ -1599,31 +1600,87 @@ public class test_smart {
|
|||
}
|
||||
|
||||
private static List<CardObj> findTrioWithTwoResponse(List<CardObj> handCards, int minCard) {
|
||||
System.out.println("[三带二响应] 寻找能压制" + getCardName(minCard) + "的三带二");
|
||||
|
||||
Map<Integer, List<CardObj>> valueGroups = CardUtil.getCardListMap(handCards);
|
||||
|
||||
// 调试信息
|
||||
System.out.println("[三带二响应] 手牌分组情况:");
|
||||
valueGroups.forEach((k, v) -> {
|
||||
System.out.println(" " + getCardName(k) + ": " + v.size() + "张");
|
||||
});
|
||||
|
||||
// 寻找三张
|
||||
Optional<Map.Entry<Integer, List<CardObj>>> trioEntry = valueGroups.entrySet().stream()
|
||||
.filter(e -> e.getKey() > minCard && e.getValue().size() >= 3)
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.findFirst();
|
||||
|
||||
if (!trioEntry.isPresent()) {
|
||||
System.out.println("[三带二响应] 未找到大于" + getCardName(minCard) + "的三张");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
System.out.println("[三带二响应] 找到三张: " + getCardName(trioEntry.get().getKey()));
|
||||
|
||||
Optional<Map.Entry<Integer, List<CardObj>>> pairEntry = valueGroups.entrySet().stream()
|
||||
.filter(e -> e.getKey() != trioEntry.get().getKey() && e.getValue().size() >= 2)
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.findFirst();
|
||||
|
||||
if (!pairEntry.isPresent()) {
|
||||
// 智能选择携带的两张牌 - 优先带走单牌
|
||||
List<CardObj> carryCards = selectOptimalCarryCards(handCards, trioEntry.get().getKey());
|
||||
|
||||
if (carryCards.size() < 2) {
|
||||
System.out.println("[三带二响应] 未找到足够的携带牌");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
System.out.println("[三带二响应] 选择携带: " + carryCards.stream().map(c -> getCardName(c.cardMod)).collect(Collectors.joining("")));
|
||||
|
||||
List<CardObj> result = new ArrayList<>(trioEntry.get().getValue().subList(0, 3));
|
||||
result.addAll(pairEntry.get().getValue().subList(0, 2));
|
||||
result.addAll(carryCards.subList(0, 2));
|
||||
|
||||
System.out.println("[三带二响应] 最终出牌: " + result.stream().map(c -> getCardName(c.cardMod)).collect(Collectors.joining("")));
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 智能选择三带二的携带牌
|
||||
* 策略:优先带走单牌,优化手牌结构
|
||||
*/
|
||||
private static List<CardObj> selectOptimalCarryCards(List<CardObj> handCards, int trioValue) {
|
||||
System.out.println("[智能携带] 分析携带牌选择策略");
|
||||
|
||||
Map<Integer, List<CardObj>> groups = CardUtil.getCardListMap(handCards);
|
||||
List<CardObj> carryCandidates = new ArrayList<>();
|
||||
|
||||
// 1. 优先选择单牌(除了三张本身)
|
||||
List<CardObj> singleCards = handCards.stream()
|
||||
.filter(c -> c.cardMod != trioValue) // 排除三张牌
|
||||
.filter(c -> groups.get(c.cardMod).size() == 1) // 只要单牌
|
||||
.sorted(Comparator.comparingInt(CardObj::getCardMod))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
System.out.println("[智能携带] 可选单牌: " + singleCards.stream().map(c -> getCardName(c.cardMod)).collect(Collectors.joining(",")));
|
||||
|
||||
if (singleCards.size() >= 2) {
|
||||
// 选择两张单牌带走
|
||||
carryCandidates.addAll(singleCards.subList(0, 2));
|
||||
System.out.println("[智能携带] 选择带走2张单牌,优化手牌结构");
|
||||
return carryCandidates;
|
||||
}
|
||||
|
||||
// 2. 如果单牌不够,选择最小的牌
|
||||
List<CardObj> otherCards = handCards.stream()
|
||||
.filter(c -> c.cardMod != trioValue)
|
||||
.sorted(Comparator.comparingInt(CardObj::getCardMod))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (otherCards.size() >= 2) {
|
||||
carryCandidates.addAll(otherCards.subList(0, 2));
|
||||
System.out.println("[智能携带] 选择带走2张最小牌");
|
||||
return carryCandidates;
|
||||
}
|
||||
|
||||
System.out.println("[智能携带] 无可选携带牌");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
private static List<CardObj> findBombResponse(List<CardObj> handCards, int minCard) {
|
||||
Map<Integer, List<CardObj>> valueGroups = CardUtil.getCardListMap(handCards);
|
||||
|
|
@ -1806,19 +1863,30 @@ public class test_smart {
|
|||
}
|
||||
|
||||
private static List<CardObj> findSmallestTrioWithTwo(List<CardObj> handCards) {
|
||||
System.out.println("[主动三带二] 寻找最优的三带二组合");
|
||||
|
||||
List<CardObj> trio = findSmallestTrio(handCards);
|
||||
if (trio.isEmpty()) return new ArrayList<>();
|
||||
if (trio.isEmpty()) {
|
||||
System.out.println("[主动三带二] 未找到三张");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
System.out.println("[主动三带二] 找到三张: " + getCardName(trio.get(0).cardMod));
|
||||
|
||||
Map<Integer, List<CardObj>> groups = CardUtil.getCardListMap(handCards);
|
||||
Optional<Map.Entry<Integer, List<CardObj>>> pairEntry = groups.entrySet().stream()
|
||||
.filter(e -> e.getKey() != trio.get(0).cardMod && e.getValue().size() >= 2)
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.findFirst();
|
||||
|
||||
if (!pairEntry.isPresent()) return new ArrayList<>();
|
||||
// 使用智能携带策略
|
||||
List<CardObj> carryCards = selectOptimalCarryCards(handCards, trio.get(0).cardMod);
|
||||
|
||||
if (carryCards.size() < 2) {
|
||||
System.out.println("[主动三带二] 未找到足够的携带牌");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
System.out.println("[主动三带二] 选择携带: " + carryCards.stream().map(c -> getCardName(c.cardMod)).collect(Collectors.joining("")));
|
||||
|
||||
List<CardObj> result = new ArrayList<>(trio);
|
||||
result.addAll(pairEntry.get().getValue().subList(0, 2));
|
||||
result.addAll(carryCards.subList(0, 2));
|
||||
|
||||
System.out.println("[主动三带二] 最终出牌: " + result.stream().map(c -> getCardName(c.cardMod)).collect(Collectors.joining("")));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -2106,7 +2174,8 @@ public class test_smart {
|
|||
boolean consecutive = isConsecutive(uniqueValues);
|
||||
|
||||
if (allPairs && consecutive) {
|
||||
System.out.println("[牌型分析] 结论: 连对 (" + (cardCount/2) + "连)");
|
||||
int pairCount = cardCount / 2;
|
||||
System.out.println("[牌型分析] 结论: 连对 (" + pairCount + "连对,共" + cardCount + "张牌)");
|
||||
return TYPE_CONSECUTIVE_PAIR;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue