Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9882 for branches


Ignore:
Timestamp:
08/14/13 10:28:28 (11 years ago)
Author:
ascheibe
Message:

#2069 cleaned up battlerunner

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  
    2222
    2323//
    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.java
     24// Add this file to the HL bin folder. Compile it with the following command:
     25// javac -cp c:\robocode\;robocode.jar BattleRunner.java
    2626//
    2727public class BattleRunner {
    28 
    2928    static String[] defaultRobots = new String[] {
    3029        "Evaluation.BestSolution*",
     
    3736        "sample.SittingDuck"
    3837    };
    39     public static String player = "Evaluation.output*";
    40     //static int
     38    public static String player = "Evaluation.output*";   
    4139    public static int score = 0;
    4240
     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  //
    4346    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;
    5751        String[] robots = new String[defaultRobots.length];
    58         robots = defaultRobots.clone();
    59 
    60         if (args.length == 1)
     52        robots = defaultRobots.clone();     
     53 
     54    if (args.length == 1)
    6155        {
    62             robots[0] = player = args[0];
    63             engine.setVisible(true);
     56            robots[0] = player = args[0];           
    6457        }
    6558        else if (args.length == 2)
    6659        {
    6760            robots[0] = player = args[0];
    68             engine.setVisible(false);
     61      roboCodePath = args[1];           
    6962        }
    70         else if (args.length > 2)
     63    else if (args.length == 3)
    7164        {
    7265            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]);
    7568        }
    7669        else
    77             engine.setVisible(false);
     70    {
     71            System.exit(-1);
     72    }   
    7873
     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 
    7980        for (String s : robots)
    8081            bots += s + ", ";
    8182        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);
    8785        RobotSpecification[] selectedRobots = engine.getLocalRepository(bots);
    8886
    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] });
    9290
    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);
    9893        }
    99         // Cleanup our RobocodeEngine
    10094        engine.close();
    10195
    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
    10597        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 properly
    11198        System.exit(0);
    11299    }
     
    114101
    115102//
    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.
    117104//
    118105class 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) {   
    126107        for (robocode.BattleResults result : e.getSortedResults()) {
    127             //System.out.println("  " + result.getTeamLeaderName() + ": " + result.getScore());
    128108            if (result.getTeamLeaderName().equals(BattleRunner.player))
    129109                BattleRunner.score += result.getScore();
     
    132112        }
    133113    }
    134 
    135     // Called when the game sends out an information message during the battle
    136     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 battle
    141     public void onBattleError(BattleErrorEvent e) {
    142         //System.out.println("Err> " + e.getError());
    143     }
    144114}
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Interpreter.cs

    r9881 r9882  
    7171      ProcessStartInfo evaluateCodeInfo = new ProcessStartInfo();
    7272      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";
    7474      evaluateCodeInfo.RedirectStandardOutput = true;
    7575      evaluateCodeInfo.RedirectStandardError = true;
Note: See TracChangeset for help on using the changeset viewer.