Changeset 9947
- Timestamp:
- 09/11/13 15:21:01 (11 years ago)
- Location:
- branches/Robocode.TrunkInt
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode.Views/3.3/SolutionCodeView.cs
r9926 r9947 50 50 51 51 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); 53 53 } 54 54 } -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/BestSolutionAnalyzer.cs
r9926 r9947 40 40 private const string RobocodePathParamaterName = "RobocodePath"; 41 41 private const string NrOfRoundsParameterName = "NrOfRounds"; 42 private const string EnemiesParameterName = "Enemies"; 42 43 43 44 public bool EnabledByDefault { … … 64 65 get { return (ILookupParameter<IntValue>)Parameters[NrOfRoundsParameterName]; } 65 66 } 67 public ILookupParameter<ICheckedItemList<StringValue>> EnemiesParameter { 68 get { return (ILookupParameter<ICheckedItemList<StringValue>>)Parameters[EnemiesParameterName]; } 69 } 66 70 #endregion 67 71 … … 78 82 Parameters.Add(new LookupParameter<DirectoryValue>(RobocodePathParamaterName, "Path of the Robocode installation.")); 79 83 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.")); 80 85 } 81 86 … … 97 102 98 103 // 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); 100 105 // store the new solution in the best solution parameter 101 106 BestSolutionParameter.ActualValue = bestSolution; -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/External Evaluator/BattleRunner.java
r9926 r9947 27 27 // 28 28 public 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 };39 29 public static String player = "Evaluation.output*"; 40 30 public static List<Double> score = new ArrayList<Double>(); … … 45 35 // The fourth argument is the number of rounds. 46 36 public static void main(String[] args) { 37 if (args.length < 5) 38 System.exit(-1); 39 47 40 String roboCodePath = "C:\\robocode"; 48 41 Boolean visible = false; 49 42 String bots = ""; 50 43 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]; 84 52 85 53 RobocodeEngine.setLogMessagesEnabled(false); -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Interpreter.cs
r9926 r9947 26 26 using System.Linq; 27 27 using System.Reflection; 28 using HeuristicLab.Core; 29 using HeuristicLab.Data; 28 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 31 30 32 namespace HeuristicLab.Problems.Robocode { 31 33 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) { 33 35 if (robotName == null) 34 36 robotName = GenerateRobotName(); … … 81 83 evaluateCodeInfo.Arguments += " false " + nrOfRounds; 82 84 } 85 86 foreach (var enemy in enemies) 87 evaluateCodeInfo.Arguments += enemy.Value + "* "; 83 88 84 89 evaluateCodeInfo.RedirectStandardOutput = true; -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/RobocodeEvaluator.cs
r9926 r9947 37 37 private const string RobocodePathParamaterName = "RobocodePath"; 38 38 private const string NrOfRoundsParameterName = "NrOfRounds"; 39 private const string EnemiesParameterName = "Enemies"; 39 40 40 41 #region Parameters … … 51 52 get { return (ILookupParameter<IntValue>)Parameters[NrOfRoundsParameterName]; } 52 53 } 54 public ILookupParameter<ICheckedItemList<StringValue>> EnemiesParameter { 55 get { return (ILookupParameter<ICheckedItemList<StringValue>>)Parameters[EnemiesParameterName]; } 56 } 53 57 #endregion 54 58 … … 63 67 Parameters.Add(new LookupParameter<DirectoryValue>(RobocodePathParamaterName, "Path of the Robocode installation.")); 64 68 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.")); 65 70 } 66 71 … … 68 73 ISymbolicExpressionTree tree = TankProgramParameter.ActualValue; 69 74 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)); 71 76 72 77 return base.Apply(); -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/RobocodeProblem.cs
r9926 r9947 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.IO; 22 25 using System.Linq; 23 26 using HeuristicLab.Common; … … 44 47 private const string RobocodePathParamaterName = "RobocodePath"; 45 48 private const string NrOfRoundsParameterName = "NrOfRounds"; 49 private const string EnemiesParameterName = "Enemies"; 46 50 #endregion 47 51 … … 62 66 get { return (IFixedValueParameter<IntValue>)Parameters[NrOfRoundsParameterName]; } 63 67 } 68 public IValueParameter<ICheckedItemList<StringValue>> EnemiesParameter { 69 get { return (IValueParameter<ICheckedItemList<StringValue>>)Parameters[EnemiesParameterName]; } 70 } 64 71 #endregion 65 72 … … 77 84 robocodeDir.Value = @"C:\robocode"; 78 85 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 79 99 Parameters.Add(new FixedValueParameter<IntValue>(MaxTankProgramDepthParameterName, "Maximal depth of the Robocode tank program.", new IntValue(6))); 80 100 Parameters.Add(new FixedValueParameter<IntValue>(MaxTankProgramLengthParameterName, "Maximal length of the tank program.", new IntValue(1000))); … … 82 102 Parameters.Add(new FixedValueParameter<DirectoryValue>(RobocodePathParamaterName, "Path of the Robocode installation.", robocodeDir)); 83 103 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)); 84 105 85 106 Maximization.Value = true; -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Solution.cs
r9926 r9947 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 24 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 38 39 public int NrOfRounds { get; set; } 39 40 41 [Storable] 42 public ICheckedItemList<StringValue> Enemies { get; set; } 43 40 44 [StorableConstructor] 41 45 private Solution(bool deserializing) : base(deserializing) { } … … 45 49 Path = (string)original.Path.Clone(); 46 50 NrOfRounds = original.NrOfRounds; 51 Enemies = cloner.Clone(original.Enemies); 47 52 } 48 53 49 public Solution(ISymbolicExpressionTree tree, string path, int nrOfRounds )54 public Solution(ISymbolicExpressionTree tree, string path, int nrOfRounds, ICheckedItemList<StringValue> enemies) 50 55 : base() { 51 56 this.Tree = tree; 52 57 this.Path = path; 53 58 this.NrOfRounds = nrOfRounds; 59 this.Enemies = enemies; 54 60 } 55 61
Note: See TracChangeset
for help on using the changeset viewer.