mirror of
https://github.com/tiennm99/caro.git
synced 2026-08-07 20:22:02 +00:00
add baseScore select
This commit is contained in:
+44
-17
@@ -16,27 +16,54 @@ public class ClientEventListener_CODE_GAME_LANDLORD_ELECT extends ClientEventLis
|
||||
@Override
|
||||
public void call(Channel channel, String data) {
|
||||
Map<String, Object> map = MapHelper.parser(data);
|
||||
int turnClientId = (int) map.get("nextClientId");
|
||||
|
||||
int turnClientId = (Integer)map.get("nextClientId");
|
||||
int highestScore = (Integer)map.get("highestScore");
|
||||
if (map.containsKey("preClientNickname")) {
|
||||
SimplePrinter.printNotice(map.get("preClientNickname") + " don't rob the landlord!");
|
||||
if (highestScore != 0 && map.get("preClientId") == map.get("currentLandlordId")) {
|
||||
SimplePrinter.printNotice(map.get("preClientNickname") + " robs the landlord with " + highestScore + " score" + (highestScore == 1 ? "" : "s") + "!");
|
||||
} else {
|
||||
SimplePrinter.printNotice(map.get("preClientNickname") + " don't rob the landlord!");
|
||||
}
|
||||
}
|
||||
|
||||
if(turnClientId == SimpleClient.id) {
|
||||
SimplePrinter.printNotice("It's your turn. Do you want to rob the landlord? [Y/N] (enter [exit|e] to exit current room)");
|
||||
String line = SimpleWriter.write(User.INSTANCE.getNickname(), "Y/N");
|
||||
if (line.equalsIgnoreCase("exit") || line.equalsIgnoreCase("e")) {
|
||||
pushToServer(channel, ServerEventCode.CODE_CLIENT_EXIT);
|
||||
} else if (line.equalsIgnoreCase("Y")) {
|
||||
pushToServer(channel, ServerEventCode.CODE_GAME_LANDLORD_ELECT, "TRUE");
|
||||
} else if (line.equalsIgnoreCase("N")) {
|
||||
pushToServer(channel, ServerEventCode.CODE_GAME_LANDLORD_ELECT, "FALSE");
|
||||
} else {
|
||||
SimplePrinter.printNotice("Invalid options");
|
||||
call(channel, data);
|
||||
}
|
||||
} else {
|
||||
if (turnClientId != SimpleClient.id) {
|
||||
SimplePrinter.printNotice("It's " + map.get("nextClientNickname") + "'s turn. Please wait patiently for his/her confirmation !");
|
||||
} else {
|
||||
String message = "It's your turn. What score do you want to rob the landlord? [0";
|
||||
|
||||
for(int i = highestScore + 1; i <= 3; ++i) {
|
||||
message = message + "/" + i;
|
||||
}
|
||||
|
||||
message = message + "] (enter [exit|e] to exit current room)";
|
||||
SimplePrinter.printNotice(message);
|
||||
String line = SimpleWriter.write("getScore");
|
||||
if (!line.equalsIgnoreCase("exit") && !line.equalsIgnoreCase("e")) {
|
||||
try {
|
||||
int currentScore = Integer.parseInt(line);
|
||||
if (currentScore <= highestScore && currentScore != 0 || currentScore > 3) {
|
||||
SimplePrinter.printNotice("Invalid options");
|
||||
this.call(channel, data);
|
||||
return;
|
||||
}
|
||||
|
||||
String result;
|
||||
if (currentScore > highestScore) {
|
||||
result = MapHelper.newInstance().put("highestScore", currentScore).put("currentLandlordId", SimpleClient.id).json();
|
||||
} else if (map.containsKey("currentLandlordId")) {
|
||||
result = MapHelper.newInstance().put("highestScore", highestScore).put("currentLandlordId", (Integer)map.get("currentLandlordId")).json();
|
||||
} else {
|
||||
result = MapHelper.newInstance().put("highestScore", 0).json();
|
||||
}
|
||||
|
||||
this.pushToServer(channel, ServerEventCode.CODE_GAME_LANDLORD_ELECT, result);
|
||||
} catch (Exception e) {
|
||||
SimplePrinter.printNotice("Invalid options");
|
||||
this.call(channel, data);
|
||||
}
|
||||
} else {
|
||||
this.pushToServer(channel, ServerEventCode.CODE_CLIENT_EXIT);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -18,6 +18,8 @@ public class ClientSide {
|
||||
|
||||
private int scoreInc;
|
||||
|
||||
private int round;
|
||||
|
||||
private String nickname;
|
||||
|
||||
private List<Poker> pokers;
|
||||
@@ -54,6 +56,18 @@ public class ClientSide {
|
||||
score = 0;
|
||||
}
|
||||
|
||||
public final void resetRound() {
|
||||
round = 0;
|
||||
}
|
||||
|
||||
public final int getRound() {
|
||||
return round;
|
||||
}
|
||||
|
||||
public final void addRound() {
|
||||
round += 1;
|
||||
}
|
||||
|
||||
public final ClientRole getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,5 +16,5 @@ public abstract class AbstractRobotDecisionMakers {
|
||||
|
||||
public abstract PokerSell howToPlayPokers(PokerSell lastPokerSell, ClientSide robot);
|
||||
|
||||
public abstract boolean howToChooseLandlord(List<Poker> leftPokers, List<Poker> rightPokers, List<Poker> myPokers);
|
||||
public abstract int getLandlordScore(List<Poker> leftPokers, List<Poker> rightPokers, List<Poker> myPokers);
|
||||
}
|
||||
|
||||
+16
-3
@@ -51,10 +51,23 @@ public class EasyRobotDecisionMakers extends AbstractRobotDecisionMakers {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean howToChooseLandlord(List<Poker> leftPokers, List<Poker> rightPokers, List<Poker> myPokers) {
|
||||
public int getLandlordScore(List<Poker> leftPokers, List<Poker> rightPokers, List<Poker> myPokers) {
|
||||
List<PokerSell> leftSells = PokerHelper.parsePokerSells(leftPokers);
|
||||
List<PokerSell> mySells = PokerHelper.parsePokerSells(myPokers);
|
||||
List<PokerSell> rightSells = PokerHelper.parsePokerSells(rightPokers);
|
||||
return mySells.size() > leftSells.size() && mySells.size() > rightSells.size();
|
||||
}
|
||||
int expectedScore = 0;
|
||||
if (mySells.size() > leftSells.size()) {
|
||||
++expectedScore;
|
||||
}
|
||||
|
||||
if (mySells.size() > rightSells.size()) {
|
||||
++expectedScore;
|
||||
}
|
||||
|
||||
if (expectedScore != 0) {
|
||||
++expectedScore;
|
||||
}
|
||||
|
||||
return expectedScore;
|
||||
}
|
||||
}
|
||||
|
||||
+15
-2
@@ -129,11 +129,24 @@ public class MediumRobotDecisionMakers extends AbstractRobotDecisionMakers {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean howToChooseLandlord(List<Poker> leftPokers, List<Poker> rightPokers, List<Poker> myPokers) {
|
||||
public int getLandlordScore(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;
|
||||
int expectedScore = 0;
|
||||
if (myScore >= Math.min(leftScore, rightScore)) {
|
||||
++expectedScore;
|
||||
}
|
||||
|
||||
if (myScore * 2 >= leftScore + rightScore) {
|
||||
++expectedScore;
|
||||
}
|
||||
|
||||
if (myScore >= Math.max(leftScore, rightScore)) {
|
||||
++expectedScore;
|
||||
}
|
||||
|
||||
return expectedScore;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -30,8 +30,8 @@ public class RobotDecisionMakers {
|
||||
return decisionMakersMap.get(difficultyCoefficient).howToPlayPokers(lastPokerSell, robot);
|
||||
}
|
||||
|
||||
public static boolean howToChooseLandlord(int difficultyCoefficient, List<Poker> leftPokers, List<Poker> rightPokers, List<Poker> myPokers) {
|
||||
return decisionMakersMap.get(difficultyCoefficient).howToChooseLandlord(leftPokers, rightPokers, myPokers);
|
||||
public static int getLandlordScore(int difficultyCoefficient, List<Poker> leftPokers, List<Poker> rightPokers, List<Poker> myPokers) {
|
||||
return decisionMakersMap.get(difficultyCoefficient).getLandlordScore(leftPokers, rightPokers, myPokers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user