Пример #1
0
  public String startCombat(ArrayList<String> botIds, int maxTicks, String mapName) {
    _sides = new ArrayList<AbstractBot>();

    ArrayList<String> botNames = new ArrayList<String>();

    for (String botId : botIds) {
      // Utils.log("Loading botData for [" + botId + "]");

      BotData botData = null;
      try {
        botData = UsersTable.getBotData(botId);
      } catch (Exception e) {
        e.printStackTrace();
        return "Error1: " + e.getMessage();
      }

      if (botData == null) {
        return "Error2: bot not found";
      }

      Utils.log("Creating bot [" + botData.botName + "]");
      File jarFile = new File("bots/user" + botId + "/" + botData.jarName);

      try {
        URL jarURL = jarFile.toURI().toURL();
        URLClassLoader classLoader = new URLClassLoader(new URL[] {jarURL});

        Class pl = classLoader.loadClass(botData.jarName.replaceAll(".jar", "") + ".MyBot");
        AbstractBot b = (AbstractBot) pl.getConstructor(new Class[0]).newInstance(new Object[0]);

        _sides.add(b);
      } catch (Exception e) {
        e.printStackTrace();
        return "Error3: " + e.getMessage();
      }

      botNames.add(botData.botName);
      // Utils.log("Added bot "+botData.botName);
    }

    try {
      _combat = new Combat(this, botNames, maxTicks, mapName);
    } catch (Exception e) {
      e.printStackTrace();
      return "Error4: " + e.getMessage();
    }

    _combat.startCombat();
    return "";
  }
Пример #2
0
 public String getLogUrl() {
   return Combat.LOG_URL + _combat.getLog().getFileName();
 }
Пример #3
0
 public void process_finish(JSONObject cmd) {
   System.out.println("=== Simulation finished");
   System.out.println("=== Check log at " + Combat.LOG_URL + _combat.getLog().getFileName());
 }
Пример #4
0
 public void sendReady(int side) {
   _combat.processReady(side);
 }
Пример #5
0
 @Override
 public void sendOrderBuild(AbstractBot b, String type) {
   int side = _sides.indexOf(b);
   _combat.processOrderBuild(side, type);
 }
Пример #6
0
 @Override
 public void sendOrderAttack(AbstractBot b, int unitId, int targetId) {
   int side = _sides.indexOf(b);
   _combat.processOrderAttack(side, unitId, targetId);
 }
Пример #7
0
 // ==== Приказы от ботов =====================================================
 @Override
 public void sendOrderMove(AbstractBot b, int unitId, int toX, int toY) {
   int side = _sides.indexOf(b);
   _combat.processOrderMove(side, unitId, toX, toY);
 }