Example #1
0
  public void run() throws IOException {
    try {
      remoteProcessClient.writeToken(token);
      int teamSize = remoteProcessClient.readTeamSize();
      remoteProcessClient.writeProtocolVersion();
      Game game = remoteProcessClient.readGameContext();

      Strategy[] strategies = new Strategy[teamSize];

      for (int strategyIndex = 0; strategyIndex < teamSize; ++strategyIndex) {
        strategies[strategyIndex] = new MyStrategy();
      }

      PlayerContext playerContext;

      while ((playerContext = remoteProcessClient.readPlayerContext()) != null) {
        Car[] playerCars = playerContext.getCars();
        if (playerCars == null || playerCars.length != teamSize) {
          break;
        }

        Move[] moves = new Move[teamSize];

        for (int carIndex = 0; carIndex < teamSize; ++carIndex) {
          Car playerCar = playerCars[carIndex];

          Move move = new Move();
          moves[carIndex] = move;
          strategies[playerCar.getTeammateIndex()].move(
              playerCar, playerContext.getWorld(), game, move);
        }

        remoteProcessClient.writeMoves(moves);
      }
    } finally {
      remoteProcessClient.close();
    }
  }