Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9884


Ignore:
Timestamp:
08/20/13 14:01:58 (11 years ago)
Author:
ascheibe
Message:

#2069

  • qualities are now scaled between 0 and 1
  • fixed naming of robots
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  
    2020import robocode.control.*;
    2121import robocode.control.events.*;
     22import java.util.*;
    2223
    2324//
     
    3738    };
    3839    public static String player = "Evaluation.output*";   
    39     public static int score = 0;
     40    public static List<Double> score = new ArrayList<Double>();
    4041
    4142  //
     
    4546  //
    4647    public static void main(String[] args) {
    47     String roboCodePath = "C:\robocode";
     48    String roboCodePath = "C:\\robocode";
    4849    Boolean visible = false;   
    4950    String bots = "";
    5051    int numberOfRounds = 3;
    5152        String[] robots = new String[defaultRobots.length];
    52         robots = defaultRobots.clone();     
     53        robots = defaultRobots.clone();   
    5354 
    5455    if (args.length == 1)
    5556        {
    56             robots[0] = player = args[0];           
     57            robots[0] = args[0];           
     58      player = args[0];           
    5759        }
    5860        else if (args.length == 2)
    5961        {
    60             robots[0] = player = args[0];
     62            robots[0] = args[0];           
     63      player = args[0];       
    6164      roboCodePath = args[1];           
    6265        }
    6366    else if (args.length == 3)
    6467        {
    65             robots[0] = player = args[0];
     68            robots[0] = args[0];           
     69      player = args[0];       
    6670      roboCodePath = args[1];
    6771            visible = Boolean.valueOf(args[2]);
     
    9599
    96100    // print out result which is then parsed by HeuristicLab
    97         System.out.println(score / (robots.length - 1));
     101        System.out.println(avg(score));
    98102        System.exit(0);
    99103    }
     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  }
    100112}
    101113
     
    104116//
    105117class 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()) {     
    108123            if (result.getTeamLeaderName().equals(BattleRunner.player))
    109                 BattleRunner.score += result.getScore();
     124                robotScore = result.getScore();
    110125            else
    111                 BattleRunner.score -= result.getScore();
    112         }
     126                opponentScore = result.getScore();
     127        }   
     128    BattleRunner.score.add(robotScore / (robotScore + opponentScore));   
    113129    }
    114130}
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Interpreter.cs

    r9882 r9884  
    3535      try {
    3636        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
    3944        string output = interpretedProgram.Replace("class output", "class " + outputname);
    4045        File.WriteAllText(path + "/robots/Evaluation/" + outputname + ".java", output, System.Text.Encoding.Default);
     
    8792
    8893      string scoreString = "";
    89       double evaluation = -900;
     94      double evaluation = -1.0;
    9095      try {
    9196        scoreString = evaluateCode.StandardOutput.ReadToEnd().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Last();
Note: See TracChangeset for help on using the changeset viewer.