Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Referee(InputStream is, PrintStream out, PrintStream err) throws IOException {
- initReferee(2, new Properties());
- Scanner in = new Scanner(is);
- try {
- // Read ###Start 2
- in.nextLine();
- int round = 0;
- while (!gameIsOver() && round < 400) {
- out.println("###Input 0");
- if (round == 0) {
- for (String line : getInitInputForPlayer(0)) {
- out.println(line);
- }
- }
- for (String line : getInputForPlayer(round, 0)) {
- out.println(line);
- }
- out.println("###Output 0 1");
- try {
- handlePlayerOutput(0, round, 0, new String[]{in.nextLine()});
- } catch (LostException e) {
- err.println("###Error 0 Lost " + e.getMessage());
- players.get(0).die(round);
- } catch (InvalidInputException e) {
- err.println("###Error 0 InvalidInput " + e.getMessage());
- players.get(0).die(round);
- }
- out.println("###Input 1");
- if (round == 0) {
- for (String line : getInitInputForPlayer(1)) {
- out.println(line);
- }
- }
- for (String line : getInputForPlayer(round, 1)) {
- out.println(line);
- }
- out.println("###Output 1 1");
- try {
- handlePlayerOutput(0, round, 1, new String[]{in.nextLine()});
- } catch (LostException e) {
- err.println("###Error 1 Lost " + e.getMessage());
- players.get(1).die(round);
- } catch (InvalidInputException e) {
- err.println("###Error 1 InvalidInput " + e.getMessage());
- players.get(1).die(round);
- }
- try {
- updateGame(round);
- } catch (GameOverException e) {
- if (players.get(0).score > players.get(1).score) {
- out.println("###End 0 1");
- } else if (players.get(0).score < players.get(1).score) {
- out.println("###End 1 0");
- } else {
- out.println("###End 01");
- }
- return;
- }
- round += 1;
- }
- if (players.get(0).score > players.get(1).score) {
- out.println("###End 0 1");
- } else if (players.get(0).score < players.get(1).score) {
- out.println("###End 1 0");
- } else {
- out.println("###End 01");
- }
- } finally {
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement