1 package com.codingame.game;
3 import java.util.Random;
5 import com.codingame.gameengine.core.MultiplayerGameManager;
6 import com.google.inject.Inject;
9 @Inject private MultiplayerGameManager<com.codingame.game.Player> gameManager;
17 com.codingame.game.Player gp;
20 Player(int i) { index = i; }
22 private int castlePosition;
23 public int getCastlePosition() { return castlePosition; }
24 public void setCastlePosition(int pos) { castlePosition = pos; }
26 private int multiplier;
27 public int getMultiplier() { return multiplier; }
28 public void setMultiplier(int m){ multiplier = m; }
31 public int getStones() { return stones; }
32 public void consumeStones(int n) throws InvalidAction {
34 throw new InvalidAction("attempted to throw more stones than they had.");
36 setStones(stones - n);
38 public void setStones(int n) {
41 public int getOppStones() {
42 return p0.stones + p1.stones - stones;
45 public void adjustScore(int trollPosition) {
46 gp.setScore(Math.abs(castlePosition - trollPosition));
49 public int getTrollDistance() {
50 return Math.abs(castlePosition - trollPosition);
54 void init(long seed) {
55 random = new Random(seed);
56 switch (random.nextInt(4)) {
75 trollPosition = roadLength / 2;
78 p0.gp = gameManager.getPlayer(0);
79 p0.setCastlePosition(0);
81 p0.adjustScore(trollPosition);
82 p0.setStones(initialStones);
85 p1.gp = gameManager.getPlayer(1);
86 p1.setCastlePosition(roadLength);
88 p1.adjustScore(trollPosition);
89 p1.setStones(initialStones);
93 boolean haveWinner() {
94 if (trollPosition == 0) {
98 else if (trollPosition == roadLength) {
106 int getWinner() { return winner; }
108 boolean exhausted() {
109 return p0.getStones() <= 0 && p1.getStones() <= 0;