|
@@ -198,13 +198,13 @@ public final class GDUtils {
|
|
|
return compareTripleWithTwo(previousPoints, currentPoints, curLevel, wildCardCountCurrent, wildCardCountPrevious);
|
|
|
case TRIPLE_SEQUENCE:
|
|
|
|
|
|
-
|
|
|
+ return compareThreeConsecutive(previousPoints, currentPoints, curLevel, wildCardCountCurrent, wildCardCountPrevious);
|
|
|
case STRAIGHT:
|
|
|
|
|
|
-
|
|
|
+ return compareStraight(previousPoints, currentPoints, curLevel, wildCardCountCurrent, wildCardCountPrevious);
|
|
|
case BOMB:
|
|
|
|
|
|
-
|
|
|
+ return compareBomb(previousPoints, currentPoints, wildCardCountCurrent, wildCardCountPrevious);
|
|
|
default:
|
|
|
|
|
|
return Integer.compare(
|
|
@@ -485,6 +485,199 @@ public final class GDUtils {
|
|
|
return Integer.compare(maxCurrentTriple, maxPreviousTriple);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 比较两组三张连续牌型的大小,支持赖子牌的处理
|
|
|
+ *
|
|
|
+ * @param previousPoints 上一手牌的点数列表(三张连续牌)
|
|
|
+ * @param currentPoints 当前手牌的点数列表(三张连续牌)
|
|
|
+ * @param curLevel 当前级数(主牌)
|
|
|
+ * @param wildCardCountCurrent 当前手牌的赖子数量
|
|
|
+ * @param wildCardCountPrevious 上一手牌的赖子数量
|
|
|
+ * @return 正数表示当前牌较大,负数表示上一手牌较大,0表示相等
|
|
|
+ */
|
|
|
+ private static int compareThreeConsecutive(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);
|
|
|
+
|
|
|
+
|
|
|
+ int previousStrength = calculateHandStrength(adjustedPrevious, wildCardCountPrevious);
|
|
|
+ int currentStrength = calculateHandStrength(adjustedCurrent, wildCardCountCurrent);
|
|
|
+
|
|
|
+
|
|
|
+ if (currentStrength > previousStrength) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (currentStrength < previousStrength) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return compareByPoints(adjustedPrevious, adjustedCurrent);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 计算手牌的强度(考虑赖子牌替换后的牌型)
|
|
|
+ * @param points 调整后的点数列表
|
|
|
+ * @param wildCardCount 赖子牌数量
|
|
|
+ * @return 该手牌的强度值
|
|
|
+ */
|
|
|
+ private static int calculateHandStrength(List<Integer> points, int wildCardCount) {
|
|
|
+
|
|
|
+ if (wildCardCount == 0) {
|
|
|
+
|
|
|
+ return points.get(points.size() - 1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ int adjustedStrength = points.get(points.size() - 1);
|
|
|
+
|
|
|
+ if (wildCardCount > 1) {
|
|
|
+ adjustedStrength += 1;
|
|
|
+ }
|
|
|
+ return adjustedStrength;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 比较两手牌的点数
|
|
|
+ * @param previousPoints 上一手牌的点数列表
|
|
|
+ * @param currentPoints 当前手牌的点数列表
|
|
|
+ * @return 正数表示当前牌较大,负数表示上一手牌较大,0表示相等
|
|
|
+ */
|
|
|
+ private static int compareByPoints(List<Integer> previousPoints, List<Integer> currentPoints) {
|
|
|
+
|
|
|
+ int maxPrevious = getMaxConsecutiveValue(previousPoints);
|
|
|
+ int maxCurrent = getMaxConsecutiveValue(currentPoints);
|
|
|
+
|
|
|
+
|
|
|
+ if (maxCurrent > maxPrevious) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (maxCurrent < maxPrevious) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ int minPrevious = getMinConsecutiveValue(previousPoints);
|
|
|
+ int minCurrent = getMinConsecutiveValue(currentPoints);
|
|
|
+
|
|
|
+ return Integer.compare(minCurrent, minPrevious);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 获取连续三张牌的最大点数(即三张中的最大牌)
|
|
|
+ *
|
|
|
+ * @param points 调整后的点数列表
|
|
|
+ * @return 三张牌中的最大点数
|
|
|
+ */
|
|
|
+ private static int getMaxConsecutiveValue(List<Integer> points) {
|
|
|
+ return points.get(points.size() - 1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 获取连续三张牌的最小点数(即三张中的最小牌)
|
|
|
+ *
|
|
|
+ * @param points 调整后的点数列表
|
|
|
+ * @return 三张牌中的最小点数
|
|
|
+ */
|
|
|
+ private static int getMinConsecutiveValue(List<Integer> points) {
|
|
|
+ return points.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 比较顺子牌型的大小(考虑赖子牌的补充)
|
|
|
+ *
|
|
|
+ * @param previousPoints 上一手牌的点数列表
|
|
|
+ * @param currentPoints 当前手牌的点数列表
|
|
|
+ * @param curLevel 当前级数(主牌)
|
|
|
+ * @param wildCardCountCurrent 当前手牌的赖子数量
|
|
|
+ * @param wildCardCountPrevious 上一手牌的赖子数量
|
|
|
+ * @return 正数表示当前牌较大,负数表示上一手牌较大,0表示相等
|
|
|
+ */
|
|
|
+ private static int compareStraight(List<Integer> previousPoints, List<Integer> currentPoints, int curLevel, int wildCardCountCurrent, int wildCardCountPrevious) {
|
|
|
+
|
|
|
+ List<Integer> adjustedPrevious = replaceWildCardsWithTrump(previousPoints, wildCardCountPrevious, curLevel, 5);
|
|
|
+ List<Integer> adjustedCurrent = replaceWildCardsWithTrump(currentPoints, wildCardCountCurrent, curLevel, 5);
|
|
|
+
|
|
|
+
|
|
|
+ int maxPreviousStraight = getMaxStraightValue(adjustedPrevious);
|
|
|
+ int maxCurrentStraight = getMaxStraightValue(adjustedCurrent);
|
|
|
+
|
|
|
+
|
|
|
+ if (maxCurrentStraight > maxPreviousStraight) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (maxCurrentStraight < maxPreviousStraight) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ int minPreviousStraight = getMinStraightValue(adjustedPrevious);
|
|
|
+ int minCurrentStraight = getMinStraightValue(adjustedCurrent);
|
|
|
+
|
|
|
+ return Integer.compare(minCurrentStraight, minPreviousStraight);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 获取顺子的最大点数(即顺子中的最大牌)
|
|
|
+ *
|
|
|
+ * @param points 调整后的点数列表
|
|
|
+ * @return 顺子的最大点数
|
|
|
+ */
|
|
|
+ private static int getMaxStraightValue(List<Integer> points) {
|
|
|
+
|
|
|
+ return points.get(points.size() - 1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 获取顺子的最小点数(即顺子中的最小牌)
|
|
|
+ *
|
|
|
+ * @param points 调整后的点数列表
|
|
|
+ * @return 顺子的最小点数
|
|
|
+ */
|
|
|
+ private static int getMinStraightValue(List<Integer> points) {
|
|
|
+
|
|
|
+ return points.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 比较炸弹牌型的大小(考虑赖子牌的增强)
|
|
|
+ *
|
|
|
+ * @param previousPoints 上一手牌的点数列表
|
|
|
+ * @param currentPoints 当前手牌的点数列表
|
|
|
+ * @param wildCardCountCurrent 当前手牌中的赖子数量
|
|
|
+ * @param wildCardCountPrevious 上一手牌中的赖子数量
|
|
|
+ * @return 正数表示当前牌较大,负数表示上一手牌较大,0表示相等
|
|
|
+ */
|
|
|
+ private static int compareBomb(List<Integer> previousPoints, List<Integer> currentPoints, int wildCardCountCurrent, int wildCardCountPrevious) {
|
|
|
+
|
|
|
+ int maxPreviousBomb = getMaxFrequencyCard(previousPoints, 4);
|
|
|
+ int maxCurrentBomb = getMaxFrequencyCard(currentPoints, 4);
|
|
|
+
|
|
|
+
|
|
|
+ if (maxCurrentBomb > maxPreviousBomb) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (maxCurrentBomb < maxPreviousBomb) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (wildCardCountCurrent > wildCardCountPrevious) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ if (wildCardCountCurrent < wildCardCountPrevious) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* 获取指定频率的最大点数
|
|
|
*
|
|
@@ -640,18 +833,18 @@ public final class GDUtils {
|
|
|
return CardType.STRAIGHT;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- if (cardCount >= 6 && cardCount % 2 == 0 && uniqueCount + wildCount >= cardCount / 2
|
|
|
- && isPairSequenceWithWild(pointFrequency, wildCount)) {
|
|
|
- return CardType.PAIR_SEQUENCE;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
if (cardCount >= 6 && cardCount % 3 == 0 && uniqueCount + wildCount >= cardCount / 3
|
|
|
&& isTripleSequenceWithWild(pointFrequency, wildCount)) {
|
|
|
return CardType.TRIPLE_SEQUENCE;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ if (cardCount >= 6 && cardCount % 2 == 0 && uniqueCount + wildCount >= cardCount / 2
|
|
|
+ && isPairSequenceWithWild(pointFrequency, wildCount)) {
|
|
|
+ return CardType.PAIR_SEQUENCE;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
if (cardCount == 5 && uniqueCount <= 3 && isTripleWithTwo(pointFrequency, wildCount)) {
|
|
|
return CardType.TRIPLE_WITH_TWO;
|
|
@@ -770,6 +963,10 @@ public final class GDUtils {
|
|
|
.sorted()
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
+
|
|
|
+ if (triples.isEmpty()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
if (triples.contains(14) && triples.contains(2)) {
|
|
|
return true;
|
|
@@ -790,6 +987,7 @@ public final class GDUtils {
|
|
|
}
|
|
|
gaps += (int) (3 - pointFrequency.get(triples.get(i)));
|
|
|
}
|
|
|
+
|
|
|
gaps += (int) (3 - pointFrequency.get(triples.get(triples.size() - 1)));
|
|
|
return gaps <= wildCount;
|
|
|
}
|