mirror of
https://github.com/tiennm99/caro.git
synced 2026-05-24 04:24:23 +00:00
robot 出牌策略
This commit is contained in:
@@ -44,7 +44,7 @@ public class SimpleClient {
|
||||
}
|
||||
|
||||
if(serverAddress == null || port == 0){
|
||||
String serverInfo = StreamUtils.convertToString(new URL("https://raw.githubusercontent.com/abbychau/ratel/master/serverlist.json"));
|
||||
String serverInfo = StreamUtils.convertToString(new URL("https://github.com/ainilili/ratel/blob/dev-1.1.0/serverlist.json"));
|
||||
List<String> serverAddressList = Noson.convert(serverInfo, new NoType<List<String>>() {});
|
||||
SimplePrinter.printNotice("Please select a server:");
|
||||
for(int i = 0; i < serverAddressList.size(); i++) {
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package org.nico.ratel.landlords.client.event;
|
||||
|
||||
import org.nico.ratel.landlords.print.SimplePrinter;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
|
||||
public class ClientEventListener_CODE_NOT_SUPPORT extends ClientEventListener{
|
||||
|
||||
@Override
|
||||
public void call(Channel channel, String data) {
|
||||
SimplePrinter.printNotice(data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
+1
-1
@@ -31,7 +31,7 @@ public class ClientEventListener_CODE_SHOW_OPTIONS_PVE extends ClientEventListen
|
||||
int choose = Integer.valueOf(line);
|
||||
|
||||
if(0 < choose && choose < 4) {
|
||||
pushToServer(channel, ServerEventCode.CODE_ROOM_CREATE_PVE, null);
|
||||
pushToServer(channel, ServerEventCode.CODE_ROOM_CREATE_PVE, String.valueOf(choose));
|
||||
}else {
|
||||
SimplePrinter.printNotice("Invalid option, please choose again:");
|
||||
call(channel, data);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class Poker{
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Poker [level=" + level + ", type=" + type + "]";
|
||||
return String.valueOf(level.getLevel()) + " ";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.nico.ratel.landlords.entity;
|
||||
import java.util.List;
|
||||
|
||||
import org.nico.ratel.landlords.enums.SellType;
|
||||
import org.nico.ratel.landlords.helper.PokerHelper;
|
||||
|
||||
public class PokerSell {
|
||||
|
||||
@@ -11,14 +12,24 @@ public class PokerSell {
|
||||
private SellType sellType;
|
||||
|
||||
private List<Poker> sellPokers;
|
||||
|
||||
public PokerSell(int score, SellType sellType, List<Poker> sellPokers) {
|
||||
super();
|
||||
this.score = score;
|
||||
|
||||
private int coreLevel;
|
||||
|
||||
public PokerSell(SellType sellType, List<Poker> sellPokers, int coreLevel) {
|
||||
this.score = PokerHelper.parseScore(sellType, coreLevel);
|
||||
this.sellType = sellType;
|
||||
this.sellPokers = sellPokers;
|
||||
this.coreLevel = coreLevel;
|
||||
}
|
||||
|
||||
public final int getCoreLevel() {
|
||||
return coreLevel;
|
||||
}
|
||||
|
||||
public final void setCoreLevel(int coreLevel) {
|
||||
this.coreLevel = coreLevel;
|
||||
}
|
||||
|
||||
public final int getScore() {
|
||||
return score;
|
||||
}
|
||||
@@ -42,5 +53,10 @@ public class PokerSell {
|
||||
public final void setSellPokers(List<Poker> sellPokers) {
|
||||
this.sellPokers = sellPokers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PokerSell [sellType=" + sellType + ", sellPokers=" + sellPokers + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ public class Room{
|
||||
private int lastSellClient = -1;
|
||||
|
||||
private int currentSellClient = -1;
|
||||
|
||||
private int difficultyCoefficient;
|
||||
|
||||
public Room() {
|
||||
}
|
||||
@@ -42,6 +44,14 @@ public class Room{
|
||||
this.status = RoomStatus.BLANK;
|
||||
}
|
||||
|
||||
public final int getDifficultyCoefficient() {
|
||||
return difficultyCoefficient;
|
||||
}
|
||||
|
||||
public final void setDifficultyCoefficient(int difficultyCoefficient) {
|
||||
this.difficultyCoefficient = difficultyCoefficient;
|
||||
}
|
||||
|
||||
public final RoomType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,8 @@ public enum ClientEventCode implements Serializable{
|
||||
CODE_GAME_POKER_PLAY_ORDER_ERROR("顺序错误"),
|
||||
|
||||
CODE_GAME_OVER("游戏结束"),
|
||||
|
||||
CODE_NOT_SUPPORT("不支持"),
|
||||
;
|
||||
|
||||
private String msg;
|
||||
|
||||
@@ -11,14 +11,15 @@ import org.nico.ratel.landlords.entity.PokerSell;
|
||||
import org.nico.ratel.landlords.enums.PokerLevel;
|
||||
import org.nico.ratel.landlords.enums.PokerType;
|
||||
import org.nico.ratel.landlords.enums.SellType;
|
||||
import org.nico.ratel.landlords.utils.ListUtils;
|
||||
|
||||
public class PokerHelper {
|
||||
|
||||
|
||||
/**
|
||||
* Print the type of poker style
|
||||
*/
|
||||
public static int pokerPrinterType = 0;
|
||||
|
||||
|
||||
/**
|
||||
* The list of all pokers, by 54
|
||||
*/
|
||||
@@ -56,7 +57,7 @@ public class PokerHelper {
|
||||
public static void sortPoker(List<Poker> pokers){
|
||||
Collections.sort(pokers, pokerComparator);
|
||||
}
|
||||
|
||||
|
||||
public static int[] getIndexes(Character[] options, List<Poker> pokers) {
|
||||
List<Poker> copyList = new ArrayList<>(pokers.size());
|
||||
copyList.addAll(pokers);
|
||||
@@ -99,11 +100,10 @@ public class PokerHelper {
|
||||
}
|
||||
|
||||
public static PokerSell checkPokerType(List<Poker> pokers) {
|
||||
|
||||
|
||||
if(pokers != null && ! pokers.isEmpty()) {
|
||||
sortPoker(pokers);
|
||||
int score = -1;
|
||||
|
||||
|
||||
int[] levelTable = new int[20];
|
||||
for(Poker poker: pokers) {
|
||||
levelTable[poker.getLevel().getLevel()] ++;
|
||||
@@ -112,7 +112,7 @@ public class PokerHelper {
|
||||
int startIndex = -1;
|
||||
int endIndex = -1;
|
||||
int count = 0;
|
||||
|
||||
|
||||
int singleCount = 0;
|
||||
int doubleCount = 0;
|
||||
int threeCount = 0;
|
||||
@@ -148,83 +148,94 @@ public class PokerHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(singleCount == doubleCount && singleCount == threeCount && singleCount == 0 && fourCount == 1) {
|
||||
score = startIndex * 4 + 999;
|
||||
return new PokerSell(score, SellType.BOMB, pokers);
|
||||
return new PokerSell(SellType.BOMB, pokers, startIndex);
|
||||
}
|
||||
|
||||
|
||||
if(singleCount == 2 && startIndex == PokerLevel.LEVEL_SMALL_KING.getLevel() && endIndex == PokerLevel.LEVEL_BIG_KING.getLevel()) {
|
||||
score = Integer.MAX_VALUE;
|
||||
return new PokerSell(score, SellType.KING_BOMB, pokers);
|
||||
return new PokerSell(SellType.KING_BOMB, pokers, PokerLevel.LEVEL_SMALL_KING.getLevel());
|
||||
}
|
||||
|
||||
|
||||
if(startIndex == endIndex) {
|
||||
score = startIndex;
|
||||
if(levelTable[startIndex] == 1) {
|
||||
return new PokerSell(score, SellType.SINGLE, pokers);
|
||||
return new PokerSell(SellType.SINGLE, pokers, startIndex);
|
||||
}else if(levelTable[startIndex] == 2) {
|
||||
return new PokerSell(score, SellType.DOUBLE, pokers);
|
||||
return new PokerSell(SellType.DOUBLE, pokers, startIndex);
|
||||
}else if(levelTable[startIndex] == 3) {
|
||||
return new PokerSell(score, SellType.THREE, pokers);
|
||||
return new PokerSell(SellType.THREE, pokers, startIndex);
|
||||
}
|
||||
}
|
||||
if(endIndex - startIndex == count - 1 && endIndex < PokerLevel.LEVEL_2.getLevel()) {
|
||||
score = endIndex;
|
||||
if(levelTable[startIndex] == 1 && singleCount > 4 && doubleCount + threeCount + fourCount == 0) {
|
||||
return new PokerSell(score, SellType.SINGLE_STRAIGHT, pokers);
|
||||
return new PokerSell(SellType.SINGLE_STRAIGHT, pokers, endIndex);
|
||||
}else if(levelTable[startIndex] == 2 && doubleCount > 2 && singleCount + threeCount + fourCount == 0) {
|
||||
return new PokerSell(score, SellType.DOUBLE_STRAIGHT, pokers);
|
||||
return new PokerSell(SellType.DOUBLE_STRAIGHT, pokers, endIndex);
|
||||
}else if(levelTable[startIndex] == 3 && threeCount > 1 && doubleCount + singleCount + fourCount == 0) {
|
||||
return new PokerSell(score, SellType.THREE_STRAIGHT, pokers);
|
||||
return new PokerSell(SellType.THREE_STRAIGHT, pokers, endIndex);
|
||||
}else if(levelTable[startIndex] == 4 && fourCount > 1 && doubleCount + threeCount + singleCount == 0) {
|
||||
return new PokerSell(score, SellType.FOUR_STRAIGHT, pokers);
|
||||
return new PokerSell(SellType.FOUR_STRAIGHT, pokers, endIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(threeCount != 0) {
|
||||
score = threeEndIndex;
|
||||
if(singleCount != 0 && singleCount == threeCount && doubleCount == 0 && fourCount == 0) {
|
||||
if(threeCount == 1) {
|
||||
return new PokerSell(score, SellType.THREE_ZONES_SINGLE, pokers);
|
||||
return new PokerSell(SellType.THREE_ZONES_SINGLE, pokers, threeEndIndex);
|
||||
}else {
|
||||
if(threeEndIndex - threeStartIndex + 1 == threeCount && threeEndIndex < PokerLevel.LEVEL_2.getLevel()) {
|
||||
return new PokerSell(score, SellType.THREE_STRAIGHT_WITH_SINGLE, pokers);
|
||||
return new PokerSell(SellType.THREE_STRAIGHT_WITH_SINGLE, pokers, threeEndIndex);
|
||||
}
|
||||
}
|
||||
}else if(doubleCount != 0 && doubleCount == threeCount && singleCount == 0 && fourCount == 0) {
|
||||
if(threeCount == 1) {
|
||||
return new PokerSell(score, SellType.THREE_ZONES_DOUBLE, pokers);
|
||||
return new PokerSell(SellType.THREE_ZONES_DOUBLE, pokers, threeEndIndex);
|
||||
}else {
|
||||
if(threeEndIndex - threeStartIndex + 1 == threeCount && threeEndIndex < PokerLevel.LEVEL_2.getLevel()) {
|
||||
return new PokerSell(score, SellType.FOUR_STRAIGHT_WITH_DOUBLE, pokers);
|
||||
return new PokerSell(SellType.FOUR_STRAIGHT_WITH_DOUBLE, pokers, threeEndIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(fourCount != 0) {
|
||||
score = fourEndIndex;
|
||||
if(singleCount != 0 && singleCount == fourCount * 2 && doubleCount == 0 && threeCount == 0) {
|
||||
if(fourCount == 1) {
|
||||
return new PokerSell(score, SellType.FOUR_ZONES_SINGLE, pokers);
|
||||
return new PokerSell(SellType.FOUR_ZONES_SINGLE, pokers, fourEndIndex);
|
||||
}else {
|
||||
if(fourEndIndex - fourStartIndex + 1 == fourCount && fourEndIndex < PokerLevel.LEVEL_2.getLevel()) {
|
||||
return new PokerSell(score, SellType.FOUR_STRAIGHT_WITH_SINGLE, pokers);
|
||||
return new PokerSell(SellType.FOUR_STRAIGHT_WITH_SINGLE, pokers, fourEndIndex);
|
||||
}
|
||||
}
|
||||
}else if(doubleCount != 0 && doubleCount == fourCount * 2 && singleCount == 0 && threeCount == 0) {
|
||||
if(fourCount == 1) {
|
||||
return new PokerSell(score, SellType.FOUR_ZONES_DOUBLE, pokers);
|
||||
return new PokerSell(SellType.FOUR_ZONES_DOUBLE, pokers, fourEndIndex);
|
||||
}else {
|
||||
if(fourEndIndex - fourStartIndex + 1 == fourCount && fourEndIndex < PokerLevel.LEVEL_2.getLevel()) {
|
||||
return new PokerSell(score, SellType.FOUR_STRAIGHT_WITH_DOUBLE, pokers);
|
||||
return new PokerSell(SellType.FOUR_STRAIGHT_WITH_DOUBLE, pokers, fourEndIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new PokerSell(-1, SellType.ILLEGAL, null);
|
||||
return new PokerSell(SellType.ILLEGAL, null, -1);
|
||||
}
|
||||
|
||||
public static int parseScore(SellType sellType, int level) {
|
||||
if(sellType == SellType.BOMB) {
|
||||
return level * 4 + 999;
|
||||
}else if(sellType == SellType.KING_BOMB) {
|
||||
return Integer.MAX_VALUE;
|
||||
}else if(sellType == SellType.SINGLE || sellType == SellType.DOUBLE || sellType == SellType.THREE) {
|
||||
return level;
|
||||
}else if(sellType == SellType.SINGLE_STRAIGHT || sellType == SellType.DOUBLE_STRAIGHT || sellType == SellType.THREE_STRAIGHT || sellType == SellType.FOUR_STRAIGHT) {
|
||||
return level;
|
||||
}else if(sellType == SellType.THREE_ZONES_SINGLE || sellType == SellType.THREE_STRAIGHT_WITH_SINGLE || sellType == SellType.THREE_ZONES_DOUBLE || sellType == SellType.FOUR_STRAIGHT_WITH_DOUBLE) {
|
||||
return level;
|
||||
}else if(sellType == SellType.FOUR_ZONES_SINGLE || sellType == SellType.FOUR_STRAIGHT_WITH_SINGLE || sellType == SellType.FOUR_ZONES_DOUBLE || sellType == SellType.FOUR_STRAIGHT_WITH_DOUBLE) {
|
||||
return level;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static List<Poker> getPoker(int[] indexes, List<Poker> pokers){
|
||||
@@ -265,19 +276,19 @@ public class PokerHelper {
|
||||
public static String printPoker(List<Poker> pokers) {
|
||||
sortPoker(pokers);
|
||||
switch(pokerPrinterType){
|
||||
case 0:
|
||||
case 0:
|
||||
return buildHandStringSharp(pokers);
|
||||
case 1:
|
||||
case 1:
|
||||
return buildHandStringRounded(pokers);
|
||||
case 2:
|
||||
case 2:
|
||||
return textOnly(pokers);
|
||||
case 3:
|
||||
case 3:
|
||||
return textOnlyNoType(pokers);
|
||||
default:
|
||||
default:
|
||||
return buildHandStringSharp(pokers);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
private static String buildHandStringSharp(List<Poker> pokers){
|
||||
StringBuilder builder = new StringBuilder();
|
||||
@@ -376,37 +387,7 @@ 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;
|
||||
@@ -423,17 +404,17 @@ public class PokerHelper {
|
||||
if(level == lastLevel){
|
||||
++ count;
|
||||
}else{
|
||||
count = 0;
|
||||
count = 1;
|
||||
}
|
||||
if(level < PokerLevel.LEVEL_2.getLevel() && level - 1 == lastLevel){
|
||||
++ increase;
|
||||
}else{
|
||||
increase = 0;
|
||||
increase = 1;
|
||||
}
|
||||
|
||||
|
||||
score += (count + (increase > 4 ? increase : 0)) * level;
|
||||
}
|
||||
|
||||
|
||||
if(level == PokerLevel.LEVEL_2.getLevel()){
|
||||
score += level * 2;
|
||||
}else if(level > PokerLevel.LEVEL_2.getLevel()){
|
||||
@@ -444,4 +425,140 @@ public class PokerHelper {
|
||||
}
|
||||
return score;
|
||||
}
|
||||
|
||||
public static List<PokerSell> parsePokerSells(List<Poker> pokers){
|
||||
List<PokerSell> pokerSells = new ArrayList<>();
|
||||
int size = pokers.size();
|
||||
|
||||
//king boom
|
||||
{
|
||||
if(size > 1) {
|
||||
if(pokers.get(size - 1).getLevel() == PokerLevel.LEVEL_BIG_KING && pokers.get(size - 2).getLevel() == PokerLevel.LEVEL_SMALL_KING) {
|
||||
pokerSells.add(new PokerSell(SellType.KING_BOMB, ListUtils.getList(new Poker[] {pokers.get(size - 2), pokers.get(size - 1)}), PokerLevel.LEVEL_BIG_KING.LEVEL_10.getLevel()));
|
||||
}
|
||||
}
|
||||
}
|
||||
//all single or double
|
||||
{
|
||||
int count = 0;
|
||||
int lastLevel = -1;
|
||||
List<Poker> sellPokers = new ArrayList<>(4);
|
||||
for(int index = 0; index < pokers.size(); index ++) {
|
||||
Poker poker = pokers.get(index);
|
||||
int level = poker.getLevel().getLevel();
|
||||
if(lastLevel == -1) {
|
||||
++ count;
|
||||
sellPokers.add(poker);
|
||||
}else {
|
||||
if(level == lastLevel) {
|
||||
++ count;
|
||||
sellPokers.add(poker);
|
||||
}else {
|
||||
count = 1;
|
||||
sellPokers.clear();
|
||||
}
|
||||
}
|
||||
if(count == 1) {
|
||||
pokerSells.add(new PokerSell(SellType.SINGLE, ListUtils.getList(sellPokers), poker.getLevel().getLevel()));
|
||||
}else if(count == 2){
|
||||
pokerSells.add(new PokerSell(SellType.DOUBLE, ListUtils.getList(sellPokers), poker.getLevel().getLevel()));
|
||||
}else if(count == 3){
|
||||
pokerSells.add(new PokerSell(SellType.THREE, ListUtils.getList(sellPokers), poker.getLevel().getLevel()));
|
||||
}else if(count == 4){
|
||||
pokerSells.add(new PokerSell(SellType.BOMB, ListUtils.getList(sellPokers), poker.getLevel().getLevel()));
|
||||
}
|
||||
|
||||
lastLevel = level;
|
||||
}
|
||||
}
|
||||
//顺子
|
||||
{
|
||||
parsePokerSellStraight(pokerSells, SellType.SINGLE);
|
||||
parsePokerSellStraight(pokerSells, SellType.DOUBLE);
|
||||
parsePokerSellStraight(pokerSells, SellType.THREE);
|
||||
parsePokerSellStraight(pokerSells, SellType.BOMB);
|
||||
}
|
||||
|
||||
return pokerSells;
|
||||
}
|
||||
|
||||
private static void parsePokerSellStraight(List<PokerSell> pokerSells, SellType sellType) {
|
||||
int minLenght = -1;
|
||||
int width = -1;
|
||||
SellType targetSellType = null;
|
||||
if(sellType == SellType.SINGLE) {
|
||||
minLenght = 5;
|
||||
width = 1;
|
||||
targetSellType = SellType.SINGLE_STRAIGHT;
|
||||
}else if(sellType == SellType.DOUBLE) {
|
||||
minLenght = 3;
|
||||
width = 2;
|
||||
targetSellType = SellType.DOUBLE_STRAIGHT;
|
||||
}else if(sellType == SellType.THREE) {
|
||||
minLenght = 2;
|
||||
width = 3;
|
||||
targetSellType = SellType.THREE_STRAIGHT;
|
||||
}else if(sellType == SellType.BOMB) {
|
||||
minLenght = 2;
|
||||
width = 4;
|
||||
targetSellType = SellType.FOUR_STRAIGHT;
|
||||
}
|
||||
|
||||
int increase_1 = 0;
|
||||
int lastLevel_1 = -1;
|
||||
List<Poker> sellPokers_1 = new ArrayList<>(4);
|
||||
for(int index = 0; index < pokerSells.size(); index ++) {
|
||||
PokerSell sell = pokerSells.get(index);
|
||||
|
||||
if(sell.getSellType() == sellType) {
|
||||
int level = sell.getCoreLevel();
|
||||
if(lastLevel_1 == -1) {
|
||||
++ increase_1;
|
||||
sellPokers_1.addAll(sell.getSellPokers());
|
||||
}else {
|
||||
if(level - 1 == lastLevel_1 && level != PokerLevel.LEVEL_2.getLevel()) {
|
||||
++ increase_1;
|
||||
sellPokers_1.addAll(sell.getSellPokers());
|
||||
}else {
|
||||
if(increase_1 >= minLenght) {
|
||||
for(int s = 0; s <= increase_1 - minLenght; s ++) {
|
||||
int len = minLenght + s;
|
||||
for(int subIndex = 0; subIndex <= increase_1 - len; subIndex ++) {
|
||||
pokerSells.add(new PokerSell(targetSellType, ListUtils.getList(sellPokers_1.subList(subIndex * width, (subIndex + len) * width)), level));
|
||||
}
|
||||
}
|
||||
}
|
||||
increase_1 = 0;
|
||||
sellPokers_1.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<Poker> pokers = new ArrayList<>();
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_3, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_3, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_3, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_3, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_4, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_4, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_4, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_4, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_5, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_5, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_5, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_5, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_6, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_6, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_6, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_6, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_7, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_7, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_7, PokerType.BLANK));
|
||||
pokers.add(new Poker(PokerLevel.LEVEL_7, PokerType.BLANK));
|
||||
System.out.println(parsePokerSells(pokers));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ import org.nico.ratel.landlords.entity.PokerSell;
|
||||
|
||||
public abstract class AbstractRobotDecisionMakers {
|
||||
|
||||
public abstract List<Poker> howToPlayPokers(PokerSell lastPokerSell, List<Poker> myPokers);
|
||||
public abstract PokerSell howToPlayPokers(PokerSell lastPokerSell, List<Poker> myPokers);
|
||||
|
||||
public abstract boolean howToChooseLandlord(List<Poker> leftPokers, List<Poker> rightPokers, List<Poker> myPokers);
|
||||
}
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
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;
|
||||
|
||||
public class MediumRobotDecisionMakers extends AbstractRobotDecisionMakers{
|
||||
|
||||
@Override
|
||||
public PokerSell howToPlayPokers(PokerSell lastPokerSell, List<Poker> myPokers) {
|
||||
// TODO Auto-generated method stub
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
+17
-6
@@ -1,6 +1,8 @@
|
||||
package org.nico.ratel.landlords.robot;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.nico.ratel.landlords.entity.Poker;
|
||||
import org.nico.ratel.landlords.entity.PokerSell;
|
||||
@@ -12,15 +14,24 @@ import org.nico.ratel.landlords.entity.PokerSell;
|
||||
*/
|
||||
public class RobotDecisionMakers {
|
||||
|
||||
private static AbstractRobotDecisionMakers decisionMakers = new SimpleRobotDecisionMakers();
|
||||
private static Map<Integer, AbstractRobotDecisionMakers> decisionMakersMap = new HashMap<Integer, AbstractRobotDecisionMakers>() {
|
||||
private static final long serialVersionUID = 8541568961784067309L;
|
||||
{
|
||||
decisionMakersMap.put(1, new SimpleRobotDecisionMakers());
|
||||
decisionMakersMap.put(2, new MediumRobotDecisionMakers());
|
||||
}
|
||||
};
|
||||
|
||||
public static List<Poker> howToPlayPokers(PokerSell lastPokerSell, List<Poker> myPokers){
|
||||
|
||||
return null;
|
||||
public static boolean contains(int difficultyCoefficient) {
|
||||
return decisionMakersMap.containsKey(difficultyCoefficient);
|
||||
}
|
||||
|
||||
public static boolean howToChooseLandlord(List<Poker> leftPokers, List<Poker> rightPokers, List<Poker> myPokers) {
|
||||
return decisionMakers.howToChooseLandlord(leftPokers, rightPokers, myPokers);
|
||||
public static PokerSell howToPlayPokers(int difficultyCoefficient, PokerSell lastPokerSell, List<Poker> myPokers){
|
||||
return decisionMakersMap.get(difficultyCoefficient).howToPlayPokers(lastPokerSell, myPokers);
|
||||
}
|
||||
|
||||
public static boolean howToChooseLandlord(int difficultyCoefficient, List<Poker> leftPokers, List<Poker> rightPokers, List<Poker> myPokers) {
|
||||
return decisionMakersMap.get(difficultyCoefficient).howToChooseLandlord(leftPokers, rightPokers, myPokers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-6
@@ -1,10 +1,12 @@
|
||||
package org.nico.ratel.landlords.robot;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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;
|
||||
import org.nico.ratel.landlords.enums.PokerLevel;
|
||||
import org.nico.ratel.landlords.enums.SellType;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -15,16 +17,14 @@ import org.nico.ratel.landlords.helper.PokerHelper;
|
||||
public class SimpleRobotDecisionMakers extends AbstractRobotDecisionMakers{
|
||||
|
||||
@Override
|
||||
public List<Poker> howToPlayPokers(PokerSell lastPokerSell, List<Poker> myPokers) {
|
||||
public PokerSell 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;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.nico.ratel.landlords.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ListUtils {
|
||||
|
||||
public static <T> List<T> getList(T[] array){
|
||||
List<T> list = new ArrayList<>(array.length);
|
||||
for(T t: array) {
|
||||
list.add(t);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static <T> List<T> getList(List<T> source){
|
||||
List<T> list = new ArrayList<>(source.size());
|
||||
list.addAll(source);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
+36
-25
@@ -1,12 +1,15 @@
|
||||
package org.nico.ratel.landlords.server.event;
|
||||
|
||||
import org.nico.ratel.landlords.channel.ChannelUtils;
|
||||
import org.nico.ratel.landlords.entity.ClientSide;
|
||||
import org.nico.ratel.landlords.entity.Room;
|
||||
import org.nico.ratel.landlords.enums.ClientEventCode;
|
||||
import org.nico.ratel.landlords.enums.ClientRole;
|
||||
import org.nico.ratel.landlords.enums.ClientStatus;
|
||||
import org.nico.ratel.landlords.enums.RoomStatus;
|
||||
import org.nico.ratel.landlords.enums.RoomType;
|
||||
import org.nico.ratel.landlords.enums.ServerEventCode;
|
||||
import org.nico.ratel.landlords.robot.RobotDecisionMakers;
|
||||
import org.nico.ratel.landlords.server.ServerContains;
|
||||
|
||||
public class ServerEventListener_CODE_ROOM_CREATE_PVE implements ServerEventListener{
|
||||
@@ -14,34 +17,42 @@ public class ServerEventListener_CODE_ROOM_CREATE_PVE implements ServerEventList
|
||||
@Override
|
||||
public void call(ClientSide clientSide, String data) {
|
||||
|
||||
Room room = new Room(ServerContains.getServerId());
|
||||
room.setType(RoomType.PVE);
|
||||
room.setStatus(RoomStatus.BLANK);
|
||||
room.setRoomOwner(clientSide.getNickname());
|
||||
room.getClientSideMap().put(clientSide.getId(), clientSide);
|
||||
room.getClientSideList().add(clientSide);
|
||||
|
||||
clientSide.setRoomId(room.getId());
|
||||
ServerContains.ROOM_MAP.put(room.getId(), room);
|
||||
|
||||
ClientSide preClient = clientSide;
|
||||
//Add robots
|
||||
for(int index = 1; index < 3; index ++) {
|
||||
ClientSide robot = new ClientSide(- ServerContains.getClientId(), ClientStatus.PLAYING, null);
|
||||
robot.setNickname("robot_" + index);
|
||||
robot.setRole(ClientRole.ROBOT);
|
||||
preClient.setNext(robot);
|
||||
robot.setPre(preClient);
|
||||
robot.setRoomId(room.getId());
|
||||
room.getClientSideMap().put(robot.getId(), robot);
|
||||
room.getClientSideList().add(robot);
|
||||
int difficultyCoefficient = Integer.valueOf(data);
|
||||
if(RobotDecisionMakers.contains(difficultyCoefficient)) {
|
||||
|
||||
Room room = new Room(ServerContains.getServerId());
|
||||
room.setType(RoomType.PVE);
|
||||
room.setStatus(RoomStatus.BLANK);
|
||||
room.setRoomOwner(clientSide.getNickname());
|
||||
room.getClientSideMap().put(clientSide.getId(), clientSide);
|
||||
room.getClientSideList().add(clientSide);
|
||||
room.setDifficultyCoefficient(difficultyCoefficient);
|
||||
|
||||
preClient = robot;
|
||||
clientSide.setRoomId(room.getId());
|
||||
ServerContains.ROOM_MAP.put(room.getId(), room);
|
||||
|
||||
ClientSide preClient = clientSide;
|
||||
//Add robots
|
||||
for(int index = 1; index < 3; index ++) {
|
||||
ClientSide robot = new ClientSide(- ServerContains.getClientId(), ClientStatus.PLAYING, null);
|
||||
robot.setNickname("robot_" + index);
|
||||
robot.setRole(ClientRole.ROBOT);
|
||||
preClient.setNext(robot);
|
||||
robot.setPre(preClient);
|
||||
robot.setRoomId(room.getId());
|
||||
room.getClientSideMap().put(robot.getId(), robot);
|
||||
room.getClientSideList().add(robot);
|
||||
|
||||
preClient = robot;
|
||||
}
|
||||
preClient.setNext(clientSide);
|
||||
clientSide.setPre(preClient);
|
||||
|
||||
ServerEventListener.get(ServerEventCode.CODE_GAME_STARTING).call(clientSide, String.valueOf(room.getId()));
|
||||
}else {
|
||||
ChannelUtils.pushToClient(clientSide.getChannel(), ClientEventCode.CODE_NOT_SUPPORT, "The current difficulty coefficient is not supported, please pay attention to the following");
|
||||
}
|
||||
preClient.setNext(clientSide);
|
||||
clientSide.setPre(preClient);
|
||||
|
||||
ServerEventListener.get(ServerEventCode.CODE_GAME_STARTING).call(clientSide, String.valueOf(room.getId()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-2
@@ -1,7 +1,6 @@
|
||||
package org.nico.ratel.landlords.server.robot;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -40,7 +39,7 @@ public class RobotEventListener_CODE_GAME_LANDLORD_ELECT implements RobotEventLi
|
||||
PokerHelper.sortPoker(leftPokers);
|
||||
PokerHelper.sortPoker(rightPokers);
|
||||
|
||||
ServerEventListener.get(ServerEventCode.CODE_GAME_LANDLORD_ELECT).call(robot, String.valueOf(RobotDecisionMakers.howToChooseLandlord(leftPokers, rightPokers, landlordPokers)));
|
||||
ServerEventListener.get(ServerEventCode.CODE_GAME_LANDLORD_ELECT).call(robot, String.valueOf(RobotDecisionMakers.howToChooseLandlord(room.getDifficultyCoefficient(), leftPokers, rightPokers, landlordPokers)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+31
-6
@@ -1,8 +1,17 @@
|
||||
package org.nico.ratel.landlords.server.robot;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.nico.ratel.landlords.channel.ChannelUtils;
|
||||
import org.nico.ratel.landlords.entity.ClientSide;
|
||||
import org.nico.ratel.landlords.entity.Poker;
|
||||
import org.nico.ratel.landlords.entity.PokerSell;
|
||||
import org.nico.ratel.landlords.entity.Room;
|
||||
import org.nico.ratel.landlords.enums.ClientEventCode;
|
||||
import org.nico.ratel.landlords.enums.ClientRole;
|
||||
import org.nico.ratel.landlords.enums.SellType;
|
||||
import org.nico.ratel.landlords.helper.MapHelper;
|
||||
import org.nico.ratel.landlords.robot.RobotDecisionMakers;
|
||||
import org.nico.ratel.landlords.server.ServerContains;
|
||||
|
||||
public class RobotEventListener_CODE_GAME_POKER_PLAY implements RobotEventListener{
|
||||
@@ -10,12 +19,28 @@ public class RobotEventListener_CODE_GAME_POKER_PLAY implements RobotEventListen
|
||||
@Override
|
||||
public void call(ClientSide robot, String data) {
|
||||
Room room = ServerContains.ROOM_MAP.get(robot.getRoomId());
|
||||
|
||||
if(room.getLastSellClient() == robot.getId()) {
|
||||
|
||||
}else {
|
||||
PokerSell lastPokerShell = room.getLastPokerShell();
|
||||
|
||||
PokerSell lastPokerShell = null;
|
||||
if(room.getLastSellClient() != robot.getId()) {
|
||||
lastPokerShell = room.getLastPokerShell();
|
||||
|
||||
PokerSell pokerSell = RobotDecisionMakers.howToPlayPokers(room.getDifficultyCoefficient(), lastPokerShell, robot.getPokers());
|
||||
if(pokerSell == null || pokerSell.getSellType() == SellType.ILLEGAL) {
|
||||
ClientSide turnClient = robot.getNext();
|
||||
for(ClientSide client: room.getClientSideList()) {
|
||||
String result = MapHelper.newInstance()
|
||||
.put("clientId", robot.getId())
|
||||
.put("clientNickname", robot.getNickname())
|
||||
.put("nextClientId", turnClient.getId())
|
||||
.put("nextClientNickname", turnClient.getNickname())
|
||||
.json();
|
||||
if(client.getRole() == ClientRole.PLAYER) {
|
||||
ChannelUtils.pushToClient(client.getChannel(), ClientEventCode.CODE_GAME_POKER_PLAY_PASS, result);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user