Changeset 9882
- Timestamp:
- 08/14/13 10:28:28 (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
r9790 r9882 22 22 23 23 // 24 // Please add this file to the /libs forlder in the robocode installation directory, and compile it with the following command:25 // javac -cp .;robocode.jar BattleRunner.java24 // Add this file to the HL bin folder. Compile it with the following command: 25 // javac -cp c:\robocode\;robocode.jar BattleRunner.java 26 26 // 27 27 public class BattleRunner { 28 29 28 static String[] defaultRobots = new String[] { 30 29 "Evaluation.BestSolution*", … … 37 36 "sample.SittingDuck" 38 37 }; 39 public static String player = "Evaluation.output*"; 40 //static int 38 public static String player = "Evaluation.output*"; 41 39 public static int score = 0; 42 40 41 // 42 // This program requires at least 1 argument: the name of the robot. 43 // The second argument is the path to the robocode installation. If not give, c:\robocode is assumed. 44 // The third argument is optional. If it is true, robocode is shown, otherwise it is hidden. 45 // 43 46 public static void main(String[] args) { 44 45 // Disable log messages from Robocode 46 RobocodeEngine.setLogMessagesEnabled(false); 47 48 // Create the RobocodeEngine 49 // RobocodeEngine engine = new RobocodeEngine(); // Run from current working directory 50 RobocodeEngine engine = new RobocodeEngine(new java.io.File("F:/robocode")); // Run from C:/Robocode 51 52 // Add our own battle listener to the RobocodeEngine 53 engine.addBattleListener(new BattleObserver()); 54 55 score = 0; 56 String bots = ""; 47 String roboCodePath = "C:\robocode"; 48 Boolean visible = false; 49 String bots = ""; 50 int numberOfRounds = 3; 57 51 String[] robots = new String[defaultRobots.length]; 58 robots = defaultRobots.clone(); 59 60 52 robots = defaultRobots.clone(); 53 54 if (args.length == 1) 61 55 { 62 robots[0] = player = args[0]; 63 engine.setVisible(true); 56 robots[0] = player = args[0]; 64 57 } 65 58 else if (args.length == 2) 66 59 { 67 60 robots[0] = player = args[0]; 68 engine.setVisible(false); 61 roboCodePath = args[1]; 69 62 } 70 else if (args.length > 2)63 else if (args.length == 3) 71 64 { 72 65 robots[0] = player = args[0]; 73 for(int i = 1; i < args.length && i < robots.length; i++) 74 robots[i] = args[i];66 roboCodePath = args[1]; 67 visible = Boolean.valueOf(args[2]); 75 68 } 76 69 else 77 engine.setVisible(false); 70 { 71 System.exit(-1); 72 } 78 73 74 RobocodeEngine.setLogMessagesEnabled(false); 75 RobocodeEngine engine = new RobocodeEngine(new java.io.File(roboCodePath)); 76 engine.setVisible(visible); 77 engine.addBattleListener(new BattleObserver()); 78 79 // setup the battle specification 79 80 for (String s : robots) 80 81 bots += s + ", "; 81 82 bots = bots.substring(0, bots.length() - 1); 82 83 // Setup the battle specification 84 85 int numberOfRounds = 5; 86 BattlefieldSpecification battlefield = new BattlefieldSpecification(800, 600); // 800x600 83 84 BattlefieldSpecification battlefield = new BattlefieldSpecification(800, 600); 87 85 RobotSpecification[] selectedRobots = engine.getLocalRepository(bots); 88 86 89 System.out.println("Bots: " + bots);90 for(RobotSpecification s : selectedRobots)91 System.out.println("Robot name: " + s.getName());87 for (int i = 1; i < selectedRobots.length; i++) { 88 BattleSpecification battleSpec = new BattleSpecification(numberOfRounds, battlefield, 89 new RobotSpecification[] { selectedRobots[0], selectedRobots[i] }); 92 90 93 for (int i = 1; i < selectedRobots.length; i++) { 94 BattleSpecification battleSpec = new BattleSpecification(numberOfRounds, battlefield, new RobotSpecification[] { selectedRobots[0], selectedRobots[i] }); 95 96 // Run our specified battle and let it run till it is over 97 engine.runBattle(battleSpec, true); // waits till the battle finishes 91 // run our specified battle and wait till the battle finishes 92 engine.runBattle(battleSpec, true); 98 93 } 99 // Cleanup our RobocodeEngine100 94 engine.close(); 101 95 102 //System.out.println(player); 103 //System.out.println(robots[0]); 104 //System.out.println(args[0]); 96 // print out result which is then parsed by HeuristicLab 105 97 System.out.println(score / (robots.length - 1)); 106 107 //for(String s : robots)108 // System.out.println("Robot name: " + s);109 110 // Make sure that the Java VM is shut down properly111 98 System.exit(0); 112 99 } … … 114 101 115 102 // 116 // Our private battle listener for handling the battle event we are interested in.103 // The battle listener for handling the battle event we are interested in. 117 104 // 118 105 class BattleObserver extends BattleAdaptor { 119 120 // Called when the battle is completed successfully with battle results 121 public void onBattleCompleted(BattleCompletedEvent e) { 122 //System.out.println("-- Battle has completed --"); 123 124 // Print out the sorted results with the robot names 125 //System.out.println("Battle results:"); 106 public void onBattleCompleted(BattleCompletedEvent e) { 126 107 for (robocode.BattleResults result : e.getSortedResults()) { 127 //System.out.println(" " + result.getTeamLeaderName() + ": " + result.getScore());128 108 if (result.getTeamLeaderName().equals(BattleRunner.player)) 129 109 BattleRunner.score += result.getScore(); … … 132 112 } 133 113 } 134 135 // Called when the game sends out an information message during the battle136 public void onBattleMessage(BattleMessageEvent e) {137 //System.out.println("Msg> " + e.getMessage());138 }139 140 // Called when the game sends out an error message during the battle141 public void onBattleError(BattleErrorEvent e) {142 //System.out.println("Err> " + e.getError());143 }144 114 } -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Interpreter.cs
r9881 r9882 71 71 ProcessStartInfo evaluateCodeInfo = new ProcessStartInfo(); 72 72 evaluateCodeInfo.FileName = "cmd.exe"; 73 evaluateCodeInfo.Arguments = "/C java -classpath " + formattedPath + "\\libs;" + formattedPath + "\\libs\\robocode.core-1.8.1.0.jar;" + formattedPath + "\\libs\\robocode.jar;" + formattedPath + "\\libs\\picocontainer-2.14.2.jar BattleRunner Evaluation." + outputname + "* false";73 evaluateCodeInfo.Arguments = "/C java -classpath " + formattedPath + "\\libs;" + formattedPath + "\\libs\\robocode.core-1.8.1.0.jar;" + formattedPath + "\\libs\\robocode.jar;" + formattedPath + "\\libs\\picocontainer-2.14.2.jar BattleRunner Evaluation." + outputname + "* " + formattedPath + " false"; 74 74 evaluateCodeInfo.RedirectStandardOutput = true; 75 75 evaluateCodeInfo.RedirectStandardError = true;
Note: See TracChangeset
for help on using the changeset viewer.