1 package com.codingame.game;
5 import java.util.regex.Pattern;
6 import java.util.Scanner;
7 import java.util.InputMismatchException;
8 import java.util.NoSuchElementException;
10 import com.codingame.gameengine.core.AbstractMultiplayerPlayer;
11 import com.codingame.gameengine.module.entities.Group;
12 import com.codingame.gameengine.module.entities.Text;
13 import com.codingame.gameengine.module.entities.Sprite;
15 public class Player extends AbstractMultiplayerPlayer {
20 public int getExpectedOutputLines() {
24 // same-typed positional parameters… a disaster waiting to happen
25 void gameInit(int roadLength, int initialStones, long seed) {
26 sendInputLine(String.format("%d %d %d",
27 roadLength, initialStones, seed));
32 stoneThrow = null; // correctness over stability!
33 messageString = null; //
35 sendInputLine(String.format("%d %d %d",
36 model.getTrollDistance(),
38 model.getOppStones()));
42 static enum Action { Throw, Timeout, Invalid }
47 private void reportMsg(String tag) {
48 System.err.println("Message @" + tag + ": " + messageString);
51 void receiveGameTurn() {
53 try { messageString = getOutputs().get(0); }
54 catch (TimeoutException e) { type = Action.Timeout; return; }
56 Scanner s = new Scanner(messageString);
57 try { stoneThrow = s.nextInt(); }
58 catch (InputMismatchException e) { type = Action.Invalid; return; }
59 catch (NoSuchElementException e) { type = Action.Invalid; return; }
62 if (s.hasNext(rest)) messageString = s.next(rest);
63 else messageString = "";
67 private static final Pattern rest = Pattern.compile(".*");
68 private static final Pattern eol = Pattern.compile("\n");