class Model {
@Inject private MultiplayerGameManager<com.codingame.game.Player> gameManager;
+ @Inject private LeagueManager league;
+ long seed;
Random random;
int roadLength;
int initialStones;
class Player {
com.codingame.game.Player gp;
int index;
+ boolean hit;
- Player(int i) { index = i; }
+ Player(int i) {
+ index = i;
+ hit = false;
+ }
+
+ void loseRound() {
+ hit = true;
+ winner = 1 - index;
+ }
private int castlePosition;
public int getCastlePosition() { return castlePosition; }
}
public void adjustScore(int trollPosition) {
- gp.setScore(Math.abs(castlePosition - trollPosition));
+ if (gp.isActive()) {
+ gp.setScore(Math.abs(castlePosition - trollPosition));
+ }
}
public int getTrollDistance() {
}
}
- void init(long seed) {
+ void init() {
+ seed = gameManager.getSeed();
random = new Random(seed);
- switch (random.nextInt(4)) {
- case 0:
+
+ switch(league.mapLevel) {
+ case SINGLE:
roadLength = 6;
initialStones = 15;
break;
- case 1:
- roadLength = 6;
- initialStones = 30;
- break;
- case 2:
- roadLength = 14;
- initialStones = 30;
+ case DISCRETE:
+ int i = random.nextInt(4);
+ switch (i) {
+ case 0:
+ roadLength = 6;
+ initialStones = 15;
+ break;
+ case 1:
+ roadLength = 6;
+ initialStones = 30;
+ break;
+ case 2:
+ roadLength = 14;
+ initialStones = 30;
+ break;
+ case 3:
+ roadLength = 14;
+ initialStones = 50;
+ break;
+ }
break;
- case 3:
- roadLength = 14;
- initialStones = 50;
+ case CONTINUOUS:
+ roadLength = 2 * (3 + random.nextInt(7-3+1));
+ initialStones = 15 + random.nextInt(50-15+1);
break;
}
gameManager.addToGameSummary(GameManager.formatErrorMessage("Ill-formed road length: " + buf));
}
}
+ ps.setProperty("roadLength", new Integer(roadLength).toString());
+
buf = ps.getProperty("initialStones");
if (buf != null) {
try {
gameManager.addToGameSummary(GameManager.formatErrorMessage("Ill-formed initial stone count: " + buf));
}
}
+ ps.setProperty("initialStones", new Integer(initialStones).toString());
trollPosition = roadLength / 2;
p1.setStones(initialStones);
}
- private int winner;
- boolean haveWinner() {
- if (trollPosition == 0) {
+ void moveTroll(int delta) {
+ trollPosition += delta;
+ if (trollPosition <= 0) {
+ trollPosition = 0;
winner = 1;
- return true;
}
- else if (trollPosition == roadLength) {
+ if (trollPosition >= roadLength) {
+ trollPosition = roadLength;
winner = 0;
- return true;
}
- else {
- return false;
+
+ p0.adjustScore(trollPosition);
+ p1.adjustScore(trollPosition);
+ }
+
+ boolean FIX_IT() {
+ switch (league.fixLevel) {
+ case SOMETIMES: return random.nextInt(10) > 0;
+ case NEVER: return false;
+ default: throw new JavaLimitationError();
}
}
+
+ private Integer winner;
+ boolean haveWinner() {
+ return winner != null;
+ }
+
int getWinner() { return winner; }
int getLoser() { return 1 - winner; }
boolean exhausted() {
- return p0.getStones() <= 0 && p1.getStones() <= 0;
+ return p0.getStones() <= 0 || p1.getStones() <= 0;
}
}