1 package com.codingame.game;
4 import java.util.Random;
6 import java.util.regex.Pattern;
7 import java.util.Scanner;
8 import java.util.InputMismatchException;
9 import java.util.NoSuchElementException;
11 import com.codingame.gameengine.core.AbstractMultiplayerPlayer;
12 import com.codingame.gameengine.module.entities.Group;
13 import com.codingame.gameengine.module.entities.Text;
14 import com.codingame.gameengine.module.entities.Sprite;
16 public class Player extends AbstractMultiplayerPlayer {
21 public int getExpectedOutputLines() {
25 // same-typed positional parameters… a disaster waiting to happen
26 void gameInit(int roadLength, int initialStones, long seed) {
27 sendInputLine(String.format("%d %d %d %d 0",
28 roadLength, initialStones, seed,
29 model.getMultiplier()));
34 stoneThrow = null; // correctness over stability!
35 messageString = null; //
37 sendInputLine(String.format("%d %d %d",
38 model.getTrollDistance(),
40 model.getOppStones()));
44 static enum Action { Throw, Timeout, Invalid }
49 private void reportMsg(String tag) {
50 System.err.println("Message @" + tag + ": " + messageString);
53 void receiveGameTurn() {
55 try { messageString = getOutputs().get(0); }
56 catch (TimeoutException e) { type = Action.Timeout; return; }
58 Scanner s = new Scanner(messageString);
59 try { stoneThrow = s.nextInt(); }
60 catch (InputMismatchException e) { type = Action.Invalid; return; }
61 catch (NoSuchElementException e) { type = Action.Invalid; return; }
64 if (s.hasNext(rest)) messageString = s.next(rest);
65 else messageString = "";
69 private static final Pattern rest = Pattern.compile(".*");
70 private static final Pattern eol = Pattern.compile("\n");