Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.95 KB | None | 0 0
  1. public Referee(InputStream is, PrintStream out, PrintStream err) throws IOException {
  2.         initReferee(2, new Properties());
  3.  
  4.         Scanner in = new Scanner(is);
  5.  
  6.         try {
  7.             // Read ###Start 2
  8.             in.nextLine();
  9.  
  10.             int round = 0;
  11.  
  12.             while (!gameIsOver() && round < 400) {
  13.                 out.println("###Input 0");
  14.                 if (round == 0) {
  15.                     for (String line : getInitInputForPlayer(0)) {
  16.                         out.println(line);
  17.                     }
  18.                 }
  19.                 for (String line : getInputForPlayer(round, 0)) {
  20.                     out.println(line);
  21.                 }
  22.  
  23.                 out.println("###Output 0 1");
  24.                 try {
  25.                     handlePlayerOutput(0, round, 0, new String[]{in.nextLine()});
  26.                 } catch (LostException e) {
  27.                     err.println("###Error 0 Lost " + e.getMessage());
  28.                     players.get(0).die(round);
  29.                 } catch (InvalidInputException e) {
  30.                     err.println("###Error 0 InvalidInput " + e.getMessage());
  31.                     players.get(0).die(round);
  32.                 }
  33.  
  34.                 out.println("###Input 1");
  35.                 if (round == 0) {
  36.                     for (String line : getInitInputForPlayer(1)) {
  37.                         out.println(line);
  38.                     }
  39.                 }
  40.                 for (String line : getInputForPlayer(round, 1)) {
  41.                     out.println(line);
  42.                 }
  43.  
  44.                 out.println("###Output 1 1");
  45.                 try {
  46.                     handlePlayerOutput(0, round, 1, new String[]{in.nextLine()});
  47.                 } catch (LostException e) {
  48.                     err.println("###Error 1 Lost " + e.getMessage());
  49.                     players.get(1).die(round);
  50.                 } catch (InvalidInputException e) {
  51.                     err.println("###Error 1 InvalidInput " + e.getMessage());
  52.                     players.get(1).die(round);
  53.                 }
  54.  
  55.                 try {
  56.                     updateGame(round);
  57.                 } catch (GameOverException e) {
  58.                     if (players.get(0).score > players.get(1).score) {
  59.                         out.println("###End 0 1");
  60.                     } else if (players.get(0).score < players.get(1).score) {
  61.                         out.println("###End 1 0");
  62.                     } else {
  63.                         out.println("###End 01");
  64.                     }
  65.  
  66.                     return;
  67.                 }
  68.  
  69.                 round += 1;
  70.             }
  71.  
  72.             if (players.get(0).score > players.get(1).score) {
  73.                 out.println("###End 0 1");
  74.             } else if (players.get(0).score < players.get(1).score) {
  75.                 out.println("###End 1 0");
  76.             } else {
  77.                 out.println("###End 01");
  78.             }
  79.         } finally {
  80.             in.close();
  81.         }
  82.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement