Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10043


Ignore:
Timestamp:
10/16/13 15:47:25 (11 years ago)
Author:
ascheibe
Message:

#2069

  • use groups for defining allowed child symbols in grammar
  • split functions group into functions and actions in grammar
  • moved run symbol to event group in grammar
  • fixed a bug in the ifthenelse symbol
  • enemy collection now marks one enemy per default
Location:
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/EnemyCollection.cs

    r10011 r10043  
    3333  [StorableClass]
    3434  public class EnemyCollection : CheckedItemList<StringValue> {
     35    private const string sampleRobotToSelect = "sample.Crazy";
     36
    3537    [Storable]
    3638    public string RobocodePath { get; set; }
     
    6971          robotList.SetItemCheckedState(robot, false);
    7072        }
    71       } catch { }
     73      }
     74      catch { }
     75
     76      //select one robot so that if a user tries out the Robocode problem it works with the default settings
     77      if (robotList.Exists(x => x.Value == sampleRobotToSelect)) {
     78        StringValue sampleRobot = robotList.Single(x => x.Value == sampleRobotToSelect);
     79        robotList.SetItemCheckedState(sampleRobot, true);
     80      }
    7281
    7382      return robotList;
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Grammar.cs

    r10028 r10043  
    2020#endregion
    2121
    22 using System.Linq;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
     
    3433    private const string ControlStatementsName = "Control Statements";
    3534    private const string RobocodeFunctionsName = "Robocode Functions";
     35    private const string RobocodeActionsName = "Robocode Actions";
    3636    private const string RelationalOperatorsName = "Relational Operators";
    3737    private const string LogicalOperators = "Logical Operators";
     
    9494      var getY = new GetY();
    9595
    96       //var setAdjustGunForRobotTurn = new SetAdjustGunForRobotTurn();
    97       //var setAdjustRadarForGunTurn = new SetAdjustRadarForGunTurn();
    98       //var setAdjustRadarForRobotTurn = new SetAdjustRadarForRobotTurn();
    99       //var independent = new Independent();
    100 
    10196      var turnLeft = new TurnLeft();
    10297      var turnRight = new TurnRight();
     
    124119      var actionSymbols = new ISymbol[] {
    125120        ahead, back, fire, turnGunLeft, turnGunRight, turnLeft, turnRadarLeft, turnRadarRight, turnRight
    126         //setAdjustGunForRobotTurn, setAdjustRadarForGunTurn, setAdjustRadarForRobotTurn,
    127121      };
    128122      var functionSymbols = new ISymbol[] {
     
    130124      };
    131125
    132       var events = new GroupSymbol(EventsName, new ISymbol[] { onScannedRobot, onBulletHit, onBulletMissed, onHitByBullet, onHitRobot, onHitWall });
     126      var events = new GroupSymbol(EventsName, new ISymbol[] { run, onScannedRobot, onBulletHit, onBulletMissed, onHitByBullet, onHitRobot, onHitWall });
    133127      var controlStatements = new GroupSymbol(ControlStatementsName, controlSymbols);
    134128      var expressions = new GroupSymbol(ExpressionsName, new ISymbol[] { logicalExpr, numericalExpr });
    135       var robocodeFunctions = new GroupSymbol(RobocodeFunctionsName, actionSymbols.Concat(functionSymbols));
     129      var robocodeFunctions = new GroupSymbol(RobocodeFunctionsName, functionSymbols);
     130      var robocodeActions = new GroupSymbol(RobocodeActionsName, actionSymbols);
    136131      var relationalOperators = new GroupSymbol(RelationalOperatorsName, new ISymbol[] { equal, lessThan, lessThanOrEqual, greaterThan, greaterThanOrEqual });
    137132      var logicalOperators = new GroupSymbol(LogicalOperators, new ISymbol[] { conjunction, disjunction, negation });
     
    141136      #region Adding Symbols
    142137      AddSymbol(tank);
    143       AddSymbol(run);
    144138      AddSymbol(stat);
    145139      AddSymbol(block);
     
    151145      AddSymbol(controlStatements);
    152146      AddSymbol(robocodeFunctions);
     147      AddSymbol(robocodeActions);
    153148      AddSymbol(relationalOperators);
    154149      AddSymbol(logicalOperators);
     
    171166      AddAllowedChildSymbol(tank, onHitWall, 6);
    172167
    173       // Run
    174       AddAllowedChildSymbol(run, stat);
    175 
    176       // Event
    177       foreach (var s in events.Symbols)
    178         AddAllowedChildSymbol(s, stat);
     168      // Events
     169      AddAllowedChildSymbol(events, stat);
    179170
    180171      // Block
     
    184175      AddAllowedChildSymbol(stat, stat);
    185176      AddAllowedChildSymbol(stat, block);
    186       foreach (var s in controlSymbols)
    187         AddAllowedChildSymbol(stat, s);
    188       foreach (var s in robocodeFunctions.Symbols)
    189         AddAllowedChildSymbol(stat, s);
     177      AddAllowedChildSymbol(stat, controlStatements);
     178      AddAllowedChildSymbol(stat, robocodeFunctions);
     179      AddAllowedChildSymbol(stat, robocodeActions);
    190180      AddAllowedChildSymbol(stat, emptyEvent);
    191181      AddAllowedChildSymbol(stat, doNothing);
     
    207197
    208198      // Numerical Expressions
    209       foreach (var s in functionSymbols.Concat(new[] { number }))
    210         AddAllowedChildSymbol(numericalExpr, s);
    211       foreach (var s in numericalOperators.Symbols) {
    212         AddAllowedChildSymbol(numericalExpr, s);
    213         foreach (var ne in functionSymbols.Concat(new[] { number }))
    214           AddAllowedChildSymbol(s, ne);
    215         foreach (var no in numericalOperators.Symbols) {
    216           AddAllowedChildSymbol(s, no);
    217         }
    218       }
     199      AddAllowedChildSymbol(numericalExpr, number);
     200      AddAllowedChildSymbol(numericalExpr, robocodeFunctions);
     201      AddAllowedChildSymbol(numericalExpr, numericalOperators);
     202      AddAllowedChildSymbol(numericalOperators, number);
     203      AddAllowedChildSymbol(numericalOperators, robocodeFunctions);
     204      AddAllowedChildSymbol(numericalOperators, numericalOperators);
    219205
    220206      // Logical Expressions
    221207      AddAllowedChildSymbol(logicalExpr, logicalVal);
    222       foreach (var s in logicalOperators.Symbols) {
    223         AddAllowedChildSymbol(logicalExpr, s);
    224         AddAllowedChildSymbol(s, logicalVal);
    225         foreach (var lo in logicalOperators.Symbols)
    226           AddAllowedChildSymbol(s, lo);
    227         foreach (var ro in relationalOperators.Symbols)
    228           AddAllowedChildSymbol(s, ro);
    229       }
    230       foreach (var s in relationalOperators.Symbols)
    231         AddAllowedChildSymbol(s, numericalExpr);
    232 
    233       // Functions
    234       foreach (var f in robocodeFunctions.Symbols) {
    235         if (f is Fire) AddAllowedChildSymbol(f, shotPower);
    236         else AddAllowedChildSymbol(f, numericalExpr);
     208      AddAllowedChildSymbol(logicalExpr, logicalOperators);
     209      AddAllowedChildSymbol(logicalOperators, logicalVal);
     210      AddAllowedChildSymbol(logicalOperators, logicalOperators);
     211      AddAllowedChildSymbol(logicalOperators, relationalOperators);
     212      AddAllowedChildSymbol(relationalOperators, numericalExpr);
     213
     214      // Functions and Actions
     215      AddAllowedChildSymbol(robocodeFunctions, numericalExpr);
     216      foreach (var a in robocodeActions.Symbols) {
     217        if (a is Fire) AddAllowedChildSymbol(a, shotPower);
     218        else AddAllowedChildSymbol(a, numericalExpr);
    237219      }
    238220      #endregion
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/RobocodeProblem.cs

    r10014 r10043  
    8787      Parameters.Add(new ValueParameter<Grammar>(TankGrammarParameterName, "Grammar for the tank program.", new Grammar()));
    8888      Parameters.Add(new FixedValueParameter<DirectoryValue>(RobocodePathParamaterName, "Path of the Robocode installation.", robocodeDir));
    89       Parameters.Add(new FixedValueParameter<IntValue>(NrOfRoundsParameterName, "Nr. of Rounds a Robot has to fight against each opponent.", new IntValue(3)));
     89      Parameters.Add(new FixedValueParameter<IntValue>(NrOfRoundsParameterName, "Nr. of rounds a robot has to fight against each opponent.", new IntValue(3)));
    9090      Parameters.Add(new ValueParameter<EnemyCollection>(EnemiesParameterName, "The enemies that should be battled.", robotList));
    9191
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Solution.cs

    r9971 r10043  
    2727namespace HeuristicLab.Problems.Robocode {
    2828  [StorableClass]
    29   [Item("Solution", "A Robocode program.")]
     29  [Item("Solution", "Robocode program and configuration.")]
    3030  public sealed class Solution : Item {
    3131    [Storable]
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Statements/IfThenElseStat.cs

    r10028 r10043  
    5050    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5151      ISymbolicExpressionTreeNode condition = null, truePart = null, falsePart = null;
     52      string[] parts = new string[3];
    5253      var enumerator = children.GetEnumerator();
    5354      int childCount = 0;
     
    6364      if (childCount < 2) throw new ArgumentException("Unexpected number of children. Expected at least 2 children.");
    6465
    65       var parts = new[] {
    66         ((CodeNode)condition.Symbol).Interpret(condition, condition.Subtrees),
    67         ((CodeNode)truePart.Symbol).Interpret(truePart, truePart.Subtrees),
    68         ((CodeNode)falsePart.Symbol).Interpret(falsePart, falsePart.Subtrees)
    69       };
     66      parts[0] = ((CodeNode)condition.Symbol).Interpret(condition, condition.Subtrees);
     67      parts[1] = ((CodeNode)truePart.Symbol).Interpret(truePart, truePart.Subtrees);
     68      if (childCount == 3) parts[2] = ((CodeNode)falsePart.Symbol).Interpret(falsePart, falsePart.Subtrees);
    7069
    7170      string result = "if (" + parts[0] + ") {" + parts[1] + "}";
Note: See TracChangeset for help on using the changeset viewer.