diff --git a/landlords-common/src/main/java/org/nico/ratel/landlords/helper/PokerHelper.java b/landlords-common/src/main/java/org/nico/ratel/landlords/helper/PokerHelper.java index 6e897f5..371e94c 100644 --- a/landlords-common/src/main/java/org/nico/ratel/landlords/helper/PokerHelper.java +++ b/landlords-common/src/main/java/org/nico/ratel/landlords/helper/PokerHelper.java @@ -13,8 +13,15 @@ import org.nico.ratel.landlords.enums.PokerType; import org.nico.ratel.landlords.enums.SellType; public class PokerHelper { - + + /** + * Print the type of poker style + */ public static int pokerPrinterType = 0; + + /** + * The list of all pokers, by 54 + */ private static List basePokers = new ArrayList(54); private static Comparator pokerComparator = new Comparator() { @@ -369,4 +376,72 @@ public class PokerHelper { } return builder.toString(); } + + public static List parsePokerSells(List pokers){ + List allPokerSell = new ArrayList<>(); + //single or double or three or four + int count = 0; + int lastLevel = -1; + List ps = new ArrayList<>(); + for(int index = 0; index < pokers.size(); index ++){ + int level = pokers.get(index).getLevel().getLevel(); + if(lastLevel == -1 || level == lastLevel){ + ++ count; + ps.add(pokers.get(index)); + }else{ + count = 0; + ps.clear(); + } + if(count == 1){ + allPokerSell.add(new PokerSell(level, SellType.SINGLE, ps)); + }else if(count == 2){ + allPokerSell.add(new PokerSell(level, SellType.DOUBLE, ps)); + }else if(count == 3){ + allPokerSell.add(new PokerSell(level, SellType.THREE, ps)); + }else if(count == 4){ + allPokerSell.add(new PokerSell(level + 999, SellType.BOMB, ps)); + } + } + + + return null; + } + + public static int parsePokerColligationScore(List pokers){ + int score = 0; + int count = 0; + int increase = 0; + int lastLevel = -1; + if(pokers != null && ! pokers.isEmpty()){ + for(int index = 0; index < pokers.size(); index ++){ + int level = pokers.get(index).getLevel().getLevel(); + if(lastLevel == -1){ + increase ++; + count ++; + score += lastLevel; + }else{ + if(level == lastLevel){ + ++ count; + }else{ + count = 0; + } + if(level < PokerLevel.LEVEL_2.getLevel() && level - 1 == lastLevel){ + ++ increase; + }else{ + increase = 0; + } + + score += (count + (increase > 4 ? increase : 0)) * level; + } + + if(level == PokerLevel.LEVEL_2.getLevel()){ + score += level * 2; + }else if(level > PokerLevel.LEVEL_2.getLevel()){ + score += level * 3; + } + lastLevel = level; + } + } + return score; + } } diff --git a/landlords-common/src/main/java/org/nico/ratel/landlords/robot/AbstractRobotDecisionMakers.java b/landlords-common/src/main/java/org/nico/ratel/landlords/robot/AbstractRobotDecisionMakers.java new file mode 100644 index 0000000..5b695ed --- /dev/null +++ b/landlords-common/src/main/java/org/nico/ratel/landlords/robot/AbstractRobotDecisionMakers.java @@ -0,0 +1,19 @@ +package org.nico.ratel.landlords.robot; + +import java.util.List; + +import org.nico.ratel.landlords.entity.Poker; +import org.nico.ratel.landlords.entity.PokerSell; + +/** + * + * @author nico + * @version createTime:2018年11月15日 上午12:12:15 + */ + +public abstract class AbstractRobotDecisionMakers { + + public abstract List howToPlayPokers(PokerSell lastPokerSell, List myPokers); + + public abstract boolean howToChooseLandlord(List leftPokers, List rightPokers, List myPokers); +} diff --git a/landlords-common/src/main/java/org/nico/ratel/landlords/robot/RobotDecisionMakers.java b/landlords-common/src/main/java/org/nico/ratel/landlords/robot/RobotDecisionMakers.java index d0c3d0c..5f93a5b 100644 --- a/landlords-common/src/main/java/org/nico/ratel/landlords/robot/RobotDecisionMakers.java +++ b/landlords-common/src/main/java/org/nico/ratel/landlords/robot/RobotDecisionMakers.java @@ -12,16 +12,15 @@ import org.nico.ratel.landlords.entity.PokerSell; */ public class RobotDecisionMakers { + private static AbstractRobotDecisionMakers decisionMakers = new SimpleRobotDecisionMakers(); + public static List howToPlayPokers(PokerSell lastPokerSell, List myPokers){ return null; } public static boolean howToChooseLandlord(List leftPokers, List rightPokers, List myPokers) { - - - - return true; + return decisionMakers.howToChooseLandlord(leftPokers, rightPokers, myPokers); } } diff --git a/landlords-common/src/main/java/org/nico/ratel/landlords/robot/SimpleRobotDecisionMakers.java b/landlords-common/src/main/java/org/nico/ratel/landlords/robot/SimpleRobotDecisionMakers.java new file mode 100644 index 0000000..6b9001b --- /dev/null +++ b/landlords-common/src/main/java/org/nico/ratel/landlords/robot/SimpleRobotDecisionMakers.java @@ -0,0 +1,30 @@ +package org.nico.ratel.landlords.robot; + +import java.util.List; + +import org.nico.ratel.landlords.entity.Poker; +import org.nico.ratel.landlords.entity.PokerSell; +import org.nico.ratel.landlords.helper.PokerHelper; + +/** + * + * @author nico + * @version createTime:2018年11月15日 上午12:13:49 + */ + +public class SimpleRobotDecisionMakers extends AbstractRobotDecisionMakers{ + + @Override + public List howToPlayPokers(PokerSell lastPokerSell, List myPokers) { + return null; + } + + @Override + public boolean howToChooseLandlord(List leftPokers, List rightPokers, List myPokers) { + int leftScore = PokerHelper.parsePokerColligationScore(leftPokers); + int rightScore = PokerHelper.parsePokerColligationScore(rightPokers); + int myScore = PokerHelper.parsePokerColligationScore(myPokers); + return myScore >= (leftScore + rightScore)/2; + } + +}