Changeset 9884
- Timestamp:
- 08/20/13 14:01:58 (11 years ago)
- Location:
- branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/External Evaluator/BattleRunner.java
r9882 r9884 20 20 import robocode.control.*; 21 21 import robocode.control.events.*; 22 import java.util.*; 22 23 23 24 // … … 37 38 }; 38 39 public static String player = "Evaluation.output*"; 39 public static int score = 0;40 public static List<Double> score = new ArrayList<Double>(); 40 41 41 42 // … … 45 46 // 46 47 public static void main(String[] args) { 47 String roboCodePath = "C:\ robocode";48 String roboCodePath = "C:\\robocode"; 48 49 Boolean visible = false; 49 50 String bots = ""; 50 51 int numberOfRounds = 3; 51 52 String[] robots = new String[defaultRobots.length]; 52 robots = defaultRobots.clone(); 53 robots = defaultRobots.clone(); 53 54 54 55 if (args.length == 1) 55 56 { 56 robots[0] = player = args[0]; 57 robots[0] = args[0]; 58 player = args[0]; 57 59 } 58 60 else if (args.length == 2) 59 61 { 60 robots[0] = player = args[0]; 62 robots[0] = args[0]; 63 player = args[0]; 61 64 roboCodePath = args[1]; 62 65 } 63 66 else if (args.length == 3) 64 67 { 65 robots[0] = player = args[0]; 68 robots[0] = args[0]; 69 player = args[0]; 66 70 roboCodePath = args[1]; 67 71 visible = Boolean.valueOf(args[2]); … … 95 99 96 100 // print out result which is then parsed by HeuristicLab 97 System.out.println( score / (robots.length - 1));101 System.out.println(avg(score)); 98 102 System.exit(0); 99 103 } 104 105 private static double avg(List <Double> lst) { 106 double sum = 0; 107 for (double val : lst) { 108 sum += val; 109 } 110 return sum / lst.size(); 111 } 100 112 } 101 113 … … 104 116 // 105 117 class BattleObserver extends BattleAdaptor { 106 public void onBattleCompleted(BattleCompletedEvent e) { 107 for (robocode.BattleResults result : e.getSortedResults()) { 118 public void onBattleCompleted(BattleCompletedEvent e) { 119 double robotScore = -1.0; 120 double opponentScore = - 1.0; 121 122 for (robocode.BattleResults result : e.getSortedResults()) { 108 123 if (result.getTeamLeaderName().equals(BattleRunner.player)) 109 BattleRunner.score += result.getScore();124 robotScore = result.getScore(); 110 125 else 111 BattleRunner.score -= result.getScore(); 112 } 126 opponentScore = result.getScore(); 127 } 128 BattleRunner.score.add(robotScore / (robotScore + opponentScore)); 113 129 } 114 130 } -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Interpreter.cs
r9882 r9884 35 35 try { 36 36 outputname = Guid.NewGuid().ToString(); 37 outputname = outputname.Replace('-', '_'); 38 outputname = "Robocode" + outputname; 37 outputname = outputname.Remove(8, 1); 38 outputname = outputname.Remove(12, 1); 39 outputname = outputname.Remove(16, 1); 40 outputname = outputname.Remove(20, 1); 41 outputname = outputname.Remove(0, 1); 42 outputname = outputname.Insert(0, "R"); 43 39 44 string output = interpretedProgram.Replace("class output", "class " + outputname); 40 45 File.WriteAllText(path + "/robots/Evaluation/" + outputname + ".java", output, System.Text.Encoding.Default); … … 87 92 88 93 string scoreString = ""; 89 double evaluation = - 900;94 double evaluation = -1.0; 90 95 try { 91 96 scoreString = evaluateCode.StandardOutput.ReadToEnd().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Last();
Note: See TracChangeset
for help on using the changeset viewer.