@@ -172,42 +172,48 @@ void start(InputStream is, PrintStream out) {
172172 * The amount of expected output lines from the player.
173173 */
174174 protected void execute (T player , int nbrOutputLines ) {
175- if (!this .initDone ) {
176- throw new RuntimeException ("Impossible to execute a player during init phase." );
177- }
175+ try {
176+ if (!this .initDone ) {
177+ throw new RuntimeException ("Impossible to execute a player during init phase." );
178+ }
178179
179- player .setTimeout (false );
180+ player .setTimeout (false );
180181
181- InputCommand iCmd = InputCommand .parse (s .nextLine ());
182+ InputCommand iCmd = InputCommand .parse (s .nextLine ());
182183
183- if (iCmd .cmd != InputCommand .Command .GET_GAME_INFO ) {
184- throw new RuntimeException ("Invalid command: " + iCmd .cmd );
185- }
184+ if (iCmd .cmd != InputCommand .Command .GET_GAME_INFO ) {
185+ throw new RuntimeException ("Invalid command: " + iCmd .cmd );
186+ }
186187
187- dumpView ();
188- dumpInfos ();
189- dumpNextPlayerInput (player .getInputs ().toArray (new String [0 ]));
190- if (nbrOutputLines > 0 ) {
191- addTurnTime ();
192- }
193- dumpNextPlayerInfos (player .getIndex (), nbrOutputLines , player .hasNeverBeenExecuted () ? firstTurnMaxTime : turnMaxTime );
194-
195- // READ PLAYER OUTPUTS
196- iCmd = InputCommand .parse (s .nextLine ());
197- if (iCmd .cmd == InputCommand .Command .SET_PLAYER_OUTPUT ) {
198- List <String > output = new ArrayList <>(iCmd .lineCount );
199- for (int i = 0 ; i < iCmd .lineCount ; i ++) {
200- output .add (s .nextLine ());
188+ dumpView ();
189+ dumpInfos ();
190+ dumpNextPlayerInput (player .getInputs ().toArray (new String [0 ]));
191+ if (nbrOutputLines > 0 ) {
192+ addTurnTime ();
193+ }
194+ dumpNextPlayerInfos (player .getIndex (), nbrOutputLines , player .hasNeverBeenExecuted () ? firstTurnMaxTime : turnMaxTime );
195+
196+ // READ PLAYER OUTPUTS
197+ iCmd = InputCommand .parse (s .nextLine ());
198+ if (iCmd .cmd == InputCommand .Command .SET_PLAYER_OUTPUT ) {
199+ List <String > output = new ArrayList <>(iCmd .lineCount );
200+ for (int i = 0 ; i < iCmd .lineCount ; i ++) {
201+ output .add (s .nextLine ());
202+ }
203+ player .setOutputs (output );
204+ } else if (iCmd .cmd == InputCommand .Command .SET_PLAYER_TIMEOUT ) {
205+ player .setTimeout (true );
206+ } else {
207+ throw new RuntimeException ("Invalid command: " + iCmd .cmd );
201208 }
202- player .setOutputs (output );
203- } else if (iCmd .cmd == InputCommand .Command .SET_PLAYER_TIMEOUT ) {
204- player .setTimeout (true );
205- } else {
206- throw new RuntimeException ("Invalid command: " + iCmd .cmd );
207- }
208209
209- player .resetInputs ();
210- newTurn = false ;
210+ player .resetInputs ();
211+ newTurn = false ;
212+ } catch (RuntimeException e ) {
213+ //Don't let the user catch game fail exceptions
214+ dumpFail (e );
215+ throw e ;
216+ }
211217 }
212218
213219 /**
0 commit comments