Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9898 for branches


Ignore:
Timestamp:
08/22/13 15:16:13 (11 years ago)
Author:
ascheibe
Message:

#2069 added automatic discovery of robocode jars

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Interpreter.cs

    r9892 r9898  
    3636      string interpretedProgram = InterpretProgramTree(tree.Root, robotName);
    3737      string battleRunnerPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
     38      string roboCodeLibPath = Path.Combine(path, "libs");
     39      string robocodeJar = Path.Combine(roboCodeLibPath, "robocode.jar");
     40      string robocodeCoreJar = GetFileName(roboCodeLibPath, "robocode.core*");
     41      string picocontainerJar = GetFileName(roboCodeLibPath, "picocontainer*");
     42      string robotsPath = Path.Combine(path, "robots", "Evaluation");
     43      string srcRobotPath = Path.Combine(robotsPath, robotName + ".java");
    3844
    3945      try {
    40         File.WriteAllText(path + "/robots/Evaluation/" + robotName + ".java", interpretedProgram, System.Text.Encoding.Default);
     46        File.WriteAllText(srcRobotPath, interpretedProgram, System.Text.Encoding.Default);
    4147      }
    4248      catch (Exception ex) {
     
    4652      ProcessStartInfo javaCompileInfo = new ProcessStartInfo();
    4753      javaCompileInfo.FileName = "cmd.exe";
    48       javaCompileInfo.Arguments = "/C javac -cp " + path + "\\libs\\robocode.jar " +
    49                                   path + "\\robots\\Evaluation\\" + robotName + ".java";
     54      javaCompileInfo.Arguments = "/C javac -cp " + robocodeJar + "; " + srcRobotPath;
    5055      javaCompileInfo.RedirectStandardOutput = true;
    5156      javaCompileInfo.RedirectStandardError = true;
     
    6772
    6873      //parallel execution of multiple robocode instances can sometimes lead to a damaged robot.database
    69       try { File.Delete(path + "/robots/robot.database"); }
     74      try { File.Delete(path + @"\robots\robot.database"); }
    7075      catch { }
    7176
     
    7378
    7479      evaluateCodeInfo.FileName = "cmd.exe";
    75       evaluateCodeInfo.Arguments = "/C java -classpath " + battleRunnerPath + ";" + path + "\\libs\\robocode.core-1.8.1.0.jar;" + path + "\\libs\\robocode.jar;" +
    76                                    path + "\\libs\\picocontainer-2.14.2.jar BattleRunner Evaluation." +
    77                                    robotName + "* " + path;
     80      evaluateCodeInfo.Arguments = "/C java -cp " + battleRunnerPath + ";" + robocodeCoreJar + ";" + robocodeJar +
     81                                  ";" + picocontainerJar + ";" + " BattleRunner Evaluation." + robotName + "* " + path;
     82
    7883      if (showUI)
    7984        evaluateCodeInfo.Arguments += " true";
     
    97102      double evaluation = -1.0;
    98103      try {
    99         scoreString = evaluateCode.StandardOutput.ReadToEnd().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Last();
     104        scoreString = evaluateCode.StandardOutput.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Last();
    100105        evaluation = Double.Parse(scoreString, CultureInfo.InvariantCulture);
    101106      }
     
    112117    private static void DeleteRobotFiles(string path, string outputname) {
    113118      try {
    114         File.Delete(path + "/robots/Evaluation/" + outputname + ".java");
    115         File.Delete(path + "/robots/Evaluation/" + outputname + ".class");
     119        File.Delete(path + @"\robots\Evaluation\" + outputname + ".java");
     120        File.Delete(path + @"\robots\Evaluation\" + outputname + ".class");
    116121      }
    117122      catch { }
     123    }
     124
     125    private static string GetFileName(string path, string pattern) {
     126      string fileName = string.Empty;
     127      try {
     128        fileName = Directory.GetFiles(path, pattern).First();
     129      }
     130      catch {
     131        throw new Exception("Error finding required RoboCode files.");
     132      }
     133      return fileName;
    118134    }
    119135
Note: See TracChangeset for help on using the changeset viewer.