Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9947


Ignore:
Timestamp:
09/11/13 15:21:01 (11 years ago)
Author:
jkarder
Message:

#2069:

  • modified the RobocodeProblem to extract all robots in robocode directory
  • modified the battle runner to take a number of enemies that should be battled
Location:
branches/Robocode.TrunkInt
Files:
9 edited

Legend:

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

    r9926 r9947  
    5050
    5151    private void btnRunInRobocode_Click(object sender, EventArgs e) {
    52       Interpreter.EvaluateTankProgram(Content.Tree, Content.Path, programName, true, Content.NrOfRounds);
     52      Interpreter.EvaluateTankProgram(Content.Tree, Content.Path, Content.Enemies, programName, true, Content.NrOfRounds);
    5353    }
    5454  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/BestSolutionAnalyzer.cs

    r9926 r9947  
    4040    private const string RobocodePathParamaterName = "RobocodePath";
    4141    private const string NrOfRoundsParameterName = "NrOfRounds";
     42    private const string EnemiesParameterName = "Enemies";
    4243
    4344    public bool EnabledByDefault {
     
    6465      get { return (ILookupParameter<IntValue>)Parameters[NrOfRoundsParameterName]; }
    6566    }
     67    public ILookupParameter<ICheckedItemList<StringValue>> EnemiesParameter {
     68      get { return (ILookupParameter<ICheckedItemList<StringValue>>)Parameters[EnemiesParameterName]; }
     69    }
    6670    #endregion
    6771
     
    7882      Parameters.Add(new LookupParameter<DirectoryValue>(RobocodePathParamaterName, "Path of the Robocode installation."));
    7983      Parameters.Add(new LookupParameter<IntValue>(NrOfRoundsParameterName, "Nr. of Rounds a Robot has to fight against each opponent."));
     84      Parameters.Add(new LookupParameter<ICheckedItemList<StringValue>>(EnemiesParameterName, "The enemies that should be battled."));
    8085    }
    8186
     
    97102
    98103      // create a solution instance
    99       var bestSolution = new Solution(bestTree, RobocodePathParameter.ActualValue.Value, NrOfRoundsParameter.ActualValue.Value);
     104      var bestSolution = new Solution(bestTree, RobocodePathParameter.ActualValue.Value, NrOfRoundsParameter.ActualValue.Value, EnemiesParameter.ActualValue);
    100105      // store the new solution in the best solution parameter
    101106      BestSolutionParameter.ActualValue = bestSolution;
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/External Evaluator/BattleRunner.java

    r9926 r9947  
    2727//
    2828public class BattleRunner {
    29     static String[] defaultRobots = new String[] {
    30         "Evaluation.BestSolution*",
    31         "sample.Corners",
    32         "sample.Crazy",
    33         "sample.Fire",
    34         "sample.TrackFire",
    35         "sample.Walls",
    36         "sample.SpinBot",
    37         "sample.SittingDuck"
    38     };
    3929    public static String player = "Evaluation.output*";   
    4030    public static List<Double> score = new ArrayList<Double>();
     
    4535  // The fourth argument is the number of rounds.
    4636  public static void main(String[] args) {
     37    if (args.length < 5)
     38      System.exit(-1); 
     39
    4740    String roboCodePath = "C:\\robocode";
    4841    Boolean visible = false;   
    4942    String bots = "";
    5043    int numberOfRounds = 3;
    51         String[] robots = new String[defaultRobots.length];
    52         robots = defaultRobots.clone();   
    53  
    54     if (args.length == 1)
    55         {
    56             robots[0] = args[0];           
    57       player = args[0];           
    58         }
    59         else if (args.length == 2)
    60         {
    61             robots[0] = args[0];           
    62       player = args[0];       
    63       roboCodePath = args[1];           
    64         }
    65     else if (args.length == 3)
    66         {
    67             robots[0] = args[0];           
    68       player = args[0];       
    69       roboCodePath = args[1];
    70             visible = Boolean.valueOf(args[2]);
    71         }
    72     else if (args.length == 4)
    73         {
    74             robots[0] = args[0];           
    75       player = args[0];       
    76       roboCodePath = args[1];
    77             visible = Boolean.valueOf(args[2]);
    78       numberOfRounds = Integer.valueOf(args[3]);
    79         }
    80         else
    81     {
    82             System.exit(-1);
    83     }   
     44        String[] robots = new String[1 + args.length - 4];     
     45
     46    player = robots[0] = args[0];       
     47    roboCodePath = args[1];
     48    visible = Boolean.valueOf(args[2]);
     49    numberOfRounds = Integer.valueOf(args[3]);
     50    for (int i = 4; i < args.length; i++)
     51      robots[i - 3] = args[i];
    8452
    8553        RobocodeEngine.setLogMessagesEnabled(false);
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Interpreter.cs

    r9926 r9947  
    2626using System.Linq;
    2727using System.Reflection;
     28using HeuristicLab.Core;
     29using HeuristicLab.Data;
    2830using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2931
    3032namespace HeuristicLab.Problems.Robocode {
    3133  public static class Interpreter {
    32     public static double EvaluateTankProgram(ISymbolicExpressionTree tree, string path, string robotName = null, bool showUI = false, int nrOfRounds = 3) {
     34    public static double EvaluateTankProgram(ISymbolicExpressionTree tree, string path, ICheckedItemList<StringValue> enemies, string robotName = null, bool showUI = false, int nrOfRounds = 3) {
    3335      if (robotName == null)
    3436        robotName = GenerateRobotName();
     
    8183        evaluateCodeInfo.Arguments += " false " + nrOfRounds;
    8284      }
     85
     86      foreach (var enemy in enemies)
     87        evaluateCodeInfo.Arguments += enemy.Value + "* ";
    8388
    8489      evaluateCodeInfo.RedirectStandardOutput = true;
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/RobocodeEvaluator.cs

    r9926 r9947  
    3737    private const string RobocodePathParamaterName = "RobocodePath";
    3838    private const string NrOfRoundsParameterName = "NrOfRounds";
     39    private const string EnemiesParameterName = "Enemies";
    3940
    4041    #region Parameters
     
    5152      get { return (ILookupParameter<IntValue>)Parameters[NrOfRoundsParameterName]; }
    5253    }
     54    public ILookupParameter<ICheckedItemList<StringValue>> EnemiesParameter {
     55      get { return (ILookupParameter<ICheckedItemList<StringValue>>)Parameters[EnemiesParameterName]; }
     56    }
    5357    #endregion
    5458
     
    6367      Parameters.Add(new LookupParameter<DirectoryValue>(RobocodePathParamaterName, "Path of the Robocode installation."));
    6468      Parameters.Add(new LookupParameter<IntValue>(NrOfRoundsParameterName, "Nr. of Rounds a Robot has to fight against each opponent."));
     69      Parameters.Add(new LookupParameter<ICheckedItemList<StringValue>>(EnemiesParameterName, "The enemies that should be battled."));
    6570    }
    6671
     
    6873      ISymbolicExpressionTree tree = TankProgramParameter.ActualValue;
    6974      string path = RobocodePathParameter.ActualValue.Value;
    70       QualityParameter.ActualValue = new DoubleValue(Interpreter.EvaluateTankProgram(tree, path, null, false, NrOfRoundsParameter.ActualValue.Value));
     75      QualityParameter.ActualValue = new DoubleValue(Interpreter.EvaluateTankProgram(tree, path, EnemiesParameter.ActualValue, null, false, NrOfRoundsParameter.ActualValue.Value));
    7176
    7277      return base.Apply();
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/RobocodeProblem.cs

    r9926 r9947  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.IO;
    2225using System.Linq;
    2326using HeuristicLab.Common;
     
    4447    private const string RobocodePathParamaterName = "RobocodePath";
    4548    private const string NrOfRoundsParameterName = "NrOfRounds";
     49    private const string EnemiesParameterName = "Enemies";
    4650    #endregion
    4751
     
    6266      get { return (IFixedValueParameter<IntValue>)Parameters[NrOfRoundsParameterName]; }
    6367    }
     68    public IValueParameter<ICheckedItemList<StringValue>> EnemiesParameter {
     69      get { return (IValueParameter<ICheckedItemList<StringValue>>)Parameters[EnemiesParameterName]; }
     70    }
    6471    #endregion
    6572
     
    7784      robocodeDir.Value = @"C:\robocode";
    7885
     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);
     98
    7999      Parameters.Add(new FixedValueParameter<IntValue>(MaxTankProgramDepthParameterName, "Maximal depth of the Robocode tank program.", new IntValue(6)));
    80100      Parameters.Add(new FixedValueParameter<IntValue>(MaxTankProgramLengthParameterName, "Maximal length of the tank program.", new IntValue(1000)));
     
    82102      Parameters.Add(new FixedValueParameter<DirectoryValue>(RobocodePathParamaterName, "Path of the Robocode installation.", robocodeDir));
    83103      Parameters.Add(new FixedValueParameter<IntValue>(NrOfRoundsParameterName, "Nr. of Rounds a Robot has to fight against each opponent.", new IntValue(3)));
     104      Parameters.Add(new ValueParameter<ICheckedItemList<StringValue>>(EnemiesParameterName, "The enemies that should be battled.", robotList));
    84105
    85106      Maximization.Value = true;
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Solution.cs

    r9926 r9947  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Data;
    2425using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3839    public int NrOfRounds { get; set; }
    3940
     41    [Storable]
     42    public ICheckedItemList<StringValue> Enemies { get; set; }
     43
    4044    [StorableConstructor]
    4145    private Solution(bool deserializing) : base(deserializing) { }
     
    4549      Path = (string)original.Path.Clone();
    4650      NrOfRounds = original.NrOfRounds;
     51      Enemies = cloner.Clone(original.Enemies);
    4752    }
    4853
    49     public Solution(ISymbolicExpressionTree tree, string path, int nrOfRounds)
     54    public Solution(ISymbolicExpressionTree tree, string path, int nrOfRounds, ICheckedItemList<StringValue> enemies)
    5055      : base() {
    5156      this.Tree = tree;
    5257      this.Path = path;
    5358      this.NrOfRounds = nrOfRounds;
     59      this.Enemies = enemies;
    5460    }
    5561
Note: See TracChangeset for help on using the changeset viewer.