Browse Source

修改连对,炸弹,升级上限bug

xhb 2 months ago
parent
commit
7d8504626a

+ 5 - 1
incubator-game/src/main/java/com/incubator/game/room/GDRoom.java

@@ -1359,7 +1359,11 @@ public class GDRoom extends Room {
                     // 升级
                     winPlayer.data.levelIndex = Math.min(winPlayer.data.levelIndex + upLevel, GDUtils.levelPoint.length - 1);
                     int score = winPlayer.data.levelPointView[0] + upLevel;//胜利方牌级
-                    score = Math.min(score,this.data.modev);
+                    if (score>this.data.modev){
+                        upLevel = score - this.data.modev;
+                        score = this.data.modev;
+                    }
+//                    score = Math.min(score,this.data.modev);
                     if (score ==this.data.modev){
                         if (this.data.lvPlayerId==null){
                             this.data.lvPlayerId = winPlayer.getId();

+ 36 - 33
incubator-game/src/main/java/com/incubator/game/util/GDUtils.java

@@ -250,8 +250,15 @@ public final class GDUtils {
                 return compareStraight(previousPoints, currentPoints, curLevel, wildCardCountCurrent, wildCardCountPrevious);
             case BOMB:
                 // 炸弹:赖子牌可以增强炸弹的级别
-                return compareBomb(previousPoints, currentPoints, wildCardCountCurrent, wildCardCountPrevious);
+                return compareBomb(previousPoints, currentPoints,curLevel, wildCardCountCurrent, wildCardCountPrevious);
             default:
+                if (disCardsType.equals(CardType.FIVE_BOMB)||
+                    disCardsType.equals(CardType.SIX_BOMB)||
+                    disCardsType.equals(CardType.SEVEN_BOMB)||
+                    disCardsType.equals(CardType.EIGHT_BOMB)
+                ){
+                    return compareBomb(previousPoints, currentPoints,curLevel, wildCardCountCurrent, wildCardCountPrevious);
+                }
                 // 默认按最大点数比较
                 return Integer.compare(
                         currentPoints.get(currentPoints.size() - 1),
@@ -380,17 +387,20 @@ public final class GDUtils {
         // 替换赖子牌为当前级牌点数,形成有效的对子序列
         List<Integer> adjustedPrevious = replaceWildCardsPairSequence(previousPoints, wildCardCountPrevious, curLevel);
         List<Integer> adjustedCurrent = replaceWildCardsPairSequence(currentPoints, wildCardCountCurrent, curLevel);
-
+        // 使用 Collections.sort 进行降序排序
+        Collections.sort(adjustedPrevious, Collections.reverseOrder());
+        // 使用 Collections.sort 进行降序排序
+        Collections.sort(adjustedCurrent, Collections.reverseOrder());
         // 获取三连对的最大点数
         int maxPrevious = getMaxConsecutiveValue(adjustedPrevious);
         int maxCurrent = getMaxConsecutiveValue(adjustedCurrent);
 
         // 级牌优先级比较
-        boolean previousIsTrump = (maxPrevious == curLevel);
-        boolean currentIsTrump = (maxCurrent == curLevel);
-
-        if (currentIsTrump && !previousIsTrump) return 1; // 当前牌是级牌三连对
-        if (!currentIsTrump && previousIsTrump) return -1; // 上一手牌是级牌三连对
+//        boolean previousIsTrump = (maxPrevious == curLevel);
+//        boolean currentIsTrump = (maxCurrent == curLevel);
+//
+//        if (currentIsTrump && !previousIsTrump) return 1; // 当前牌是级牌三连对
+//        if (!currentIsTrump && previousIsTrump) return -1; // 上一手牌是级牌三连对
 
         // 默认比较最大点数
         return Integer.compare(maxCurrent, maxPrevious);
@@ -753,10 +763,16 @@ public final class GDUtils {
      * @param wildCardCountPrevious 上一手牌中的赖子数量
      * @return 正数表示当前牌较大,负数表示上一手牌较大,0表示相等
      */
-    private static int compareBomb(List<Integer> previousPoints, List<Integer> currentPoints, int wildCardCountCurrent, int wildCardCountPrevious) {
+    private static int compareBomb(List<Integer> previousPoints, List<Integer> currentPoints,int curLevel, int wildCardCountCurrent, int wildCardCountPrevious) {
         // 获取上一手牌和当前手牌中的最大炸弹点数
-        int maxPreviousBomb = getMaxFrequencyCard(previousPoints, 4);
-        int maxCurrentBomb = getMaxFrequencyCard(currentPoints, 4);
+//        int maxPreviousBomb = getMaxFrequencyCard(previousPoints, 4);
+//        int maxCurrentBomb = getMaxFrequencyCard(currentPoints, 4);
+        int maxPreviousBomb = Collections.max(previousPoints);
+        int maxCurrentBomb = Collections.max(currentPoints);
+        //优先比较级牌
+        if (maxCurrentBomb == curLevel) {
+            return 1;
+        }
 
         // 如果当前手牌的炸弹点数较大,返回1
         if (maxCurrentBomb > maxPreviousBomb) {
@@ -1171,30 +1187,13 @@ public final class GDUtils {
             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
+                // 1. 移除所有的 14
+                sortedPoints.removeIf(num -> num == 14);
+                // 2. 添加两个 1
+                sortedPoints.add(1);
+                sortedPoints.add(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;
+            return sortedPoints;
         }
         // 特殊处理:仅在特定条件下将三个14转换为1
         if (cardCountMap.containsKey(14)) {
@@ -1690,6 +1689,10 @@ public final class GDUtils {
 
     // 判断是否为三顺(赖子补齐)
     private static boolean isTripleSequenceWithWild(Map<Integer, Long> pointFrequency, int wildCount) {
+        if (pointFrequency.size()>=3){
+            return false;
+        }
+
         List<Integer> triples = pointFrequency.keySet().stream()
                 .filter(key -> pointFrequency.get(key) >= 3||pointFrequency.get(key)+wildCount>=3)
                 .sorted()