Explorar el Código

找服务接口

Administrator hace 2 meses
padre
commit
f235225ab0

+ 42 - 7
incubator-game/src/main/java/com/incubator/game/util/GDUtils.java

@@ -250,6 +250,7 @@ public final class GDUtils {
         return (int) points.stream().filter(card -> card == wildCard).count();
     }
 
+
     /**
      * 替换赖子牌为当前手牌中的任意其他牌(排除大王和小王)
      *
@@ -263,7 +264,7 @@ public final class GDUtils {
         List<Integer> adjustedPoints = new ArrayList<>(points);
         adjustedPoints.removeIf(p -> p == -1); // 移除赖子标识
 
-        // 找到当前手牌中排除大王小王的最小点数
+        // 找到当前手牌中排除大王小王的最小点数
         List<Integer> availablePoints = adjustedPoints.stream()
                 .filter(p -> p != 16 && p != 17)  // 排除大王(17)和小王(16)
                 .distinct()  // 确保不重复
@@ -279,6 +280,12 @@ public final class GDUtils {
             wildCardCount--;
         }
 
+        // 如果赖子牌数量仍然大于0,但已经满足requiredCount,将剩余的赖子牌添加为当前级牌
+        while (wildCardCount > 0) {
+            adjustedPoints.add(curLevel);
+            wildCardCount--;
+        }
+
         adjustedPoints.sort(Collections.reverseOrder()); // 按照点数降序排序
         return adjustedPoints;
     }
@@ -491,9 +498,9 @@ public final class GDUtils {
      * @return 正数表示当前牌较大,负数表示上一手牌较大,0表示相等
      */
     private static int compareTripleWithTwo(List<Integer> previousPoints, List<Integer> currentPoints, int curLevel, int wildCardCountCurrent, int wildCardCountPrevious) {
-        // 替换赖子牌为当前级牌点数,形成有效的三带二牌型(只关注三张牌的部分)
-        List<Integer> adjustedPrevious = replaceWildCardsWithTrump(previousPoints, wildCardCountPrevious, curLevel, 3);  // 只需三张
-        List<Integer> adjustedCurrent = replaceWildCardsWithTrump(currentPoints, wildCardCountCurrent, curLevel, 3);  // 只需三张
+        // 替换赖子牌为当前级牌点数,形成有效的三带二牌型
+        List<Integer> adjustedPrevious = replaceWildCardsWithTrump(previousPoints, wildCardCountPrevious, curLevel, 5);
+        List<Integer> adjustedCurrent = replaceWildCardsWithTrump(currentPoints, wildCardCountCurrent, curLevel, 5);
 
         // 获取三张牌的最大点数
         int maxPreviousTriple = getMaxFrequencyCard(adjustedPrevious, 3);
@@ -510,7 +517,32 @@ public final class GDUtils {
             return -1; // 上一手牌是主牌三张,优先级更高
         }
 
-        // 默认比较三张点数(忽略两张部分)
+        // 如果三张牌的点数相同,比较两张牌的点数
+        if (maxCurrentTriple == maxPreviousTriple) {
+            // 移除三张牌的部分,剩下两张牌的部分
+            adjustedPrevious.removeIf(card -> card == maxPreviousTriple);
+            adjustedCurrent.removeIf(card -> card == maxCurrentTriple);
+
+            // 获取两张牌的最大点数
+            int maxPreviousPair = getMaxFrequencyCard(adjustedPrevious, 2);
+            int maxCurrentPair = getMaxFrequencyCard(adjustedCurrent, 2);
+
+            // 主牌优先级比较
+            boolean previousIsTrumpPair = (maxPreviousPair == curLevel);
+            boolean currentIsTrumpPair = (maxCurrentPair == curLevel);
+
+            if (currentIsTrumpPair && !previousIsTrumpPair) {
+                return 1; // 当前牌是主牌两张,优先级更高
+            }
+            if (!currentIsTrumpPair && previousIsTrumpPair) {
+                return -1; // 上一手牌是主牌两张,优先级更高
+            }
+
+            // 默认比较两张牌的点数
+            return Integer.compare(maxCurrentPair, maxPreviousPair);
+        }
+
+        // 默认比较三张牌的点数
         return Integer.compare(maxCurrentTriple, maxPreviousTriple);
     }
 
@@ -906,6 +938,7 @@ public final class GDUtils {
         // 初始化三张和两张的需求
         boolean hasTriple = false;
         boolean hasPair = false;
+        boolean hasTwoSingles = false;
 
         // 剩余赖子牌数量
         int remainingWilds = wildCount;
@@ -1056,7 +1089,7 @@ public final class GDUtils {
 
     // 测试代码
     public static void main(String[] args) {
-        int[] cards1 = {0x08, 0x04, 0x05, 0x06, 0x07}; // 顺子
+      /*  int[] cards1 = {0x08, 0x04, 0x05, 0x06, 0x07}; // 顺子
         int[] cards2 = {0x33, 0x13, 0x23, 0x03};       // 四炸弹
         int[] cards8 = {0xEF, 0xEF, 0xFF, 0xFF};             // 四王炸
         int[] cards9 = {0x03, 0x13, 0x23, 0x33};             // 四炸弹
@@ -1076,8 +1109,10 @@ public final class GDUtils {
         System.out.println(determineCardType(cards12, 0)); // SEVEN_BOMB
         System.out.println(determineCardType(cards13, 0)); // EIGHT_BOMB
         System.out.println(determineCardType(cards14, 0)); // STRAIGHT
-        System.out.println(determineCardType(cards15, 0)); // PAIR_SEQUENCE
+        System.out.println(determineCardType(cards15, 0)); // PAIR_SEQUENCE*/
+        int[] cards10 = {0x08, 0x18, 0x29, 0x39, 0x45};      // 五炸弹
 
+        System.out.println(determineCardType(cards10, 0x45)); // FIVE_BOMB
         int[] cards20 = {0x02, 0x02, 0x02, 0x0e, 0x0e, 0x0e}; // A-A-A-2-2-2
         int[] cards21 = {0x03, 0x03, 0x03, 0x02, 0x02, 0x02}; // 3-3-3-4-4-4