Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/07/13 08:49:34 (11 years ago)
Author:
jkarder
Message:

#2069:

  • merged IfStat and ElseStat into IfThenElseStat
  • changed the font of the suffixCode text box in the CodeNodeView
Location:
branches/Robocode.TrunkInt
Files:
1 deleted
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode.Views/3.3/CodeNodeView.Designer.cs

    r9890 r10028  
    7272            | System.Windows.Forms.AnchorStyles.Left)
    7373            | System.Windows.Forms.AnchorStyles.Right)));
     74      this.suffixCode.Font = new System.Drawing.Font("Consolas", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    7475      this.suffixCode.Location = new System.Drawing.Point(6, 16);
    7576      this.suffixCode.Multiline = true;
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Grammar.cs

    r10014 r10028  
    5757      var block = new Block();
    5858      var stat = new Stat();
    59       var ifStat = new IfStat();
    60       var elseStat = new ElseStat();
     59      var ifThenElseStat = new IfThenElseStat();
    6160      var whileStat = new WhileStat();
    6261
     
    122121
    123122      #region Symbol Collections
    124       var controlSymbols = new ISymbol[] { ifStat, whileStat };
     123      var controlSymbols = new ISymbol[] { ifThenElseStat, whileStat };
    125124      var actionSymbols = new ISymbol[] {
    126125        ahead, back, fire, turnGunLeft, turnGunRight, turnLeft, turnRadarLeft, turnRadarRight, turnRight
     
    132131
    133132      var events = new GroupSymbol(EventsName, new ISymbol[] { onScannedRobot, onBulletHit, onBulletMissed, onHitByBullet, onHitRobot, onHitWall });
    134       var controlStatements = new GroupSymbol(ControlStatementsName, controlSymbols.Concat(new[] { elseStat }));
     133      var controlStatements = new GroupSymbol(ControlStatementsName, controlSymbols);
    135134      var expressions = new GroupSymbol(ExpressionsName, new ISymbol[] { logicalExpr, numericalExpr });
    136135      var robocodeFunctions = new GroupSymbol(RobocodeFunctionsName, actionSymbols.Concat(functionSymbols));
     
    193192
    194193      // IfStat
    195       AddAllowedChildSymbol(ifStat, logicalExpr, 0);
    196       AddAllowedChildSymbol(ifStat, stat, 1);
    197       AddAllowedChildSymbol(ifStat, emptyEvent, 1);
    198       AddAllowedChildSymbol(ifStat, doNothing, 1);
    199       AddAllowedChildSymbol(ifStat, elseStat, 2);
    200       AddAllowedChildSymbol(ifStat, emptyEvent, 2);
    201       AddAllowedChildSymbol(ifStat, doNothing, 2);
    202 
    203       // ElseStat
    204       AddAllowedChildSymbol(elseStat, stat);
    205       AddAllowedChildSymbol(elseStat, emptyEvent);
    206       AddAllowedChildSymbol(elseStat, doNothing);
     194      AddAllowedChildSymbol(ifThenElseStat, logicalExpr, 0);
     195      AddAllowedChildSymbol(ifThenElseStat, stat, 1);
     196      AddAllowedChildSymbol(ifThenElseStat, emptyEvent, 1);
     197      AddAllowedChildSymbol(ifThenElseStat, doNothing, 1);
     198      AddAllowedChildSymbol(ifThenElseStat, stat, 2);
     199      AddAllowedChildSymbol(ifThenElseStat, emptyEvent, 2);
     200      AddAllowedChildSymbol(ifThenElseStat, doNothing, 2);
    207201
    208202      // WhileStat
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/HeuristicLab.Problems.Robocode-3.3.csproj

    r10011 r10028  
    116116    <Compile Include="Symbols\Void Methods\Back.cs" />
    117117    <Compile Include="Symbols\Block.cs" />
    118     <Compile Include="Symbols\Statements\ElseStat.cs" />
    119     <Compile Include="Symbols\Statements\IfStat.cs" />
     118    <Compile Include="Symbols\Statements\IfThenElseStat.cs" />
    120119    <Compile Include="Symbols\Statements\WhileStat.cs" />
    121120    <Compile Include="Symbols\Logical Expressions\BooleanTreeNode.cs" />
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Statements/IfThenElseStat.cs

    r10014 r10028  
    2828namespace HeuristicLab.Problems.Robocode {
    2929  [StorableClass]
    30   public class IfStat : CodeNode {
     30  public class IfThenElseStat : CodeNode {
    3131    public override int MinimumArity { get { return 2; } }
    3232    public override int MaximumArity { get { return 3; } }
     
    3939
    4040    [StorableConstructor]
    41     protected IfStat(bool deserializing) : base(deserializing) { }
    42     protected IfStat(IfStat original, Cloner cloner) : base(original, cloner) { }
     41    protected IfThenElseStat(bool deserializing) : base(deserializing) { }
     42    protected IfThenElseStat(IfThenElseStat original, Cloner cloner) : base(original, cloner) { }
    4343
    44     public IfStat()
    45       : base("IfStat", "An if statement.") {
    46       Prefix = "if (";
    47       Suffix = ") {";
    48     }
     44    public IfThenElseStat() : base("IfThenElseStat", "An if statement.") { }
    4945
    5046    public override IDeepCloneable Clone(Cloner cloner) {
    51       return new IfStat(this, cloner);
     47      return new IfThenElseStat(this, cloner);
    5248    }
    5349
    5450    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    55       string condition = string.Empty, ifTrue = string.Empty, ifElse = string.Empty;
    56       foreach (var c in children) {
    57         if (c.Symbol is LogicalExpression)
    58           condition = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    59         else if (c.Symbol is Stat)
    60           ifTrue = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    61         else if (c.Symbol is ElseStat || c.Symbol is EmptyEvent || c.Symbol is DoNothing)
    62           ifElse = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    63         else throw new ArgumentException("Unexpected children.", "children");
     51      ISymbolicExpressionTreeNode condition = null, truePart = null, falsePart = null;
     52      var enumerator = children.GetEnumerator();
     53      int childCount = 0;
     54      while (enumerator.MoveNext()) {
     55        childCount++;
     56        switch (childCount) {
     57          case 1: condition = enumerator.Current; break;
     58          case 2: truePart = enumerator.Current; break;
     59          case 3: falsePart = enumerator.Current; break;
     60          default: throw new ArgumentException("Unexpected number of children. Expected a maximum of 3 children.");
     61        }
    6462      }
    65       string result = Prefix + condition + Suffix + Environment.NewLine + ifTrue + Environment.NewLine + "}";
    66       result += string.IsNullOrEmpty(ifElse) ? Environment.NewLine : ifElse;
     63      if (childCount < 2) throw new ArgumentException("Unexpected number of children. Expected at least 2 children.");
     64
     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      };
     70
     71      string result = "if (" + parts[0] + ") {" + parts[1] + "}";
     72      if (!string.IsNullOrEmpty(parts[2]))
     73        result += " else {" + result[2] + "}";
    6774      return result;
    6875    }
Note: See TracChangeset for help on using the changeset viewer.