From caec047c72e7e232badecce4ee2e1e8a63279333 Mon Sep 17 00:00:00 2001 From: nico Date: Mon, 5 Nov 2018 21:17:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=8C=E7=9A=84=E7=B1=BB=E5=9E=8B=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/nico/ratel/landlords/entity/Room.java | 11 +++ .../nico/ratel/landlords/enums/SellType.java | 56 ++++++++++++ .../ServerEventListener_CODE_PLAY_ROUND.java | 2 +- .../server/event/helper/PokerHelper.java | 90 ++++++++++++++++--- 4 files changed, 145 insertions(+), 14 deletions(-) create mode 100644 landlords-common/src/main/java/org/nico/ratel/landlords/enums/SellType.java diff --git a/landlords-common/src/main/java/org/nico/ratel/landlords/entity/Room.java b/landlords-common/src/main/java/org/nico/ratel/landlords/entity/Room.java index faa5adc..a9bb66c 100644 --- a/landlords-common/src/main/java/org/nico/ratel/landlords/entity/Room.java +++ b/landlords-common/src/main/java/org/nico/ratel/landlords/entity/Room.java @@ -7,6 +7,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentSkipListMap; import org.nico.ratel.landlords.enums.RoomStatus; +import org.nico.ratel.landlords.enums.SellType; public class Room implements Serializable{ @@ -26,6 +27,8 @@ public class Room implements Serializable{ private List lastSellPokers; + private SellType sellType; + private int lastSellClient; public Room(int id) { @@ -35,6 +38,14 @@ public class Room implements Serializable{ this.status = RoomStatus.BLANK; } + public final SellType getSellType() { + return sellType; + } + + public final void setSellType(SellType sellType) { + this.sellType = sellType; + } + public int getLastSellClient() { return lastSellClient; } diff --git a/landlords-common/src/main/java/org/nico/ratel/landlords/enums/SellType.java b/landlords-common/src/main/java/org/nico/ratel/landlords/enums/SellType.java new file mode 100644 index 0000000..c0de62c --- /dev/null +++ b/landlords-common/src/main/java/org/nico/ratel/landlords/enums/SellType.java @@ -0,0 +1,56 @@ +package org.nico.ratel.landlords.enums; + +import java.io.Serializable; + +public enum SellType implements Serializable{ + + ILLEGAL("非合法"), + + ROCKET("火箭"), + + BOMB("炸弹"), + + KING_BOMB("王炸"), + + SINGLE("单个牌"), + + DOUBLE("对子牌"), + + THREE("三张牌"), + + THREE_ZONES_A("三带一"), + + THREE_ZONES_TWO("三带二"), + + SINGLE_STRAIGHT("单顺子"), + + DOUBLE_STRAIGHT("双顺子"), + + THREE_STRAIGHT("三顺子"), + + FOUR_STRAIGHT("四顺子"), + + THREE_STRAIGHT_WITH_SINGLE("飞机带单牌"), + + THREE_STRAIGHT_WITH_DOUBLE("飞机带对牌"), + + FOUR_STRAIGHT_WITH_SINGLE("四顺子带单"), + + FOUR_STRAIGHT_WITH_DOUBLE("四顺子带对"), + ; + + private String msg; + + private SellType(String msg) { + this.msg = msg; + } + + public final String getMsg() { + return msg; + } + + public final void setMsg(String msg) { + this.msg = msg; + } + +} diff --git a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_PLAY_ROUND.java b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_PLAY_ROUND.java index 9458d5e..b4212fb 100644 --- a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_PLAY_ROUND.java +++ b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_PLAY_ROUND.java @@ -18,7 +18,7 @@ public class ServerEventListener_CODE_PLAY_ROUND implements ServerEventListener< Room room = ServerContains.ROOM_MAP.get(clientSide.getRoomId()); int[] indexes = serverTransferData.getData(); - if(PokerHelper.checkPoker(indexes, clientSide.getPokers())){ + if(PokerHelper.checkPokerIndex(indexes, clientSide.getPokers())){ if(room.getLastSellClient() != clientSide.getId() && room.getLastSellPokers() != null){ // Compare the brand }else{ diff --git a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/helper/PokerHelper.java b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/helper/PokerHelper.java index c83899e..c462ca4 100644 --- a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/helper/PokerHelper.java +++ b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/helper/PokerHelper.java @@ -8,22 +8,23 @@ import java.util.List; import org.nico.ratel.landlords.entity.Poker; import org.nico.ratel.landlords.enums.PokerLevel; import org.nico.ratel.landlords.enums.PokerType; +import org.nico.ratel.landlords.enums.SellType; public class PokerHelper { private static List basePokers = new ArrayList(54); - + private static Comparator pokerComparator = new Comparator() { @Override public int compare(Poker o1, Poker o2) { return o1.getLevel().getLevel() - o2.getLevel().getLevel(); } }; - + static { PokerLevel[] pokerLevels = PokerLevel.values(); PokerType[] pokerTypes = PokerType.values(); - + for(PokerLevel level: pokerLevels) { if(level == PokerLevel.LEVEL_BIG_KING) { basePokers.add(new Poker(level, PokerType.BLANK)); @@ -41,12 +42,12 @@ public class PokerHelper { } } } - + public static void sortPoker(List pokers){ Collections.sort(pokers, pokerComparator); } - - public static boolean checkPoker(int[] indexes, List pokers){ + + public static boolean checkPokerIndex(int[] indexes, List pokers){ boolean access = true; for(int index: indexes){ if(index >= pokers.size()){ @@ -55,7 +56,70 @@ public class PokerHelper { } return access; } - + + public static SellType checkPokerType(List pokers) { + if(pokers != null && pokers.isEmpty()) { + sortPoker(pokers); + + int[] levelTable = new int[20]; + for(Poker poker: pokers) { + levelTable[poker.getLevel().getLevel()] ++; + } + + int startIndex = -1; + int endIndex = -1; + int count = -1; + + int singleCount = 0; + int doubleCount = 0; + int threeCount = 0; + int fourCount = 0; + for(int index = 0; index < levelTable.length; index ++) { + int value = levelTable[index]; + if(value != 0) { + endIndex = index; + count ++; + if(startIndex == -1) { + startIndex = index; + } + if(value == 1) { + singleCount ++; + }else if(value == 2) { + doubleCount ++; + }else if(value == 3) { + threeCount ++; + }else if(value == 4) { + fourCount ++; + } + } + } + if(count == 1) { + if(levelTable[startIndex] == 1) { + return SellType.SINGLE; + }else if(levelTable[startIndex] == 2) { + return SellType.DOUBLE; + }else if(levelTable[startIndex] == 3) { + return SellType.THREE; + }else if(levelTable[startIndex] == 4) { + return SellType.BOMB; + } + } + if(endIndex - startIndex == count - 1 && endIndex < PokerLevel.LEVEL_2.getLevel()) { + if(levelTable[startIndex] == 1) { + return SellType.SINGLE_STRAIGHT; + }else if(levelTable[startIndex] == 2) { + return SellType.DOUBLE_STRAIGHT; + }else if(levelTable[startIndex] == 3) { + return SellType.THREE_STRAIGHT; + }else if(levelTable[startIndex] == 4) { + return SellType.FOUR_STRAIGHT; + } + } + + } + return SellType.ILLEGAL; + } + public static List getPoker(int[] indexes, List pokers){ List resultPokers = new ArrayList<>(indexes.length); for(int index: indexes){ @@ -64,12 +128,12 @@ public class PokerHelper { sortPoker(resultPokers); return resultPokers; } - + public static boolean comparePoker(List pres, List currents){ - + return true; } - + public static List> distributePoker(){ Collections.shuffle(basePokers); List> pokersList = new ArrayList>(); @@ -90,12 +154,12 @@ public class PokerHelper { } return pokersList; } - + public static String unfoldPoker(List pokers, boolean serialFlag) { sortPoker(pokers); StringBuilder builder = new StringBuilder(); if(pokers != null && pokers.size() > 0) { - + for(int index = 0; index < pokers.size(); index ++) { if(index == 0) { builder.append("Poker: ┌──┐"); @@ -144,7 +208,7 @@ public class PokerHelper { } return builder.toString(); } - + public static void main(String[] args) { List> pokersList = distributePoker(); System.out.println(unfoldPoker(pokersList.get(3), false));