mirror of
https://github.com/tiennm99/caro.git
synced 2026-05-24 04:24:23 +00:00
抢地主简单策略
This commit is contained in:
@@ -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<Poker> basePokers = new ArrayList<Poker>(54);
|
||||
|
||||
private static Comparator<Poker> pokerComparator = new Comparator<Poker>() {
|
||||
@@ -369,4 +376,72 @@ public class PokerHelper {
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static List<PokerSell> parsePokerSells(List<Poker> pokers){
|
||||
List<PokerSell> allPokerSell = new ArrayList<>();
|
||||
//single or double or three or four
|
||||
int count = 0;
|
||||
int lastLevel = -1;
|
||||
List<Poker> 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<Poker> 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;
|
||||
}
|
||||
}
|
||||
|
||||
+19
@@ -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<Poker> howToPlayPokers(PokerSell lastPokerSell, List<Poker> myPokers);
|
||||
|
||||
public abstract boolean howToChooseLandlord(List<Poker> leftPokers, List<Poker> rightPokers, List<Poker> myPokers);
|
||||
}
|
||||
+3
-4
@@ -12,16 +12,15 @@ import org.nico.ratel.landlords.entity.PokerSell;
|
||||
*/
|
||||
public class RobotDecisionMakers {
|
||||
|
||||
private static AbstractRobotDecisionMakers decisionMakers = new SimpleRobotDecisionMakers();
|
||||
|
||||
public static List<Poker> howToPlayPokers(PokerSell lastPokerSell, List<Poker> myPokers){
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean howToChooseLandlord(List<Poker> leftPokers, List<Poker> rightPokers, List<Poker> myPokers) {
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
return decisionMakers.howToChooseLandlord(leftPokers, rightPokers, myPokers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+30
@@ -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<Poker> howToPlayPokers(PokerSell lastPokerSell, List<Poker> myPokers) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean howToChooseLandlord(List<Poker> leftPokers, List<Poker> rightPokers, List<Poker> myPokers) {
|
||||
int leftScore = PokerHelper.parsePokerColligationScore(leftPokers);
|
||||
int rightScore = PokerHelper.parsePokerColligationScore(rightPokers);
|
||||
int myScore = PokerHelper.parsePokerColligationScore(myPokers);
|
||||
return myScore >= (leftScore + rightScore)/2;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user