public void initForRobocodeEngine(IBattleListener listener) {
    final IWindowManager windowManager = Container.getComponent(IWindowManager.class);

    if (windowManager != null) {
      windowManager.setSlave(true);
      windowManager.setEnableGUI(false);
    }
    Container.getComponent(IHostManager.class).initSecurity();
    if (listener != null) {
      Container.getComponent(IBattleManager.class).addListener(listener);
    }
    Container.getComponent(ICpuManager.class).getCpuConstant();
    Container.getComponent(IRepositoryManager.class)
        .reload(versionManager.isLastRunVersionChanged());
  }
  public void run() {
    Thread.setDefaultUncaughtExceptionHandler(
        new Thread.UncaughtExceptionHandler() {
          @Override
          public void uncaughtException(Thread thread, Throwable t) {
            t.printStackTrace();
          }
        });

    try {
      hostManager.initSecurity();

      // Set the Look and Feel (LAF)
      if (windowManager != null && windowManager.isGUIEnabled()) {
        windowManager.init();
      }
      properties.setOptionsBattleDesiredTPS(setup.tps);

      battleManager.addListener(battleObserver);

      if (windowManager != null && windowManager.isGUIEnabled()) {
        if (!setup.minimize && setup.battleFilename == null && soundManager != null) {
          soundManager.playThemeMusic();
          windowManager.showSplashScreen();
        }
        windowManager.showRobocodeFrame(true, setup.minimize);
        windowManager.showBarCodeScanDialog(true);

        // Play the intro battle if a battle file is not specified and this is the first time
        // Robocode is being run

        if (setup.battleFilename == null && versionManager.isLastRunVersionChanged()) {
          properties.saveProperties();
          windowManager.runIntroBattle();
        }
      }

      final boolean enableCLIRecording =
          (setup.recordFilename != null || setup.recordXmlFilename != null);

      // Note: At this point the GUI should be opened (if enabled) before starting the battle from a
      // battle file
      if (setup.battleFilename != null) {
        if (setup.replayFilename != null) {
          System.err.println(
              "You cannot run both a battle and replay a battle record in the same time.");
          System.exit(8);
        }

        setup.exitOnComplete = true;

        battleManager.setBattleFilename(setup.battleFilename);
        if (new File(battleManager.getBattleFilename()).exists()) {
          battleManager.startNewBattle(
              battleManager.loadBattleProperties(), false, enableCLIRecording);
        } else {
          System.err.println(
              "The specified battle file '" + setup.battleFilename + "' was not found");
          System.exit(8);
        }
      } else if (setup.replayFilename != null) {
        setup.exitOnComplete = true;
        if (setup.replayFilename.toLowerCase().endsWith("xml.zip")) {
          recordManager.loadRecord(setup.replayFilename, BattleRecordFormat.XML_ZIP);
        } else {
          recordManager.loadRecord(setup.replayFilename, BattleRecordFormat.BINARY_ZIP);
        }

        if (new File(setup.replayFilename).exists()) {
          battleManager.replay();
        } else {
          System.err.println(
              "The specified battle record file '" + setup.replayFilename + "' was not found");
          System.exit(8);
        }
      }
    } catch (Throwable e) {
      Logger.logError(e);
    }
  }