|
@@ -1139,9 +1139,118 @@ public final class GDUtils {
|
|
|
*/
|
|
|
private static List<Integer> replaceWildCardsPairSequence(List<Integer> points, int wildCardCount, int curLevel) {
|
|
|
points = new ArrayList<>(points);
|
|
|
- // 计算癞子牌的数量
|
|
|
wildCardCount = Collections.frequency(points, -1);
|
|
|
- return replaceWildCardsWithTrump(points, wildCardCount, curLevel, 5);
|
|
|
+
|
|
|
+ // 统计每个点数的牌的数量
|
|
|
+ Map<Integer, Integer> cardCountMap = new HashMap<>();
|
|
|
+ //构建结果列表
|
|
|
+ List<Integer> result = new ArrayList<>();
|
|
|
+ for (int point : points) {
|
|
|
+ if (point!= -1) {
|
|
|
+ cardCountMap.put(point, cardCountMap.getOrDefault(point, 0) + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果没有癞子且已经是完整的三连对,直接返回
|
|
|
+ if (wildCardCount == 0) {
|
|
|
+ List<Integer> sortedPoints = points.stream()
|
|
|
+ .sorted(Comparator.reverseOrder())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Integer firstMax = sortedPoints.get(0);
|
|
|
+ Integer secondMax = sortedPoints.get(1);
|
|
|
+ if (firstMax == 14 && secondMax != 13) {
|
|
|
+ cardCountMap.remove(14); // 移除三个14
|
|
|
+ cardCountMap.put(1, cardCountMap.getOrDefault(1, 0) + 3); // 添加三个1
|
|
|
+ }
|
|
|
+
|
|
|
+ while (result.size() < 6 && !cardCountMap.isEmpty()) {
|
|
|
+ boolean found = false;
|
|
|
+ for (Map.Entry<Integer, Integer> entry : cardCountMap.entrySet()) {
|
|
|
+ int point = entry.getKey();
|
|
|
+ int count = entry.getValue();
|
|
|
+
|
|
|
+ if (count >= 2) {
|
|
|
+ result.add(point);
|
|
|
+ result.add(point);
|
|
|
+ cardCountMap.put(point, count - 2);
|
|
|
+ found = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!found) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return points;
|
|
|
+ }
|
|
|
+ // 特殊处理:仅在特定条件下将三个14转换为1
|
|
|
+ if (cardCountMap.containsKey(14)) {
|
|
|
+ List<Integer> sortedKeys = new ArrayList<>(cardCountMap.keySet());
|
|
|
+ Collections.sort(sortedKeys, Collections.reverseOrder());
|
|
|
+
|
|
|
+ int firstMax = sortedKeys.get(0);
|
|
|
+ int secondMax = sortedKeys.size() > 1 ? sortedKeys.get(1) : -1;
|
|
|
+
|
|
|
+ // 检查是否有三个14,且第二大点数小于14
|
|
|
+ if (firstMax == 14 && secondMax != 13) {
|
|
|
+ cardCountMap.remove(14); // 移除三个14
|
|
|
+ cardCountMap.put(1, cardCountMap.getOrDefault(1, 0) + 3); // 添加三个1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 处理癞子补充缺牌逻辑
|
|
|
+ if (wildCardCount ==1) { //如果癞子数量为1,则替换单张牌
|
|
|
+ Optional<Integer> first = cardCountMap.entrySet()
|
|
|
+ .stream()
|
|
|
+ .filter(entry -> entry.getValue() == 1)
|
|
|
+ .map(Map.Entry::getKey)
|
|
|
+ .findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ Integer integer = first.get();
|
|
|
+ cardCountMap.put(integer, 2);
|
|
|
+ }
|
|
|
+ }else if(wildCardCount ==2){
|
|
|
+ //查询key值数量
|
|
|
+ List<Integer> sortedKeys = new ArrayList<>(cardCountMap.keySet());
|
|
|
+ if (sortedKeys.size()<3){ //小于3则为特殊牌型 2233-1-1 直接替换
|
|
|
+ Integer maxValue = Collections.max(sortedKeys);//14
|
|
|
+ Integer minValue = Collections.min(sortedKeys);//13 QKKAA
|
|
|
+ if (maxValue-minValue==1){
|
|
|
+ cardCountMap.put(maxValue+1>14?minValue-1:maxValue+1, 2);
|
|
|
+ }else {
|
|
|
+ cardCountMap.put(maxValue-1, 2);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ //如果等于3则为普通牌型 223-1-1 直接替换
|
|
|
+ List<Integer> collect = cardCountMap.entrySet()
|
|
|
+ .stream()
|
|
|
+ .filter(entry -> entry.getValue() == 1)
|
|
|
+ .map(Map.Entry::getKey)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ cardCountMap.put(collect.get(0), 2);
|
|
|
+ cardCountMap.put(collect.get(1), 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ while (result.size() < 6 && !cardCountMap.isEmpty()) {
|
|
|
+ boolean found = false;
|
|
|
+ for (Map.Entry<Integer, Integer> entry : cardCountMap.entrySet()) {
|
|
|
+ int point = entry.getKey();
|
|
|
+ int count = entry.getValue();
|
|
|
+
|
|
|
+ if (count >= 2) {
|
|
|
+ result.add(point);
|
|
|
+ result.add(point);
|
|
|
+ cardCountMap.put(point, count - 2);
|
|
|
+ found = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!found) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|