Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9962


Ignore:
Timestamp:
09/13/13 14:05:13 (11 years ago)
Author:
ascheibe
Message:

#2069 some minor fixes in the enemy detection

Location:
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3
Files:
2 edited

Legend:

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

    r9947 r9962  
    7979
    8080      if (showUI) {
    81         evaluateCodeInfo.Arguments += " true " + nrOfRounds;
     81        evaluateCodeInfo.Arguments += " true " + nrOfRounds + " ";
    8282      } else {
    83         evaluateCodeInfo.Arguments += " false " + nrOfRounds;
     83        evaluateCodeInfo.Arguments += " false " + nrOfRounds + " ";
    8484      }
    8585
    86       foreach (var enemy in enemies)
     86      foreach (var enemy in enemies.CheckedItems)
    8787        evaluateCodeInfo.Arguments += enemy.Value + "* ";
    8888
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/RobocodeProblem.cs

    r9947 r9962  
    4040  public class RobocodeProblem : SingleObjectiveHeuristicOptimizationProblem<RobocodeEvaluator,
    4141    ISymbolicExpressionTreeCreator> {
    42     #region parameter names
     42    #region Parameter Names
    4343    private const string TankProgramParameterName = "TankProgram";
    4444    private const string MaxTankProgramLengthParameterName = "MaxProgramLength";
     
    8484      robocodeDir.Value = @"C:\robocode";
    8585
    86       var robotsDir = new DirectoryInfo(Path.Combine(robocodeDir.Value, "robots"));
    87       var robotFiles = robotsDir.GetFiles("*", SearchOption.AllDirectories)
    88                                 .Where(x => x.Extension == ".class" || x.Extension == ".jar");
    89       var robotSet = new Dictionary<string, StringValue>();
    90       foreach (var robot in robotFiles) {
    91         string robotName = Path.Combine(robot.DirectoryName, Path.GetFileNameWithoutExtension(robot.FullName));
    92         robotName = robotName.Remove(0, robotsDir.FullName.Length);
    93         string[] nameParts = robotName.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
    94         robotName = string.Join(".", nameParts);
    95         robotSet[robot.FullName] = new StringValue(robotName);
    96       }
    97       var robotList = new CheckedItemList<StringValue>(robotSet.Values);
     86      var robotList = ReloadEnemies(robocodeDir.Value);
    9887
    9988      Parameters.Add(new FixedValueParameter<IntValue>(MaxTankProgramDepthParameterName, "Maximal depth of the Robocode tank program.", new IntValue(6)));
     
    11099    public override IDeepCloneable Clone(Cloner cloner) {
    111100      return new RobocodeProblem(this, cloner);
     101    }
     102
     103    private ICheckedItemList<StringValue> ReloadEnemies(string robocodeDir) {
     104      var robotsDir = new DirectoryInfo(Path.Combine(robocodeDir, "robots"));
     105      var robotFiles = robotsDir.GetFiles("*", SearchOption.AllDirectories)
     106                                .Where(x => x.Extension == ".class" || x.Extension == ".jar");
     107      var robotSet = new Dictionary<string, StringValue>();
     108      foreach (var robot in robotFiles) {
     109        string robotName = Path.Combine(robot.DirectoryName, Path.GetFileNameWithoutExtension(robot.FullName));
     110        robotName = robotName.Remove(0, robotsDir.FullName.Length);
     111        string[] nameParts = robotName.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
     112        robotName = string.Join(".", nameParts);
     113        robotSet[robot.FullName] = new StringValue(robotName);
     114      }
     115      var robotList = new CheckedItemList<StringValue>(robotSet.Values);
     116      foreach (var robot in robotList) {
     117        robotList.SetItemCheckedState(robot, false);
     118      }
     119
     120      return robotList;
    112121    }
    113122
Note: See TracChangeset for help on using the changeset viewer.