Changeset 10011 for branches


Ignore:
Timestamp:
10/01/13 12:08:25 (8 years ago)
Author:
jkarder
Message:

#2069:

  • refactored grammar and symbols
  • fixed cloning and storable ctors
  • fixed plugin dependencies
Location:
branches/Robocode.TrunkInt
Files:
3 added
6 deleted
53 edited
3 copied
3 moved

Legend:

Unmodified
Added
Removed
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode.Views/3.3/Plugin.cs.frame

    r9971 r10011  
    3434    [PluginDependency("HeuristicLab.Core", "3.3")]
    3535    [PluginDependency("HeuristicLab.Core.Views", "3.3")]
    36     [PluginDependency("HeuristicLab.Optimization", "3.3")]
    37     [PluginDependency("HeuristicLab.Operators", "3.3")]
    3836    [PluginDependency("HeuristicLab.Common", "3.3")]
    3937    [PluginDependency("HeuristicLab.Common.Resources", "3.3")]
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/EnemyCollection.cs

    r9971 r10011  
    3737
    3838    [StorableConstructor]
    39     private EnemyCollection(bool deserializing) : base(deserializing) { }
    40     private EnemyCollection(EnemyCollection original, Cloner cloner)
     39    protected EnemyCollection(bool deserializing) : base(deserializing) { }
     40    protected EnemyCollection(EnemyCollection original, Cloner cloner)
    4141      : base(original, cloner) {
    4242      RobocodePath = original.RobocodePath;
     
    6969          robotList.SetItemCheckedState(robot, false);
    7070        }
    71       }
    72       catch { }
     71      } catch { }
    7372
    7473      return robotList;
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Grammar.cs

    r9879 r10011  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
     
    3130  public class Grammar : SymbolicExpressionGrammar {
    3231    [StorableConstructor]
    33     private Grammar(bool deserializing) : base(deserializing) { }
    34     private Grammar(Grammar original, Cloner cloner)
    35       : base(original, cloner) {
    36     }
     32    protected Grammar(bool deserializing) : base(deserializing) { }
     33    protected Grammar(Grammar original, Cloner cloner) : base(original, cloner) { }
    3734
    3835    public Grammar()
     
    5047      #region Symbols
    5148      var block = new Block();
    52 
    53       var ifStmt = new IfStatement();
    54       var elseStmt = new ElseStatement();
    55       var whileLoop = new WhileLoop();
    56 
    57       var numExpr = new NumericalExpression();
     49      var stat = new Stat();
     50      var ifStat = new IfStat();
     51      var elseStat = new ElseStat();
     52      var whileStat = new WhileStat();
     53
     54      var logicalExpr = new LogicalExpression();
     55      var numericalExpr = new NumericalExpression();
     56
     57      var equal = new Equal();
     58      var lessThan = new LessThan();
     59      var lessThanOrEqual = new LessThanOrEqual();
     60      var greaterThan = new GreaterThan();
     61      var greaterThanOrEqual = new GreaterThanOrEqual();
     62
     63      var conjunction = new Conjunction();
     64      var disjunction = new Disjunction();
     65      var negation = new Negation();
     66
     67      var addition = new Addition();
     68      var subtraction = new Subtraction();
     69      var multiplication = new Multiplication();
     70      var division = new Division();
     71      var modulus = new Modulus();
     72
    5873      var number = new Number();
    59       var numOp = new NumericalOperation();
    60       var add = new Addition();
    61       var sub = new Subtraction();
    62       var mult = new Multiplication();
    63       var div = new Division();
    64       var mod = new Modulus();
    65 
    66       var logicExpr = new LogicalExpression();
    67       var logicComp = new LogicalComparison();
    68       var numComp = new NumericalComparison();
    69       var logicVal = new LogicalValue();
    70       var not = new Negation();
    71       var and = new Conjunction();
    72       var or = new Disjunction();
    73       var eq = new Equal();
    74       var lt = new LessThan();
    75       var gt = new GreaterThan();
    76       var lteq = new LessThanOrEqual();
    77       var gteq = new GreaterThanOrEqual();
     74      var logicalVal = new LogicalValue();
    7875
    7976      var ahead = new Ahead();
    8077      var back = new Back();
    81       var doNothing = new DoNothing();
    8278      var fire = new Fire();
    8379      var shotPower = new ShotPower();
     
    108104      var onHitWall = new OnHitWall();
    109105      var onScannedRobot = new OnScannedRobot();
    110       var emptyEvent = new EmptyEvent();
    111106
    112107      var run = new Run();
    113108      var tank = new Tank();
    114       var program = new Program();
     109
     110      var doNothing = new DoNothing();
     111      var emptyEvent = new EmptyEvent();
    115112      #endregion
    116113
    117114      #region Symbol Collections
    118       var numericalExpressions = new List<ISymbol>()
    119             {
    120                 number, numOp, getEnergy, getGunHeading, getHeading, getRadarHeading, getX, getY
    121             };
    122 
    123       var numericalOperators = new List<ISymbol>()
    124             {
    125                 add, sub, mult, div, mod
    126             };
    127 
    128       var logicalExpressions = new List<ISymbol>()
    129             {
    130                 logicVal, logicComp, numComp, not
    131             };
    132 
    133       var logicalComparators = new List<ISymbol>()
    134             {
    135                 and, or
    136             };
    137 
    138       var numericalComparators = new List<ISymbol>()
    139             {
    140                 lt, gt, lteq, gteq, eq
    141             };
    142 
    143       var terminalSymbols = new List<ISymbol>()
    144             {
    145                 doNothing, //getEnergy, getGunHeading, getHeading, getRadarHeading, getX, getY
    146             };
    147 
    148       var functionSymbols = new List<ISymbol>()
    149             {
    150                 ahead, back, fire,
    151                 //setAdjustGunForRobotTurn, setAdjustRadarForGunTurn, setAdjustRadarForRobotTurn,
    152                 turnGunLeft, turnGunRight, turnLeft, turnRadarLeft, turnRadarRight, turnRight
    153             };
    154 
    155       var constantSymbols = new List<ISymbol>()
    156             {
    157                 shotPower
    158             };
    159 
    160       var eventSymbols = new List<ISymbol>()
    161             {
    162                 run, onBulletHit, onBulletMissed, onHitByBullet,
    163                 onHitRobot, onHitWall, onScannedRobot, block, emptyEvent
    164             };
     115      var eventSymbols = new ISymbol[] { onScannedRobot, onBulletHit, onBulletMissed, onHitByBullet, onHitRobot, onHitWall };
     116      var controlSymbols = new ISymbol[] { ifStat, whileStat };
     117      var functionSymbols = new ISymbol[] {
     118        ahead, back, fire, turnGunLeft, turnGunRight, turnLeft, turnRadarLeft, turnRadarRight, turnRight
     119        //setAdjustGunForRobotTurn, setAdjustRadarForGunTurn, setAdjustRadarForRobotTurn,
     120      };
     121      var relationalOperators = new ISymbol[] { equal, lessThan, lessThanOrEqual, greaterThan, greaterThanOrEqual };
     122      var logicalOperators = new ISymbol[] { conjunction, disjunction, negation };
     123      var numericalExpressions = new ISymbol[] { number, getEnergy, getGunHeading, getHeading, getRadarHeading, getX, getY };
     124      var numericalOperators = new ISymbol[] { addition, subtraction, multiplication, division, modulus };
    165125      #endregion
    166126
    167127      #region Adding Symbols
    168       // add all symbols to the grammar
    169 
    170       AddSymbol(ifStmt);
    171       AddSymbol(elseStmt);
    172       AddSymbol(whileLoop);
    173 
    174       AddSymbol(numExpr);
     128      foreach (var s in eventSymbols)
     129        AddSymbol(s);
     130      foreach (var s in controlSymbols)
     131        AddSymbol(s);
     132      foreach (var s in functionSymbols)
     133        AddSymbol(s);
     134      foreach (var s in relationalOperators)
     135        AddSymbol(s);
     136      foreach (var s in logicalOperators)
     137        AddSymbol(s);
    175138      foreach (var s in numericalExpressions)
    176139        AddSymbol(s);
     
    178141        AddSymbol(s);
    179142
    180       AddSymbol(logicExpr);
    181       foreach (var s in logicalExpressions)
    182         AddSymbol(s);
    183       foreach (var s in logicalComparators)
    184         AddSymbol(s);
    185       foreach (var s in numericalComparators)
    186         AddSymbol(s);
    187 
    188       foreach (var s in terminalSymbols)
    189         AddSymbol(s);
     143      AddSymbol(block);
     144      AddSymbol(stat);
     145      AddSymbol(elseStat);
     146      AddSymbol(shotPower);
     147      AddSymbol(logicalVal);
     148      AddSymbol(logicalExpr);
     149      AddSymbol(numericalExpr);
     150      AddSymbol(run);
     151      AddSymbol(tank);
     152      AddSymbol(emptyEvent);
     153      AddSymbol(doNothing);
     154      #endregion
     155
     156      #region Grammar Definition
     157      // StartSymbol
     158      AddAllowedChildSymbol(StartSymbol, tank);
     159
     160      // Tank
     161      AddAllowedChildSymbol(tank, run, 0);
     162      AddAllowedChildSymbol(tank, onScannedRobot, 1);
     163      AddAllowedChildSymbol(tank, onBulletHit, 2);
     164      AddAllowedChildSymbol(tank, onBulletMissed, 3);
     165      AddAllowedChildSymbol(tank, onHitByBullet, 4);
     166      AddAllowedChildSymbol(tank, onHitRobot, 5);
     167      AddAllowedChildSymbol(tank, onHitWall, 6);
     168
     169      // Run
     170      AddAllowedChildSymbol(run, stat);
     171
     172      // Event
     173      foreach (var s in eventSymbols)
     174        AddAllowedChildSymbol(s, stat);
     175
     176      // Block
     177      AddAllowedChildSymbol(block, stat);
     178
     179      // Stat
     180      AddAllowedChildSymbol(stat, stat);
     181      AddAllowedChildSymbol(stat, block);
     182      foreach (var s in controlSymbols)
     183        AddAllowedChildSymbol(stat, s);
    190184      foreach (var s in functionSymbols)
    191         AddSymbol(s);
    192       foreach (var s in constantSymbols)
    193         AddSymbol(s);
    194       foreach (var s in eventSymbols)
    195         AddSymbol(s);
    196       AddSymbol(tank);
    197       #endregion
    198 
    199       #region Defining Grammar
    200       // define grammar rules
    201 
    202       // Branches
    203       AddAllowedChildSymbol(ifStmt, logicExpr, 0);
    204       AddAllowedChildSymbol(ifStmt, block, 1);
    205       AddAllowedChildSymbol(ifStmt, elseStmt, 2);
    206       AddAllowedChildSymbol(ifStmt, doNothing, 2);
    207       AddAllowedChildSymbol(elseStmt, block);
    208       AddAllowedChildSymbol(whileLoop, logicExpr, 0);
    209       AddAllowedChildSymbol(whileLoop, block, 1);
     185        AddAllowedChildSymbol(stat, s);
     186      AddAllowedChildSymbol(stat, emptyEvent);
     187      AddAllowedChildSymbol(stat, doNothing);
     188
     189      // IfStat
     190      AddAllowedChildSymbol(ifStat, logicalExpr, 0);
     191      AddAllowedChildSymbol(ifStat, stat, 1);
     192      AddAllowedChildSymbol(ifStat, emptyEvent, 1);
     193      AddAllowedChildSymbol(ifStat, doNothing, 1);
     194      AddAllowedChildSymbol(ifStat, elseStat, 2);
     195      AddAllowedChildSymbol(ifStat, emptyEvent, 2);
     196      AddAllowedChildSymbol(ifStat, doNothing, 2);
     197
     198      // ElseStat
     199      AddAllowedChildSymbol(elseStat, stat);
     200      AddAllowedChildSymbol(elseStat, emptyEvent);
     201      AddAllowedChildSymbol(elseStat, doNothing);
     202
     203      // WhileStat
     204      AddAllowedChildSymbol(whileStat, logicalExpr, 0);
     205      AddAllowedChildSymbol(whileStat, stat, 1);
     206      AddAllowedChildSymbol(whileStat, emptyEvent, 1);
     207      AddAllowedChildSymbol(whileStat, doNothing, 1);
    210208
    211209      // Numerical Expressions
    212       foreach (var s in numericalExpressions) {
    213         AddAllowedChildSymbol(numExpr, s);
    214         AddAllowedChildSymbol(numOp, s, 1);
    215         AddAllowedChildSymbol(numOp, s, 2);
     210      foreach (var s in numericalExpressions)
     211        AddAllowedChildSymbol(numericalExpr, s);
     212      foreach (var s in numericalOperators) {
     213        AddAllowedChildSymbol(numericalExpr, s);
     214        foreach (var ne in numericalExpressions)
     215          AddAllowedChildSymbol(s, ne);
     216        foreach (var no in numericalOperators) {
     217          AddAllowedChildSymbol(s, no);
     218        }
    216219      }
    217       foreach (var s in numericalOperators)
    218         AddAllowedChildSymbol(numOp, s, 0);
    219220
    220221      // Logical Expressions
    221       foreach (var s in logicalExpressions) {
    222         AddAllowedChildSymbol(logicExpr, s);
    223         AddAllowedChildSymbol(not, s);
    224         AddAllowedChildSymbol(logicComp, s, 1);
    225         AddAllowedChildSymbol(logicComp, s, 2);
     222      AddAllowedChildSymbol(logicalExpr, logicalVal);
     223      foreach (var s in logicalOperators) {
     224        AddAllowedChildSymbol(logicalExpr, s);
     225        AddAllowedChildSymbol(s, logicalVal);
     226        foreach (var lo in logicalOperators)
     227          AddAllowedChildSymbol(s, lo);
     228        foreach (var ro in relationalOperators)
     229          AddAllowedChildSymbol(s, ro);
    226230      }
    227       foreach (var s in logicalComparators)
    228         AddAllowedChildSymbol(logicComp, s, 0);
    229       foreach (var s in numericalExpressions) {
    230         AddAllowedChildSymbol(numComp, s, 1);
    231         AddAllowedChildSymbol(numComp, s, 2);
    232       }
    233       foreach (var s in numericalComparators)
    234         AddAllowedChildSymbol(numComp, s, 0);
    235 
    236 
    237       // All Void Statements can appear in run or in an event handler or inside a block
    238       foreach (var e in eventSymbols) {
    239         AddAllowedChildSymbol(e, ifStmt);
    240         AddAllowedChildSymbol(e, whileLoop);
    241         AddAllowedChildSymbol(e, doNothing);
    242         foreach (var f in functionSymbols)
    243           AddAllowedChildSymbol(e, f);
    244       }
    245 
    246       // Add the appropriate parameters as children of their respective functions
     231      foreach (var s in relationalOperators)
     232        AddAllowedChildSymbol(s, numericalExpr);
     233
     234      // Functions
    247235      foreach (var f in functionSymbols) {
    248236        if (f is Fire)
    249237          AddAllowedChildSymbol(f, shotPower);
    250238        else
    251           AddAllowedChildSymbol(f, numExpr);
    252 
     239          AddAllowedChildSymbol(f, numericalExpr);
    253240      }
    254 
    255       // Add all Event Methods to Tank. Run and OnScannedEvent are not optional,
    256       // so EmptyEvent cannot take their places
    257 
    258       AddAllowedChildSymbol(tank, run, 0);
    259       AddAllowedChildSymbol(tank, onScannedRobot, 1);
    260       AddAllowedChildSymbol(tank, onBulletMissed, 2);
    261       AddAllowedChildSymbol(tank, onHitByBullet, 3);
    262       AddAllowedChildSymbol(tank, onHitRobot, 4);
    263       AddAllowedChildSymbol(tank, onHitWall, 5);
    264       AddAllowedChildSymbol(tank, onBulletHit, 6);
    265       for (int i = 2; i < tank.MaximumArity; i++)
    266         AddAllowedChildSymbol(tank, emptyEvent, i);
    267 
    268       AddAllowedChildSymbol(StartSymbol, tank, 0);
    269241      #endregion
    270242    }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/HeuristicLab.Problems.Robocode-3.3.csproj

    r9983 r10011  
    109109    <Compile Include="Solution.cs" />
    110110    <Compile Include="Symbols\Event Methods\Events\EmptyEvent.cs" />
     111    <Compile Include="Symbols\Logical Expressions\Logical Comparators\ILogicalComparator.cs" />
     112    <Compile Include="Symbols\Numerical Expressions\Numerical Operators\INumericalOperator.cs" />
    111113    <Compile Include="Symbols\Numerical Methods\INumericalMethod.cs" />
     114    <Compile Include="Symbols\Stat.cs" />
    112115    <Compile Include="Symbols\Void Methods\Ahead.cs" />
    113116    <Compile Include="Symbols\Void Methods\Back.cs" />
    114117    <Compile Include="Symbols\Block.cs" />
    115     <Compile Include="Symbols\Branches\ElseStatement.cs" />
    116     <Compile Include="Symbols\Branches\IfStatement.cs" />
    117     <Compile Include="Symbols\Branches\WhileLoop.cs" />
     118    <Compile Include="Symbols\Statements\ElseStat.cs" />
     119    <Compile Include="Symbols\Statements\IfStat.cs" />
     120    <Compile Include="Symbols\Statements\WhileStat.cs" />
    118121    <Compile Include="Symbols\Logical Expressions\BooleanTreeNode.cs" />
    119     <Compile Include="Symbols\Logical Expressions\Logical Comparators\Conjunction.cs" />
    120     <Compile Include="Symbols\Logical Expressions\Logical Comparators\Disjunction.cs" />
     122    <Compile Include="Symbols\Logical Expressions\Conjunction.cs" />
     123    <Compile Include="Symbols\Logical Expressions\Disjunction.cs" />
    121124    <Compile Include="Symbols\Logical Expressions\Logical Comparators\Equal.cs" />
    122125    <Compile Include="Symbols\Logical Expressions\Logical Comparators\GreaterThan.cs" />
     
    124127    <Compile Include="Symbols\Logical Expressions\Logical Comparators\LessThan.cs" />
    125128    <Compile Include="Symbols\Logical Expressions\Logical Comparators\LessThanOrEqual.cs" />
    126     <Compile Include="Symbols\Logical Expressions\LogicalComparison.cs" />
    127129    <Compile Include="Symbols\Logical Expressions\LogicalExpression.cs" />
    128130    <Compile Include="Symbols\Logical Expressions\LogicalValue.cs" />
    129131    <Compile Include="Symbols\Logical Expressions\Negation.cs" />
    130     <Compile Include="Symbols\Logical Expressions\NumericalComparison.cs" />
    131132    <Compile Include="Symbols\Numerical Expressions\NumberTreeNode.cs" />
    132133    <Compile Include="Symbols\Numerical Expressions\Number.cs" />
     
    137138    <Compile Include="Symbols\Numerical Expressions\Numerical Operators\Subtraction.cs" />
    138139    <Compile Include="Symbols\Numerical Expressions\NumericalExpression.cs" />
    139     <Compile Include="Symbols\Numerical Expressions\NumericalOperation.cs" />
    140140    <Compile Include="Symbols\CodeNode.cs" />
    141141    <Compile Include="Symbols\Tank.cs" />
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/RobocodeProblem.cs

    r9985 r10011  
    8383      robotList.RobocodePath = robocodeDir.Value;
    8484
    85       Parameters.Add(new FixedValueParameter<IntValue>(MaxTankProgramDepthParameterName, "Maximal depth of the Robocode tank program.", new IntValue(6)));
     85      Parameters.Add(new FixedValueParameter<IntValue>(MaxTankProgramDepthParameterName, "Maximal depth of the Robocode tank program.", new IntValue(10)));
    8686      Parameters.Add(new FixedValueParameter<IntValue>(MaxTankProgramLengthParameterName, "Maximal length of the tank program.", new IntValue(1000)));
    8787      Parameters.Add(new ValueParameter<Grammar>(TankGrammarParameterName, "Grammar for the tank program.", new Grammar()));
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Block.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2930  public class Block : CodeNode {
    3031    public override int MinimumArity { get { return 1; } }
    31     public override int MaximumArity { get { return 10; } }
     32    public override int MaximumArity { get { return byte.MaxValue; } }
    3233
    3334    [Storable]
     
    3839
    3940    [StorableConstructor]
    40     private Block(bool deserializing) : base(deserializing) { }
    41     private Block(Block original, Cloner cloner)
    42       : base(original, cloner) {
    43     }
     41    protected Block(bool deserializing) : base(deserializing) { }
     42    protected Block(Block original, Cloner cloner) : base(original, cloner) { }
    4443
    4544    public Block()
    4645      : base("Block", "A group of statements.") {
    47       this.Prefix = "{\r\n\t";
    48       this.Suffix = "\r\nexecute();\r\n}\r\n";
     46      Prefix = "{";
     47      Suffix = "}";
    4948    }
    5049
     
    5453
    5554    public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       string result = "";
    57       foreach (ISymbolicExpressionTreeNode c in children)
    58         result += "\r\n" + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    59       return this.Prefix + "\r\n" + result + "\r\n" + this.Suffix;
     55      string result = children.Aggregate(string.Empty, (current, c) => current + (Environment.NewLine + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     56      return Prefix + result + Environment.NewLine + Suffix;
    6057    }
    6158  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/CodeNode.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3535    protected CodeNode(CodeNode original, Cloner cloner)
    3636      : base(original, cloner) {
    37       this.Prefix = original.Prefix;
    38       this.Suffix = original.Suffix;
     37      Prefix = original.Prefix;
     38      Suffix = original.Suffix;
    3939    }
    4040    protected CodeNode(string name, string description)
    4141      : base(name, description) {
     42      Prefix = string.Empty;
     43      Suffix = string.Empty;
    4244    }
    4345
    44     public override IDeepCloneable Clone(Cloner cloner) {
    45       throw new System.NotImplementedException();
    46     }
    47 
    48     public override int MaximumArity {
    49       get { throw new System.NotImplementedException(); }
    50     }
    51 
    52     public override int MinimumArity {
    53       get { throw new System.NotImplementedException(); }
    54     }
    55 
    56     public abstract string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children);
     46    public abstract string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children);
    5747  }
    5848}
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Event Methods/Events/EmptyEvent.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3738
    3839    [StorableConstructor]
    39     private EmptyEvent(bool deserializing) : base(deserializing) { }
    40     private EmptyEvent(EmptyEvent original, Cloner cloner)
    41       : base(original, cloner) {
    42     }
     40    protected EmptyEvent(bool deserializing) : base(deserializing) { }
     41    protected EmptyEvent(EmptyEvent original, Cloner cloner) : base(original, cloner) { }
    4342
    44     public EmptyEvent()
    45       : base("EmptyEvent", "This is a placeholder for an empty event.") {
    46       this.Prefix = "";
    47       this.Suffix = "";
    48     }
     43    public EmptyEvent() : base("EmptyEvent", "This is a placeholder for an empty event.") { }
    4944
    5045    public override IDeepCloneable Clone(Cloner cloner) {
     
    5247    }
    5348
    54     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    55       return "";
     49    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     50      return ";";
    5651    }
    5752  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Event Methods/Events/OnBulletHit.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3740
    3841    [StorableConstructor]
    39     private OnBulletHit(bool deserializing) : base(deserializing) { }
    40     private OnBulletHit(OnBulletHit original, Cloner cloner)
    41       : base(original, cloner) {
    42 
    43     }
     42    protected OnBulletHit(bool deserializing) : base(deserializing) { }
     43    protected OnBulletHit(OnBulletHit original, Cloner cloner) : base(original, cloner) { }
    4444
    4545    public OnBulletHit()
    4646      : base("OnBulletHit", "This method is called when one of your bullets hits another robot.") {
    47       this.Prefix = "\r\npublic void onBulletHit(BulletHitEvent e) {\r\n";
    48       this.Suffix = "\r\nexecute();\r\n}\r\n";
     47      Prefix = "public void onBulletHit(BulletHitEvent e) {";
     48      Suffix =
     49@"execute();
     50}";
    4951    }
    5052
     
    5355    }
    5456
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       string result = "";
    57       foreach (ISymbolicExpressionTreeNode c in children)
    58         result += "\r\n" + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    59       return this.Prefix + "\r\n" + result + "\r\n" + this.Suffix;
     57    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     58      string result = children.Aggregate(string.Empty, (current, c) => current + (Environment.NewLine + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     59      return Prefix + result + Environment.NewLine + Suffix;
    6060    }
    6161  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Event Methods/Events/OnBulletMissed.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3740
    3841    [StorableConstructor]
    39     private OnBulletMissed(bool deserializing) : base(deserializing) { }
    40     private OnBulletMissed(OnBulletMissed original, Cloner cloner)
    41       : base(original, cloner) {
    42 
    43     }
     42    protected OnBulletMissed(bool deserializing) : base(deserializing) { }
     43    protected OnBulletMissed(OnBulletMissed original, Cloner cloner) : base(original, cloner) { }
    4444
    4545    public OnBulletMissed()
    4646      : base("OnBulletMissed", "This method is called when one of your bullets misses, i.e. hits a wall.") {
    47       this.Prefix = "\r\npublic void onBulletMissed(BulletMissedEvent e) {\r\n";
    48       this.Suffix = "\r\nexecute();\r\n}\r\n";
     47      Prefix = "public void onBulletMissed(BulletMissedEvent e) {";
     48      Suffix =
     49@"execute();
     50}";
    4951    }
    5052
     
    5355    }
    5456
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       string result = "";
    57       foreach (ISymbolicExpressionTreeNode c in children)
    58         result += "\r\n" + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    59       return this.Prefix + "\r\n" + result + "\r\n" + this.Suffix;
     57    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     58      string result = children.Aggregate(string.Empty, (current, c) => current + (Environment.NewLine + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     59      return Prefix + result + Environment.NewLine + Suffix;
    6060    }
    6161  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Event Methods/Events/OnHitByBullet.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3740
    3841    [StorableConstructor]
    39     private OnHitByBullet(bool deserializing) : base(deserializing) { }
    40     private OnHitByBullet(OnHitByBullet original, Cloner cloner)
    41       : base(original, cloner) {
    42 
    43     }
     42    protected OnHitByBullet(bool deserializing) : base(deserializing) { }
     43    protected OnHitByBullet(OnHitByBullet original, Cloner cloner) : base(original, cloner) { }
    4444
    4545    public OnHitByBullet()
    4646      : base("OnHitByBullet", "This method is called when your robot is hit by a bullet.") {
    47       this.Prefix = "\r\npublic void onHitByBullet(HitByBulletEvent e) {\r\n";
    48       this.Suffix = "\r\nexecute();\r\n}\r\n";
     47      Prefix = "public void onHitByBullet(HitByBulletEvent e) {";
     48      Suffix =
     49@"execute();
     50}";
    4951    }
    5052
     
    5355    }
    5456
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       string result = "";
    57       foreach (ISymbolicExpressionTreeNode c in children)
    58         result += "\r\n" + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    59       return this.Prefix + "\r\n" + result + "\r\n" + this.Suffix;
     57    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     58      string result = children.Aggregate(string.Empty, (current, c) => current + (Environment.NewLine + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     59      return Prefix + result + Environment.NewLine + Suffix;
    6060    }
    6161  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Event Methods/Events/OnHitRobot.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3740
    3841    [StorableConstructor]
    39     private OnHitRobot(bool deserializing) : base(deserializing) { }
    40     private OnHitRobot(OnHitRobot original, Cloner cloner)
    41       : base(original, cloner) {
    42     }
     42    protected OnHitRobot(bool deserializing) : base(deserializing) { }
     43    protected OnHitRobot(OnHitRobot original, Cloner cloner) : base(original, cloner) { }
    4344
    4445    public OnHitRobot()
    4546      : base("OnHitRobot", "This method is called when your robot collides with another robot.") {
    46       this.Prefix = "\r\npublic void onHitRobot(HitRobotEvent e) {\r\n";
    47       this.Suffix = "\r\nexecute();\r\n}\r\n";
     47      Prefix = "public void onHitRobot(HitRobotEvent e) {";
     48      Suffix =
     49@"execute();
     50}";
    4851    }
    4952
     
    5255    }
    5356
    54     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    55       string result = "";
    56       foreach (ISymbolicExpressionTreeNode c in children)
    57         result += "\r\n" + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    58       return this.Prefix + "\r\n" + result + "\r\n" + this.Suffix;
     57    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     58      string result = children.Aggregate(string.Empty, (current, c) => current + (Environment.NewLine + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     59      return Prefix + result + Environment.NewLine + Suffix;
    5960    }
    6061  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Event Methods/Events/OnHitWall.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3740
    3841    [StorableConstructor]
    39     private OnHitWall(bool deserializing) : base(deserializing) { }
    40     private OnHitWall(OnHitWall original, Cloner cloner)
    41       : base(original, cloner) {
    42 
    43     }
     42    protected OnHitWall(bool deserializing) : base(deserializing) { }
     43    protected OnHitWall(OnHitWall original, Cloner cloner) : base(original, cloner) { }
    4444
    4545    public OnHitWall()
    4646      : base("OnHitWall", "This method is called when your robot collides with a wall.") {
    47       this.Prefix = "\r\npublic void onHitWall(HitWallEvent e) {\r\n";
    48       this.Suffix = "\r\nexecute();\r\n}\r\n";
     47      Prefix = "public void onHitWall(HitWallEvent e) {";
     48      Suffix =
     49@"execute();
     50}";
    4951    }
    5052
     
    5355    }
    5456
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       string result = "";
    57       foreach (ISymbolicExpressionTreeNode c in children)
    58         result += "\r\n" + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    59       return this.Prefix + "\r\n" + result + "\r\n" + this.Suffix;
     57    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     58      string result = children.Aggregate(string.Empty, (current, c) => current + (Environment.NewLine + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     59      return Prefix + result + Environment.NewLine + Suffix;
    6060    }
    6161  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Event Methods/Events/OnScannedRobot.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3740
    3841    [StorableConstructor]
    39     private OnScannedRobot(bool deserializing) : base(deserializing) { }
    40     private OnScannedRobot(OnScannedRobot original, Cloner cloner)
    41       : base(original, cloner) {
    42 
    43     }
     42    protected OnScannedRobot(bool deserializing) : base(deserializing) { }
     43    protected OnScannedRobot(OnScannedRobot original, Cloner cloner) : base(original, cloner) { }
    4444
    4545    public OnScannedRobot()
    4646      : base("OnScannedRobot", "This method is called when your robot sees another robot, i.e. when the robot's radar scan \"hits\" another robot.") {
    47       this.Prefix = "\r\npublic void onScannedRobot(ScannedRobotEvent e) {" +
    48                     "\r\ndouble absoluteBearing = getHeading() + e.getBearing();" +
    49                     "\r\ndouble bearingFromGun = normalRelativeAngleDegrees(absoluteBearing - getGunHeading());" +
    50                     "\r\nsetTurnGunRight(bearingFromGun);\r\n";
    51       this.Suffix = "\r\nexecute();\r\n}\r\n";
     47      Prefix =
     48@"public void onScannedRobot(ScannedRobotEvent e) {
     49double absoluteBearing = getHeading() + e.getBearing();
     50double bearingFromGun = normalRelativeAngleDegrees(absoluteBearing - getGunHeading());
     51setTurnGunRight(bearingFromGun);";
     52      Suffix =
     53@"execute();
     54}";
    5255    }
    5356
     
    5659    }
    5760
    58     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    59       string result = "";
    60       foreach (ISymbolicExpressionTreeNode c in children)
    61         result += "\r\n" + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    62       return this.Prefix + "\r\n" + result + "\r\n" + this.Suffix;
     61    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     62      string result = children.Aggregate(string.Empty, (current, c) => current + (Environment.NewLine + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     63      return Prefix + result + Environment.NewLine + Suffix;
    6364    }
    6465  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Event Methods/Run.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2730  [StorableClass]
    2831  public class Run : CodeNode {
    29     public override int MinimumArity { get { return 2; } }
     32    public override int MinimumArity { get { return 1; } }
    3033    public override int MaximumArity { get { return 10; } }
    3134
     
    3740
    3841    [StorableConstructor]
    39     private Run(bool deserializing) : base(deserializing) { }
    40     private Run(Run original, Cloner cloner)
    41       : base(original, cloner) {
    42     }
     42    protected Run(bool deserializing) : base(deserializing) { }
     43    protected Run(Run original, Cloner cloner) : base(original, cloner) { }
    4344
    4445    public Run()
    4546      : base("Run", "The main method in every robot.") {
    46       this.Prefix = "\r\npublic void run() {\r\n\tsetAdjustGunForRobotTurn(true);\r\n\tturnRadarRightRadians(Double.POSITIVE_INFINITY);";
    47       this.Suffix = "\r\nexecute();\r\n}\r\n";
     47      Prefix =
     48@"public void run() {
     49setAdjustGunForRobotTurn(true);
     50turnRadarRightRadians(Double.POSITIVE_INFINITY);";
     51      Suffix =
     52@"execute();
     53}";
    4854    }
    4955
     
    5258    }
    5359
    54     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    55       string result = "";
    56       foreach (ISymbolicExpressionTreeNode c in children)
    57         result += "\r\n" + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    58       return this.Prefix + "\r\n" + result + "\r\n" + this.Suffix;
     60    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     61      string result = children.Aggregate(string.Empty, (current, c) => current + (Environment.NewLine + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     62      return Prefix + result + Environment.NewLine + Suffix;
    5963    }
    6064  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/BooleanTreeNode.cs

    r9790 r10011  
    3636
    3737    [StorableConstructor]
    38     private BooleanTreeNode(bool deserializing) : base(deserializing) { }
    39     private BooleanTreeNode(BooleanTreeNode original, Cloner cloner)
     38    protected BooleanTreeNode(bool deserializing) : base(deserializing) { }
     39    protected BooleanTreeNode(BooleanTreeNode original, Cloner cloner)
    4040      : base(original, cloner) {
    41       this.value = original.value;
     41      value = original.value;
    4242    }
    4343
    44     public BooleanTreeNode()
    45       : base(new LogicalValue()) {
    46     }
     44    public BooleanTreeNode() : base(new LogicalValue()) { }
    4745
    4846    public override IDeepCloneable Clone(Cloner cloner) {
     
    5553
    5654    public override void ResetLocalParameters(IRandom random) {
    57       value = (bool)(random.Next(0, 1) == 1);
     55      value = random.Next(0, 2) == 1;
    5856    }
    5957  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Conjunction.cs

    r9999 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2730  [StorableClass]
    2831  public class Conjunction : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     32    public override int MinimumArity { get { return 2; } }
     33    public override int MaximumArity { get { return byte.MaxValue; } }
    3134
    3235    [Storable]
     
    3740
    3841    [StorableConstructor]
    39     private Conjunction(bool deserializing) : base(deserializing) { }
    40     private Conjunction(Conjunction original, Cloner cloner)
    41       : base(original, cloner) {
    42     }
     42    protected Conjunction(bool deserializing) : base(deserializing) { }
     43    protected Conjunction(Conjunction original, Cloner cloner) : base(original, cloner) { }
    4344
    4445    public Conjunction()
    4546      : base("Conjunction", "Conjunction comparator.") {
    46       this.Prefix = "&&";
    47       this.Suffix = "";
     47      Prefix = "(";
     48      Suffix = ")";
    4849    }
    4950
     
    5253    }
    5354
    54     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    55       return this.Prefix + " " + this.Suffix;
     55    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     56      if (children.Count() < 2)
     57        throw new ArgumentException("Expected at leaset 2 children.", "children");
     58
     59      string result = string.Join(" && ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     60      return Prefix + result + Suffix;
    5661    }
    5762  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Disjunction.cs

    r9999 r10011  
    2020#endregion
    2121
     22using System.Collections.Generic;
     23using System.Linq;
    2224using HeuristicLab.Common;
    2325using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2729  [StorableClass]
    2830  public class Disjunction : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     31    public override int MinimumArity { get { return 2; } }
     32    public override int MaximumArity { get { return byte.MaxValue; } }
    3133
    3234    [Storable]
     
    3739
    3840    [StorableConstructor]
    39     private Disjunction(bool deserializing) : base(deserializing) { }
    40     private Disjunction(Disjunction original, Cloner cloner)
    41       : base(original, cloner) {
    42     }
     41    protected Disjunction(bool deserializing) : base(deserializing) { }
     42    protected Disjunction(Disjunction original, Cloner cloner) : base(original, cloner) { }
    4343
    4444    public Disjunction()
    4545      : base("Disjunction", "Disjunction comparator.") {
    46       this.Prefix = "||";
    47       this.Suffix = "";
     46      Prefix = "(";
     47      Suffix = ")";
    4848    }
    4949
     
    5252    }
    5353
    54     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    55       return this.Prefix + " " + this.Suffix;
     54    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     55      string result = string.Join(" || ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     56      return Prefix + result + Suffix;
    5657    }
    5758  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/Equal.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2627namespace HeuristicLab.Problems.Robocode {
    2728  [StorableClass]
    28   public class Equal : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     29  public class Equal : CodeNode, ILogicalComparator {
     30    public override int MinimumArity { get { return 2; } }
     31    public override int MaximumArity { get { return 2; } }
    3132
    3233    [Storable]
     
    3738
    3839    [StorableConstructor]
    39     private Equal(bool deserializing) : base(deserializing) { }
    40     private Equal(Equal original, Cloner cloner)
    41       : base(original, cloner) {
    42     }
     40    protected Equal(bool deserializing) : base(deserializing) { }
     41    protected Equal(Equal original, Cloner cloner) : base(original, cloner) { }
    4342
    44     public Equal()
    45       : base("Equal", "Equal comparator.") {
    46       this.Prefix = "==";
    47       this.Suffix = "";
    48     }
     43    public Equal() : base("Equal", "Equal comparator.") { }
    4944
    5045    public override IDeepCloneable Clone(Cloner cloner) {
     
    5247    }
    5348
    54     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    55       return this.Prefix + " " + this.Suffix;
     49    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     50      ISymbolicExpressionTreeNode lhs = null, rhs = null;
     51      var enumerator = children.GetEnumerator();
     52      int childCount = 0;
     53      while (enumerator.MoveNext()) {
     54        childCount++;
     55        switch (childCount) {
     56          case 1: lhs = enumerator.Current; break;
     57          case 2: rhs = enumerator.Current; break;
     58          default: throw new System.Exception("Unexpected number of children. Expected 2 children.");
     59        }
     60      }
     61      if (childCount < 2) throw new System.Exception("Unexpected number of children. Expected 2 children.");
     62
     63      var result = new[] {
     64        ((CodeNode)lhs.Symbol).Interpret(lhs, lhs.Subtrees),
     65        ((CodeNode)rhs.Symbol).Interpret(rhs, rhs.Subtrees)
     66      };
     67
     68      return result[0] + " == " + result[1];
    5669    }
    5770  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/GreaterThan.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2627namespace HeuristicLab.Problems.Robocode {
    2728  [StorableClass]
    28   public class GreaterThan : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     29  public class GreaterThan : CodeNode, ILogicalComparator {
     30    public override int MinimumArity { get { return 2; } }
     31    public override int MaximumArity { get { return 2; } }
    3132
    3233    [Storable]
     
    3738
    3839    [StorableConstructor]
    39     private GreaterThan(bool deserializing) : base(deserializing) { }
    40     private GreaterThan(GreaterThan original, Cloner cloner)
    41       : base(original, cloner) {
    42     }
     40    protected GreaterThan(bool deserializing) : base(deserializing) { }
     41    protected GreaterThan(GreaterThan original, Cloner cloner) : base(original, cloner) { }
    4342
    44     public GreaterThan()
    45       : base("GreaterThan", "GreaterThan comparator.") {
    46       this.Prefix = ">";
    47       this.Suffix = "";
    48     }
     43    public GreaterThan() : base("GreaterThan", "GreaterThan comparator.") { }
    4944
    5045    public override IDeepCloneable Clone(Cloner cloner) {
     
    5247    }
    5348
    54     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    55       return this.Prefix + " " + this.Suffix;
     49    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     50      ISymbolicExpressionTreeNode lhs = null, rhs = null;
     51      var enumerator = children.GetEnumerator();
     52      int childCount = 0;
     53      while (enumerator.MoveNext()) {
     54        childCount++;
     55        switch (childCount) {
     56          case 1: lhs = enumerator.Current; break;
     57          case 2: rhs = enumerator.Current; break;
     58          default: throw new System.Exception("Unexpected number of children. Expected 2 children.");
     59        }
     60      }
     61      if (childCount < 2) throw new System.Exception("Unexpected number of children. Expected 2 children.");
     62
     63      var result = new[] {
     64        ((CodeNode)lhs.Symbol).Interpret(lhs, lhs.Subtrees),
     65        ((CodeNode)rhs.Symbol).Interpret(rhs, rhs.Subtrees)
     66      };
     67
     68      return result[0] + " > " + result[1];
    5669    }
    5770  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/GreaterThanOrEqual.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2627namespace HeuristicLab.Problems.Robocode {
    2728  [StorableClass]
    28   public class GreaterThanOrEqual : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     29  public class GreaterThanOrEqual : CodeNode, ILogicalComparator {
     30    public override int MinimumArity { get { return 2; } }
     31    public override int MaximumArity { get { return 2; } }
    3132
    3233    [Storable]
     
    3738
    3839    [StorableConstructor]
    39     private GreaterThanOrEqual(bool deserializing) : base(deserializing) { }
    40     private GreaterThanOrEqual(GreaterThanOrEqual original, Cloner cloner)
    41       : base(original, cloner) {
    42     }
     40    protected GreaterThanOrEqual(bool deserializing) : base(deserializing) { }
     41    protected GreaterThanOrEqual(GreaterThanOrEqual original, Cloner cloner) : base(original, cloner) { }
    4342
    44     public GreaterThanOrEqual()
    45       : base("GreaterThanOrEqual", "GreaterThanOrEqual comparator.") {
    46       this.Prefix = ">=";
    47       this.Suffix = "";
    48     }
     43    public GreaterThanOrEqual() : base("GreaterThanOrEqual", "GreaterThanOrEqual comparator.") { }
    4944
    5045    public override IDeepCloneable Clone(Cloner cloner) {
     
    5247    }
    5348
    54     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    55       return this.Prefix + " " + this.Suffix;
     49    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     50      ISymbolicExpressionTreeNode lhs = null, rhs = null;
     51      var enumerator = children.GetEnumerator();
     52      int childCount = 0;
     53      while (enumerator.MoveNext()) {
     54        childCount++;
     55        switch (childCount) {
     56          case 1: lhs = enumerator.Current; break;
     57          case 2: rhs = enumerator.Current; break;
     58          default: throw new System.Exception("Unexpected number of children. Expected 2 children.");
     59        }
     60      }
     61      if (childCount < 2) throw new System.Exception("Unexpected number of children. Expected 2 children.");
     62
     63      var result = new[] {
     64        ((CodeNode)lhs.Symbol).Interpret(lhs, lhs.Subtrees),
     65        ((CodeNode)rhs.Symbol).Interpret(rhs, rhs.Subtrees)
     66      };
     67
     68      return result[0] + " >= " + result[1];
    5669    }
    5770  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/LessThan.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2627namespace HeuristicLab.Problems.Robocode {
    2728  [StorableClass]
    28   public class LessThan : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     29  public class LessThan : CodeNode, ILogicalComparator {
     30    public override int MinimumArity { get { return 2; } }
     31    public override int MaximumArity { get { return 2; } }
    3132
    3233    [Storable]
     
    3738
    3839    [StorableConstructor]
    39     private LessThan(bool deserializing) : base(deserializing) { }
    40     private LessThan(LessThan original, Cloner cloner)
    41       : base(original, cloner) {
     40    protected LessThan(bool deserializing) : base(deserializing) { }
     41    protected LessThan(LessThan original, Cloner cloner) : base(original, cloner) { }
    4242
    43     }
    44 
    45     public LessThan()
    46       : base("LessThan", "LessThan comparator.") {
    47       this.Prefix = "<";
    48       this.Suffix = "";
    49     }
     43    public LessThan() : base("LessThan", "LessThan comparator.") { }
    5044
    5145    public override IDeepCloneable Clone(Cloner cloner) {
     
    5347    }
    5448
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       return this.Prefix + " " + this.Suffix;
     49    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     50      ISymbolicExpressionTreeNode lhs = null, rhs = null;
     51      var enumerator = children.GetEnumerator();
     52      int childCount = 0;
     53      while (enumerator.MoveNext()) {
     54        childCount++;
     55        switch (childCount) {
     56          case 1: lhs = enumerator.Current; break;
     57          case 2: rhs = enumerator.Current; break;
     58          default: throw new System.Exception("Unexpected number of children. Expected 2 children.");
     59        }
     60      }
     61      if (childCount < 2) throw new System.Exception("Unexpected number of children. Expected 2 children.");
     62
     63      var result = new[] {
     64        ((CodeNode)lhs.Symbol).Interpret(lhs, lhs.Subtrees),
     65        ((CodeNode)rhs.Symbol).Interpret(rhs, rhs.Subtrees)
     66      };
     67
     68      return result[0] + " < " + result[1];
    5769    }
    5870  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/LessThanOrEqual.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2627namespace HeuristicLab.Problems.Robocode {
    2728  [StorableClass]
    28   public class LessThanOrEqual : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     29  public class LessThanOrEqual : CodeNode, ILogicalComparator {
     30    public override int MinimumArity { get { return 2; } }
     31    public override int MaximumArity { get { return 2; } }
    3132
    3233    [Storable]
     
    3738
    3839    [StorableConstructor]
    39     private LessThanOrEqual(bool deserializing) : base(deserializing) { }
    40     private LessThanOrEqual(LessThanOrEqual original, Cloner cloner)
    41       : base(original, cloner) {
    42     }
     40    protected LessThanOrEqual(bool deserializing) : base(deserializing) { }
     41    protected LessThanOrEqual(LessThanOrEqual original, Cloner cloner) : base(original, cloner) { }
    4342
    44     public LessThanOrEqual()
    45       : base("LessThanOrEqual", "LessThanOrEqual comparator.") {
    46       this.Prefix = "<=";
    47       this.Suffix = "";
    48     }
     43    public LessThanOrEqual() : base("LessThanOrEqual", "LessThanOrEqual comparator.") { }
    4944
    5045    public override IDeepCloneable Clone(Cloner cloner) {
     
    5247    }
    5348
    54     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    55       return this.Prefix + " " + this.Suffix;
     49    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     50      ISymbolicExpressionTreeNode lhs = null, rhs = null;
     51      var enumerator = children.GetEnumerator();
     52      int childCount = 0;
     53      while (enumerator.MoveNext()) {
     54        childCount++;
     55        switch (childCount) {
     56          case 1: lhs = enumerator.Current; break;
     57          case 2: rhs = enumerator.Current; break;
     58          default: throw new System.Exception("Unexpected number of children. Expected 2 children.");
     59        }
     60      }
     61      if (childCount < 2) throw new System.Exception("Unexpected number of children. Expected 2 children.");
     62
     63      var result = new[] {
     64        ((CodeNode)lhs.Symbol).Interpret(lhs, lhs.Subtrees),
     65        ((CodeNode)rhs.Symbol).Interpret(rhs, rhs.Subtrees)
     66      };
     67
     68      return result[0] + " <= " + result[1];
    5669    }
    5770  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/LogicalExpression.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3738
    3839    [StorableConstructor]
    39     private LogicalExpression(bool deserializing) : base(deserializing) { }
    40     private LogicalExpression(LogicalExpression original, Cloner cloner)
    41       : base(original, cloner) {
    42     }
     40    protected LogicalExpression(bool deserializing) : base(deserializing) { }
     41    protected LogicalExpression(LogicalExpression original, Cloner cloner) : base(original, cloner) { }
    4342
    44     public LogicalExpression()
    45       : base("LogicalExpression", "A LogicalExpression.") {
    46       this.Prefix = "";
    47       this.Suffix = "";
    48     }
     43    public LogicalExpression() : base("LogicalExpression", "A logical expression.") { }
    4944
    5045    public override IDeepCloneable Clone(Cloner cloner) {
     
    5247    }
    5348
    54     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     49    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5550      var enumerator = children.GetEnumerator();
     51      if (!enumerator.MoveNext()) throw new System.Exception("LogicalExpression was not given a child.");
    5652
    57       if (!enumerator.MoveNext()) throw new System.Exception("LogicalExpression was not given a child.");
    5853      var symbol = enumerator.Current.Symbol;
    59 
    60       if (!(symbol is LogicalValue || symbol is LogicalComparison ||
    61           symbol is NumericalComparison || symbol is Negation))
    62         throw new System.Exception("LogicalExpression was given a child of type " + symbol.GetType().ToString() +
    63             ". The expected child must be of type " + typeof(LogicalValue).ToString() + " or " +
    64             typeof(LogicalComparison).ToString() + " or " + typeof(NumericalComparison).ToString() + " or " +
    65             typeof(Negation).ToString() + ".");
     54      if (!(symbol is LogicalValue || symbol is Conjunction || symbol is Disjunction || symbol is Negation))
     55        throw new System.Exception("LogicalExpression was given a child of type " + symbol.GetType() +
     56            ". The expected child must be of type " + typeof(LogicalValue)
     57                                           + " or " + typeof(Conjunction)
     58                                           + " or " + typeof(Disjunction)
     59                                           + " or " + typeof(Negation) + ".");
    6660
    6761      string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    6862      if (enumerator.MoveNext()) throw new System.Exception("LogicalExpression was given more than one child.");
    6963
    70       return this.Prefix + result + this.Suffix;
     64      return result;
    7165    }
    7266  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/LogicalValue.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3738
    3839    [StorableConstructor]
    39     private LogicalValue(bool deserializing) : base(deserializing) { }
    40     private LogicalValue(LogicalValue original, Cloner cloner)
    41       : base(original, cloner) {
    42     }
     40    protected LogicalValue(bool deserializing) : base(deserializing) { }
     41    protected LogicalValue(LogicalValue original, Cloner cloner) : base(original, cloner) { }
    4342
    44     public LogicalValue()
    45       : base("LogicalValue", "A LogicalValue.") {
    46       this.Prefix = "";
    47       this.Suffix = "";
    48     }
     43    public LogicalValue() : base("LogicalValue", "A logical value.") { }
    4944
    5045    public override ISymbolicExpressionTreeNode CreateTreeNode() {
    51 
    5246      return new BooleanTreeNode();
    5347    }
     
    5751    }
    5852
    59     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    60       return " " + ((BooleanTreeNode)node).Value.ToString().ToLower() + " ";
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     54      return ((BooleanTreeNode)node).Value.ToString().ToLower();
    6155    }
    6256  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Negation.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3738
    3839    [StorableConstructor]
    39     private Negation(bool deserializing) : base(deserializing) { }
    40     private Negation(Negation original, Cloner cloner)
    41       : base(original, cloner) {
    42     }
     40    protected Negation(bool deserializing) : base(deserializing) { }
     41    protected Negation(Negation original, Cloner cloner) : base(original, cloner) { }
    4342
    4443    public Negation()
    45       : base("Negation", "A Negation.") {
    46       this.Prefix = "!(";
    47       this.Suffix = ")";
     44      : base("Negation", "A negation.") {
     45      Prefix = "!(";
     46      Suffix = ")";
    4847    }
    4948
     
    5251    }
    5352
    54     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5554      var enumerator = children.GetEnumerator();
    5655      if (!enumerator.MoveNext()) throw new System.Exception("Negation was not given a child.");
    5756
    5857      var symbol = enumerator.Current.Symbol;
    59       if (!(symbol is LogicalValue || symbol is LogicalComparison ||
    60           symbol is NumericalComparison || symbol is Negation))
    61         throw new System.Exception("Negation was given a child of type " + symbol.GetType().ToString() +
    62             ". The expected child must be of type " + typeof(LogicalValue).ToString() + " or " +
    63             typeof(LogicalComparison).ToString() + " or " + typeof(NumericalComparison).ToString() + " or " +
    64             typeof(Negation).ToString() + ".");
     58      if (!(symbol is LogicalValue || symbol is Conjunction || symbol is Disjunction || symbol is Negation || symbol is ILogicalComparator))
     59        throw new System.Exception("Negation was given a child of type " + symbol.GetType() +
     60            ". The expected child must be of type " + typeof(LogicalValue)
     61                                           + " or " + typeof(Conjunction)
     62                                           + " or " + typeof(Disjunction)
     63                                           + " or " + typeof(Negation)
     64                                           + " or " + typeof(ILogicalComparator) + ".");
    6565
    6666      string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    6767      if (enumerator.MoveNext()) throw new System.Exception("LogicalExpression was given more than one child.");
    6868
    69       return this.Prefix + result + this.Suffix;
     69      return Prefix + result + Suffix;
    7070    }
    7171  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Number.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3738
    3839    [StorableConstructor]
    39     private Number(bool deserializing) : base(deserializing) { }
    40     private Number(Number original, Cloner cloner)
    41       : base(original, cloner) {
    42     }
     40    protected Number(bool deserializing) : base(deserializing) { }
     41    protected Number(Number original, Cloner cloner) : base(original, cloner) { }
    4342
    44     public Number()
    45       : base("Number", "A Number.") {
    46       this.Prefix = "";
    47       this.Suffix = "";
    48     }
     43    public Number() : base("Number", "A number.") { }
    4944
    5045    public override ISymbolicExpressionTreeNode CreateTreeNode() {
    51 
    5246      return new NumberTreeNode();
    5347    }
     
    5751    }
    5852
    59     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    60       return " " + ((NumberTreeNode)node).Value + " ";
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     54      return ((NumberTreeNode)node).Value.ToString();
    6155    }
    6256  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/NumberTreeNode.cs

    r9790 r10011  
    3636
    3737    [StorableConstructor]
    38     private NumberTreeNode(bool deserializing) : base(deserializing) { }
    39     private NumberTreeNode(NumberTreeNode original, Cloner cloner)
     38    protected NumberTreeNode(bool deserializing) : base(deserializing) { }
     39    protected NumberTreeNode(NumberTreeNode original, Cloner cloner)
    4040      : base(original, cloner) {
    4141      this.value = original.value;
    4242    }
    4343
    44     public NumberTreeNode()
    45       : base(new Number()) {
    46     }
     44    public NumberTreeNode() : base(new Number()) { }
    4745
    4846    public override IDeepCloneable Clone(Cloner cloner) {
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Addition.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2629namespace HeuristicLab.Problems.Robocode {
    2730  [StorableClass]
    28   public class Addition : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     31  public class Addition : CodeNode, INumericalOperator {
     32    public override int MinimumArity { get { return 2; } }
     33    public override int MaximumArity { get { return byte.MaxValue; } }
    3134
    3235    [Storable]
     
    3740
    3841    [StorableConstructor]
    39     private Addition(bool deserializing) : base(deserializing) { }
    40     private Addition(Addition original, Cloner cloner)
    41       : base(original, cloner) {
    42 
    43     }
     42    protected Addition(bool deserializing) : base(deserializing) { }
     43    protected Addition(Addition original, Cloner cloner) : base(original, cloner) { }
    4444
    4545    public Addition()
    4646      : base("Addition", "Addition operator.") {
    47       this.Prefix = "+";
    48       this.Suffix = "";
     47      Prefix = "(";
     48      Suffix = ")";
    4949    }
    5050
     
    5353    }
    5454
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       return this.Prefix + this.Suffix;
     55    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     56      if (children.Count() < 2)
     57        throw new ArgumentException("Expected at leaset 2 children.", "children");
     58
     59      string result = string.Join(" + ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     60      return Prefix + result + Suffix;
    5761    }
    5862  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Division.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2629namespace HeuristicLab.Problems.Robocode {
    2730  [StorableClass]
    28   public class Division : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     31  public class Division : CodeNode, INumericalOperator {
     32    public override int MinimumArity { get { return 2; } }
     33    public override int MaximumArity { get { return byte.MaxValue; } }
    3134
    3235    [Storable]
     
    3740
    3841    [StorableConstructor]
    39     private Division(bool deserializing) : base(deserializing) { }
    40     private Division(Division original, Cloner cloner)
    41       : base(original, cloner) {
    42 
    43     }
     42    protected Division(bool deserializing) : base(deserializing) { }
     43    protected Division(Division original, Cloner cloner) : base(original, cloner) { }
    4444
    4545    public Division()
    4646      : base("Division", "Division operator.") {
    47       this.Prefix = "/";
    48       this.Suffix = "";
     47      Prefix = "(";
     48      Suffix = ")";
    4949    }
    5050
     
    5353    }
    5454
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       return this.Prefix + this.Suffix;
     55    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     56      if (children.Count() < 2)
     57        throw new ArgumentException("Expected at leaset 2 children.", "children");
     58
     59      string result = string.Join(" / ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     60      return Prefix + result + Suffix;
    5761    }
    5862  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Modulus.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2629namespace HeuristicLab.Problems.Robocode {
    2730  [StorableClass]
    28   public class Modulus : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     31  public class Modulus : CodeNode, INumericalOperator {
     32    public override int MinimumArity { get { return 2; } }
     33    public override int MaximumArity { get { return byte.MaxValue; } }
    3134
    3235    [Storable]
     
    3740
    3841    [StorableConstructor]
    39     private Modulus(bool deserializing) : base(deserializing) { }
    40     private Modulus(Modulus original, Cloner cloner)
    41       : base(original, cloner) {
    42 
    43     }
     42    protected Modulus(bool deserializing) : base(deserializing) { }
     43    protected Modulus(Modulus original, Cloner cloner) : base(original, cloner) { }
    4444
    4545    public Modulus()
    4646      : base("Modulus", "Modulus operator.") {
    47       this.Prefix = "%";
    48       this.Suffix = "";
     47      Prefix = "(";
     48      Suffix = ")";
    4949    }
    5050
     
    5353    }
    5454
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       return this.Prefix + this.Suffix;
     55    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     56      if (children.Count() < 2)
     57        throw new ArgumentException("Expected at leaset 2 children.", "children");
     58
     59      string result = string.Join(" % ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     60      return Prefix + result + Suffix;
    5761    }
    5862  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Multiplication.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2629namespace HeuristicLab.Problems.Robocode {
    2730  [StorableClass]
    28   public class Multiplication : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     31  public class Multiplication : CodeNode, INumericalOperator {
     32    public override int MinimumArity { get { return 2; } }
     33    public override int MaximumArity { get { return byte.MaxValue; } }
    3134
    3235    [Storable]
     
    3740
    3841    [StorableConstructor]
    39     private Multiplication(bool deserializing) : base(deserializing) { }
    40     private Multiplication(Multiplication original, Cloner cloner)
    41       : base(original, cloner) {
    42 
    43     }
     42    protected Multiplication(bool deserializing) : base(deserializing) { }
     43    protected Multiplication(Multiplication original, Cloner cloner) : base(original, cloner) { }
    4444
    4545    public Multiplication()
    4646      : base("Multiplication", "Multiplication operator.") {
    47       this.Prefix = "*";
    48       this.Suffix = "";
     47      Prefix = "(";
     48      Suffix = ")";
    4949    }
    5050
     
    5353    }
    5454
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       return this.Prefix + this.Suffix;
     55    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     56      if (children.Count() < 2)
     57        throw new ArgumentException("Expected at leaset 2 children.", "children");
     58
     59      string result = string.Join(" * ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     60      return Prefix + result + Suffix;
    5761    }
    5862  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Subtraction.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2629namespace HeuristicLab.Problems.Robocode {
    2730  [StorableClass]
    28   public class Subtraction : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     31  public class Subtraction : CodeNode, INumericalOperator {
     32    public override int MinimumArity { get { return 2; } }
     33    public override int MaximumArity { get { return byte.MaxValue; } }
    3134
    3235    [Storable]
     
    3740
    3841    [StorableConstructor]
    39     private Subtraction(bool deserializing) : base(deserializing) { }
    40     private Subtraction(Subtraction original, Cloner cloner)
    41       : base(original, cloner) {
    42 
    43     }
     42    protected Subtraction(bool deserializing) : base(deserializing) { }
     43    protected Subtraction(Subtraction original, Cloner cloner) : base(original, cloner) { }
    4444
    4545    public Subtraction()
    4646      : base("Subtraction", "Subtraction operator.") {
    47       this.Prefix = "-";
    48       this.Suffix = "";
     47      Prefix = "(";
     48      Suffix = ")";
    4949    }
    5050
     
    5353    }
    5454
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       return this.Prefix + this.Suffix;
     55    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     56      if (children.Count() < 2)
     57        throw new ArgumentException("Expected at leaset 2 children.", "children");
     58
     59      string result = string.Join(" - ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     60      return Prefix + result + Suffix;
    5761    }
    5862  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/NumericalExpression.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3738
    3839    [StorableConstructor]
    39     private NumericalExpression(bool deserializing) : base(deserializing) { }
    40     private NumericalExpression(NumericalExpression original, Cloner cloner)
    41       : base(original, cloner) {
    42     }
     40    protected NumericalExpression(bool deserializing) : base(deserializing) { }
     41    protected NumericalExpression(NumericalExpression original, Cloner cloner) : base(original, cloner) { }
    4342
    44     public NumericalExpression()
    45       : base("NumericalExpression", "A NumericalExpression.") {
    46       this.Prefix = "";
    47       this.Suffix = "";
    48     }
     43    public NumericalExpression() : base("NumericalExpression", "A numerical expression.") { }
    4944
    5045    public override IDeepCloneable Clone(Cloner cloner) {
     
    5247    }
    5348
    54     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     49    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5550      var enumerator = children.GetEnumerator();
     51      if (!enumerator.MoveNext()) throw new System.Exception("NumericalExpression was not given a child.");
    5652
    57       if (!enumerator.MoveNext()) throw new System.Exception("NumericalExpression was not given a child.");
    5853      var symbol = enumerator.Current.Symbol;
    59 
    60       if (!(symbol is Number || symbol is NumericalOperation || symbol.GetType().GetInterface(typeof(INumericalMethod).FullName) != null))
    61         throw new System.Exception("NumericalExpression was given a child of type " + symbol.GetType().ToString() +
    62             ". The expected child must be of type " + typeof(Number).ToString() + " or " +
    63             typeof(NumericalOperation).ToString() + " or " +
    64             typeof(INumericalMethod).ToString() + ".");
     54      if (!(symbol is Number || symbol is INumericalMethod || symbol is INumericalOperator))
     55        throw new System.Exception("NumericalExpression was given a child of type " + symbol.GetType() +
     56            ". The expected child must be of type " + typeof(Number)
     57                                           + " or " + typeof(INumericalMethod)
     58                                           + " or " + typeof(INumericalOperator) + ".");
    6559
    6660      string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    6761      if (enumerator.MoveNext()) throw new System.Exception("NumericalExpression was given more than one child.");
    6862
    69       return this.Prefix + result + this.Suffix;
     63      return result;
    7064    }
    7165  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/ShotPower.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3738
    3839    [StorableConstructor]
    39     private ShotPower(bool deserializing) : base(deserializing) { }
    40     private ShotPower(ShotPower original, Cloner cloner)
    41       : base(original, cloner) {
    42     }
     40    protected ShotPower(bool deserializing) : base(deserializing) { }
     41    protected ShotPower(ShotPower original, Cloner cloner) : base(original, cloner) { }
    4342
    44     public ShotPower()
    45       : base("ShotPower", "The power of a shot between 0.1 and 3.") {
    46     }
     43    public ShotPower() : base("ShotPower", "The power of a shot between 0.1 and 3.") { }
    4744
    4845    public override ISymbolicExpressionTreeNode CreateTreeNode() {
     
    5451    }
    5552
    56     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    57       return " " + ((ShotPowerTreeNode)node).Value + " ";
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     54      return ((ShotPowerTreeNode)node).Value.ToString();
    5855    }
    5956  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/ShotPowerTreeNode.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    3637
    3738    [StorableConstructor]
    38     private ShotPowerTreeNode(bool deserializing) : base(deserializing) { }
    39     private ShotPowerTreeNode(ShotPowerTreeNode original, Cloner cloner)
     39    protected ShotPowerTreeNode(bool deserializing) : base(deserializing) { }
     40    protected ShotPowerTreeNode(ShotPowerTreeNode original, Cloner cloner)
    4041      : base(original, cloner) {
    4142      this.value = original.value;
    4243    }
    4344
    44     public ShotPowerTreeNode()
    45       : base(new ShotPower()) {
    46     }
     45    public ShotPowerTreeNode() : base(new ShotPower()) { }
    4746
    4847    public override IDeepCloneable Clone(Cloner cloner) {
     
    5554
    5655    public override void ResetLocalParameters(IRandom random) {
    57       value = (double)random.Next(1, 3);
     56      value = Math.Max(0.1, random.NextDouble() * 3);
    5857    }
    5958  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Methods/GetEnergy.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3838
    3939    [StorableConstructor]
    40     private GetEnergy(bool deserializing) : base(deserializing) { }
    41     private GetEnergy(GetEnergy original, Cloner cloner)
    42       : base(original, cloner) {
    43 
    44     }
     40    protected GetEnergy(bool deserializing) : base(deserializing) { }
     41    protected GetEnergy(GetEnergy original, Cloner cloner) : base(original, cloner) { }
    4542
    4643    public GetEnergy()
    4744      : base("GetEnergy", "Returns the robot's current energy.") {
    48       this.Prefix = "getEnergy(";
    49       this.Suffix = ")";
     45      Prefix = "getEnergy(";
     46      Suffix = ")";
    5047    }
    5148
     
    5451    }
    5552
    56     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    57       return this.Prefix + this.Suffix;
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     54      return Prefix + Suffix;
    5855    }
    5956  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Methods/GetGunHeading.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3838
    3939    [StorableConstructor]
    40     private GetGunHeading(bool deserializing) : base(deserializing) { }
    41     private GetGunHeading(GetGunHeading original, Cloner cloner)
    42       : base(original, cloner) {
    43 
    44     }
     40    protected GetGunHeading(bool deserializing) : base(deserializing) { }
     41    protected GetGunHeading(GetGunHeading original, Cloner cloner) : base(original, cloner) { }
    4542
    4643    public GetGunHeading()
    4744      : base("GetGunHeading", "Returns the direction that the robot's gun is facing, in degrees.") {
    48       this.Prefix = "getGunHeading(";
    49       this.Suffix = ")";
     45      Prefix = "getGunHeading(";
     46      Suffix = ")";
    5047    }
    5148
     
    5451    }
    5552
    56     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    57       return this.Prefix + this.Suffix;
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     54      return Prefix + Suffix;
    5855    }
    5956  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Methods/GetHeading.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3838
    3939    [StorableConstructor]
    40     private GetHeading(bool deserializing) : base(deserializing) { }
    41     private GetHeading(GetHeading original, Cloner cloner)
    42       : base(original, cloner) {
    43 
    44     }
     40    protected GetHeading(bool deserializing) : base(deserializing) { }
     41    protected GetHeading(GetHeading original, Cloner cloner) : base(original, cloner) { }
    4542
    4643    public GetHeading()
    4744      : base("GetHeading", "Returns the direction that the robot's body is facing, in degrees.") {
    48       this.Prefix = "getHeading(";
    49       this.Suffix = ")";
     45      Prefix = "getHeading(";
     46      Suffix = ")";
    5047    }
    5148
     
    5451    }
    5552
    56     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    57       return this.Prefix + this.Suffix;
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     54      return Prefix + Suffix;
    5855    }
    5956  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Methods/GetRadarHeading.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3838
    3939    [StorableConstructor]
    40     private GetRadarHeading(bool deserializing) : base(deserializing) { }
    41     private GetRadarHeading(GetRadarHeading original, Cloner cloner)
    42       : base(original, cloner) {
    43     }
     40    protected GetRadarHeading(bool deserializing) : base(deserializing) { }
     41    protected GetRadarHeading(GetRadarHeading original, Cloner cloner) : base(original, cloner) { }
    4442
    4543    public GetRadarHeading()
    4644      : base("GetRadarHeading", "Returns the direction that the robot's radar is facing, in degrees.") {
    47       this.Prefix = "getRadarHeading(";
    48       this.Suffix = ")";
     45      Prefix = "getRadarHeading(";
     46      Suffix = ")";
    4947    }
    5048
     
    5351    }
    5452
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       return this.Prefix + this.Suffix;
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     54      return Prefix + Suffix;
    5755    }
    5856  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Methods/GetX.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3838
    3939    [StorableConstructor]
    40     private GetX(bool deserializing) : base(deserializing) { }
    41     private GetX(GetX original, Cloner cloner)
    42       : base(original, cloner) {
    43 
    44     }
     40    protected GetX(bool deserializing) : base(deserializing) { }
     41    protected GetX(GetX original, Cloner cloner) : base(original, cloner) { }
    4542
    4643    public GetX()
    4744      : base("GetX", "Returns the X position of the robot. (0,0) is at the bottom left of the battlefield.") {
    48       this.Prefix = "getX(";
    49       this.Suffix = ")";
     45      Prefix = "getX(";
     46      Suffix = ")";
    5047    }
    5148
     
    5451    }
    5552
    56     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    57       return this.Prefix + this.Suffix;
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     54      return Prefix + Suffix;
    5855    }
    5956  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Methods/GetY.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3838
    3939    [StorableConstructor]
    40     private GetY(bool deserializing) : base(deserializing) { }
    41     private GetY(GetY original, Cloner cloner)
    42       : base(original, cloner) {
    43 
    44     }
     40    protected GetY(bool deserializing) : base(deserializing) { }
     41    protected GetY(GetY original, Cloner cloner) : base(original, cloner) { }
    4542
    4643    public GetY()
    4744      : base("GetY", "Returns the Y position of the robot. (0,0) is at the bottom left of the battlefield.") {
    48       this.Prefix = "getY(";
    49       this.Suffix = ")";
     45      Prefix = "getY(";
     46      Suffix = ")";
    5047    }
    5148
     
    5451    }
    5552
    56     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    57       return this.Prefix + this.Suffix;
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     54      return Prefix + Suffix;
    5855    }
    5956  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Methods/INumericalMethod.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
    23 
    2422namespace HeuristicLab.Problems.Robocode {
    25   public interface INumericalMethod {
    26   }
     23  public interface INumericalMethod { }
    2724}
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Program.cs

    r9790 r10011  
    3232
    3333    [StorableConstructor]
    34     private Program(bool deserializing) : base(deserializing) { }
    35     private Program(Program original, Cloner cloner)
    36       : base(original, cloner) {
    37     }
     34    protected Program(bool deserializing) : base(deserializing) { }
     35    protected Program(Program original, Cloner cloner) : base(original, cloner) { }
    3836
    3937    public Program()
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Statements/ElseStat.cs

    r9999 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2629namespace HeuristicLab.Problems.Robocode {
    2730  [StorableClass]
    28   public class ElseStatement : CodeNode {
     31  public class ElseStat : CodeNode {
    2932    public override int MinimumArity { get { return 1; } }
    3033    public override int MaximumArity { get { return 1; } }
     
    3740
    3841    [StorableConstructor]
    39     private ElseStatement(bool deserializing) : base(deserializing) { }
    40     private ElseStatement(ElseStatement original, Cloner cloner)
    41       : base(original, cloner) {
     42    protected ElseStat(bool deserializing) : base(deserializing) { }
     43    protected ElseStat(ElseStat original, Cloner cloner) : base(original, cloner) { }
    4244
    43     }
    44 
    45     public ElseStatement()
     45    public ElseStat()
    4646      : base("ElseStatement", "An ElseStatement.") {
    47       this.Prefix = "else";
    48       this.Suffix = "";
     47      Prefix = "else";
     48      Suffix = "";
    4949    }
    5050
    5151    public override IDeepCloneable Clone(Cloner cloner) {
    52       return new ElseStatement(this, cloner);
     52      return new ElseStat(this, cloner);
    5353    }
    5454
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       string result = "";
    57       foreach (ISymbolicExpressionTreeNode c in children)
    58         result += "\r\n" + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    59       return (result == "") ? "" : this.Prefix + "\r\n" + result + "\r\n" + this.Suffix;
     55    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     56      string result = children.Aggregate(string.Empty, (current, c) => current + (Environment.NewLine + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     57      return string.IsNullOrEmpty(result)
     58        ? string.Empty
     59        : Prefix + Environment.NewLine + result + Environment.NewLine + Suffix;
    6060    }
    6161  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Statements/IfStat.cs

    r9999 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
    2224using HeuristicLab.Common;
    2325using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2628namespace HeuristicLab.Problems.Robocode {
    2729  [StorableClass]
    28   public class IfStatement : CodeNode {
     30  public class IfStat : CodeNode {
    2931    public override int MinimumArity { get { return 2; } }
    3032    public override int MaximumArity { get { return 3; } }
     
    3739
    3840    [StorableConstructor]
    39     private IfStatement(bool deserializing) : base(deserializing) { }
    40     private IfStatement(IfStatement original, Cloner cloner)
    41       : base(original, cloner) {
    42     }
     41    protected IfStat(bool deserializing) : base(deserializing) { }
     42    protected IfStat(IfStat original, Cloner cloner) : base(original, cloner) { }
    4343
    44     public IfStatement()
    45       : base("IfStatement", "An IfStatement.") {
    46       this.Prefix = "if(";
    47       this.Suffix = ")";
     44    public IfStat()
     45      : base("IfStatement", "An if statement.") {
     46      Prefix = "if (";
     47      Suffix = ")";
    4848    }
    4949
    5050    public override IDeepCloneable Clone(Cloner cloner) {
    51       return new IfStatement(this, cloner);
     51      return new IfStat(this, cloner);
    5252    }
    5353
    54     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    55       string condition = "", ifTrue = "", ifElse = "";
    56       foreach (ISymbolicExpressionTreeNode c in children) {
     54    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) {
    5757        if (c.Symbol is LogicalExpression)
    5858          condition = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    59         else if (c.Symbol is Block)
     59        else if (c.Symbol is Stat)
    6060          ifTrue = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    61         else if (c.Symbol is ElseStatement || c.Symbol is DoNothing)
     61        else if (c.Symbol is ElseStat || c.Symbol is EmptyEvent || c.Symbol is DoNothing)
    6262          ifElse = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    63         else
    64           throw new System.Exception("Unexpected Child node.");
     63        else throw new ArgumentException("Unexpected children.", "children");
    6564      }
    66       return this.Prefix + " " + condition + " " + this.Suffix +
    67           "\r\n" + ifTrue + "\r\n" + ifElse + "\r\n";
     65      return Prefix + condition + Suffix + Environment.NewLine + ifTrue + Environment.NewLine + ifElse + Environment.NewLine;
    6866    }
    6967  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Statements/WhileStat.cs

    r9999 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
    2224using HeuristicLab.Common;
    2325using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2628namespace HeuristicLab.Problems.Robocode {
    2729  [StorableClass]
    28   public class WhileLoop : CodeNode {
     30  public class WhileStat : CodeNode {
    2931    public override int MinimumArity { get { return 2; } }
    3032    public override int MaximumArity { get { return 2; } }
     
    3739
    3840    [StorableConstructor]
    39     private WhileLoop(bool deserializing) : base(deserializing) { }
    40     private WhileLoop(WhileLoop original, Cloner cloner)
    41       : base(original, cloner) {
     41    protected WhileStat(bool deserializing) : base(deserializing) { }
     42    protected WhileStat(WhileStat original, Cloner cloner) : base(original, cloner) { }
    4243
    43     }
    44 
    45     public WhileLoop()
    46       : base("WhileLoop", "A WhileLoop.") {
    47       this.Prefix = "while(";
    48       this.Suffix = ")";
     44    public WhileStat()
     45      : base("WhileStat", "A while statement.") {
     46      Prefix = "while (";
     47      Suffix = ")";
    4948    }
    5049
    5150    public override IDeepCloneable Clone(Cloner cloner) {
    52       return new WhileLoop(this, cloner);
     51      return new WhileStat(this, cloner);
    5352    }
    5453
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       string condition = "", ifTrue = "";
    57       foreach (ISymbolicExpressionTreeNode c in children) {
     54    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     55      string condition = string.Empty, ifTrue = string.Empty;
     56      foreach (var c in children) {
    5857        if (c.Symbol is LogicalExpression)
    5958          condition = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    60         else if (c.Symbol is Block)
     59        else if (c.Symbol is Stat || c.Symbol is EmptyEvent || c.Symbol is DoNothing)
    6160          ifTrue = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    62         else
    63           throw new System.Exception("Unexpected Child node.");
     61        else throw new ArgumentException("Unexpected children.", "children");
    6462      }
    65       return this.Prefix + " " + condition + " " + this.Suffix +
    66           "\r\n" + ifTrue + "\r\n";
     63      return Prefix + condition + Suffix + Environment.NewLine + ifTrue + Environment.NewLine;
    6764    }
    6865  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Tank.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2830  [StorableClass]
    2931  public class Tank : CodeNode {
    30     public override int MinimumArity { get { return 7; } }
     32    public override int MinimumArity { get { return 2; } }
    3133    public override int MaximumArity { get { return 7; } }
    3234
     
    3840
    3941    [StorableConstructor]
    40     private Tank(bool deserializing) : base(deserializing) { }
    41     private Tank(Tank original, Cloner cloner)
    42       : base(original, cloner) {
    43     }
     42    protected Tank(bool deserializing) : base(deserializing) { }
     43    protected Tank(Tank original, Cloner cloner) : base(original, cloner) { }
    4444
    4545    public Tank()
    4646      : base("Tank", "The root of a Robocode Tank program.") {
    47       this.Prefix = "package Evaluation;" +
    48                     "\r\nimport robocode.*;" +
    49                     "\r\nimport robocode.Robot;" +
    50                     "\r\nimport robocode.util.*;" +
    51                     "\r\nimport static robocode.util.Utils.normalRelativeAngleDegrees;" +
    52                     "\r\nimport java.awt.*;" +
    53                     "\r\n\r\n" +
    54                     "\r\npublic class output extends AdvancedRobot {\r\n";
    55       this.Suffix = "\r\n}";
     47      Prefix =
     48@"package Evaluation;
     49import robocode.*;
     50import robocode.Robot;
     51import robocode.util.*;
     52import static robocode.util.Utils.normalRelativeAngleDegrees;
     53import java.awt.*;
     54
     55public class output extends AdvancedRobot {";
     56      Suffix = "}";
    5657    }
    5758
     
    6061    }
    6162
    62     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    63       string result = "";
    64       foreach (ISymbolicExpressionTreeNode c in children)
    65         result += "\r\n" + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
    66       return this.Prefix + "\r\n" + result + "\r\n" + this.Suffix;
     63    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     64      string result = children.Aggregate(string.Empty, (current, c) => current + (Environment.NewLine + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     65      return Prefix + result + Environment.NewLine + Suffix;
    6766    }
    6867  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/Ahead.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3838
    3939    [StorableConstructor]
    40     private Ahead(bool deserializing) : base(deserializing) { }
    41     private Ahead(Ahead original, Cloner cloner)
    42       : base(original, cloner) {
    43     }
     40    protected Ahead(bool deserializing) : base(deserializing) { }
     41    protected Ahead(Ahead original, Cloner cloner) : base(original, cloner) { }
    4442
    4543    public Ahead()
    4644      : base("Ahead", "Immediately moves your robot ahead (forward) by distance measured in pixels.") {
    47       this.Prefix = "setAhead(";
    48       this.Suffix = ");";
     45      Prefix = "setAhead(";
     46      Suffix = ");";
    4947    }
    5048
     
    5351    }
    5452
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5654      var enumerator = children.GetEnumerator();
     55      if (!enumerator.MoveNext()) throw new System.Exception("Ahead was not given a child.");
    5756
    58       if (!enumerator.MoveNext()) throw new System.Exception("Ahead was not given a child.");
    5957      var symbol = enumerator.Current.Symbol;
    60 
    61       if (!(symbol is Number || symbol is NumericalOperation || symbol is NumericalExpression))
    62         throw new System.Exception("Ahead was given a child of type " + symbol.GetType().ToString() +
    63             ". The expected child must be of type " + typeof(Number).ToString() + " or " +
    64             typeof(NumericalOperation).ToString() + " or " +
    65             typeof(NumericalExpression).ToString() + ".");
     58      if (!(symbol is NumericalExpression))
     59        throw new System.Exception("Ahead was given a child of type " + symbol.GetType() +
     60            ". The expected child must be of type " + typeof(NumericalExpression) + ".");
    6661
    6762      string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    6863      if (enumerator.MoveNext()) throw new System.Exception("Ahead was given more than one child.");
    6964
    70       return this.Prefix + result + this.Suffix;
     65      return Prefix + result + Suffix;
    7166    }
    7267  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/Back.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3838
    3939    [StorableConstructor]
    40     private Back(bool deserializing) : base(deserializing) { }
    41     private Back(Back original, Cloner cloner)
    42       : base(original, cloner) { }
     40    protected Back(bool deserializing) : base(deserializing) { }
     41    protected Back(Back original, Cloner cloner) : base(original, cloner) { }
    4342
    4443    public Back()
    4544      : base("Back", "Immediately moves your robot backward by distance measured in pixels.") {
    46       this.Prefix = "setBack(";
    47       this.Suffix = ");";
     45      Prefix = "setBack(";
     46      Suffix = ");";
    4847    }
    4948
     
    5251    }
    5352
    54     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5554      var enumerator = children.GetEnumerator();
     55      if (!enumerator.MoveNext()) throw new System.Exception("Back was not given a child.");
    5656
    57       if (!enumerator.MoveNext()) throw new System.Exception("Back was not given a child.");
    5857      var symbol = enumerator.Current.Symbol;
    59 
    60       if (!(symbol is Number || symbol is NumericalOperation || symbol is NumericalExpression))
    61         throw new System.Exception("Back was given a child of type " + symbol.GetType().ToString() +
    62             ". The expected child must be of type " + typeof(Number).ToString() + " or " +
    63             typeof(NumericalOperation).ToString() + " or " +
    64             typeof(NumericalExpression).ToString() + ".");
     58      if (!(symbol is NumericalExpression))
     59        throw new System.Exception("Back was given a child of type " + symbol.GetType() +
     60            ". The expected child must be of type " + typeof(NumericalExpression) + ".");
    6561
    6662      string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    6763      if (enumerator.MoveNext()) throw new System.Exception("Back was given more than one child.");
    6864
    69       return this.Prefix + result + this.Suffix;
     65      return Prefix + result + Suffix;
    7066    }
    7167  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/DoNothing.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3838
    3939    [StorableConstructor]
    40     private DoNothing(bool deserializing) : base(deserializing) { }
    41     private DoNothing(DoNothing original, Cloner cloner)
    42       : base(original, cloner) {
    43     }
     40    protected DoNothing(bool deserializing) : base(deserializing) { }
     41    protected DoNothing(DoNothing original, Cloner cloner) : base(original, cloner) { }
    4442
    45     public DoNothing()
    46       : base("DoNothing", "Do nothing this turn, meaning that the robot will skip it's turn.") {
    47     }
     43    public DoNothing() : base("DoNothing", "Do nothing this turn, meaning that the robot will skip it's turn.") { }
    4844
    4945    public override IDeepCloneable Clone(Cloner cloner) {
     
    5147    }
    5248
    53     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    54       return "";
     49    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     50      return ";";
    5551    }
    5652  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/Fire.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3838
    3939    [StorableConstructor]
    40     private Fire(bool deserializing) : base(deserializing) { }
    41     private Fire(Fire original, Cloner cloner)
    42       : base(original, cloner) { }
     40    protected Fire(bool deserializing) : base(deserializing) { }
     41    protected Fire(Fire original, Cloner cloner) : base(original, cloner) { }
    4342
    4443    public Fire()
    4544      : base("Fire", "Immediately fires a bullet.") {
    46       this.Prefix = "setFire(";
    47       this.Suffix = ");";
     45      Prefix = "setFire(";
     46      Suffix = ");";
    4847    }
    4948
     
    5251    }
    5352
    54     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5554      var enumerator = children.GetEnumerator();
     55      if (!enumerator.MoveNext()) throw new System.Exception("Fire was not given a child.");
    5656
    57       if (!enumerator.MoveNext()) throw new System.Exception("Fire was not given a child.");
    5857      var symbol = enumerator.Current.Symbol;
    59 
    6058      if (!(symbol is ShotPower))
    61         throw new System.Exception("Fire was given a child of type " + symbol.GetType().ToString() +
    62             ". The expected child must be of type " + typeof(ShotPower).ToString() + ".");
     59        throw new System.Exception("Fire was given a child of type " + symbol.GetType() +
     60            ". The expected child must be of type " + typeof(ShotPower) + ".");
    6361
    6462      string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    6563      if (enumerator.MoveNext()) throw new System.Exception("Fire was given more than one child.");
    6664
    67       return this.Prefix + result + this.Suffix;
     65      return Prefix + result + Suffix;
    6866    }
    6967  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/TurnGunLeft.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3838
    3939    [StorableConstructor]
    40     private TurnGunLeft(bool deserializing) : base(deserializing) { }
    41     private TurnGunLeft(TurnGunLeft original, Cloner cloner)
    42       : base(original, cloner) {
    43     }
     40    protected TurnGunLeft(bool deserializing) : base(deserializing) { }
     41    protected TurnGunLeft(TurnGunLeft original, Cloner cloner) : base(original, cloner) { }
    4442
    4543    public TurnGunLeft()
    4644      : base("TurnGunLeft", "Immediately turns the robot's gun to the left by degrees.") {
    47       this.Prefix = "setTurnGunLeft(";
    48       this.Suffix = ");";
     45      Prefix = "setTurnGunLeft(";
     46      Suffix = ");";
    4947    }
    5048
     
    5351    }
    5452
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5654      var enumerator = children.GetEnumerator();
     55      if (!enumerator.MoveNext()) throw new System.Exception("TurnGunLeft was not given a child.");
    5756
    58       if (!enumerator.MoveNext()) throw new System.Exception("TurnGunLeft was not given a child.");
    5957      var symbol = enumerator.Current.Symbol;
    60 
    61       if (!(symbol is Number || symbol is NumericalOperation || symbol is NumericalExpression))
    62         throw new System.Exception("TurnGunLeft was given a child of type " + symbol.GetType().ToString() +
    63             ". The expected child must be of type " + typeof(Number).ToString() + " or " +
    64             typeof(NumericalOperation).ToString() + " or " +
    65             typeof(NumericalExpression).ToString() + ".");
     58      if (!(symbol is NumericalExpression))
     59        throw new System.Exception("TurnGunLeft was given a child of type " + symbol.GetType() +
     60            ". The expected child must be of type " + typeof(NumericalExpression) + ".");
    6661
    6762      string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    6863      if (enumerator.MoveNext()) throw new System.Exception("TurnGunLeft was given more than one child.");
    6964
    70       return this.Prefix + result + this.Suffix;
     65      return Prefix + result + Suffix;
    7166    }
    7267  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/TurnGunRight.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3838
    3939    [StorableConstructor]
    40     private TurnGunRight(bool deserializing) : base(deserializing) { }
    41     private TurnGunRight(TurnGunRight original, Cloner cloner)
    42       : base(original, cloner) {
    43 
    44     }
     40    protected TurnGunRight(bool deserializing) : base(deserializing) { }
     41    protected TurnGunRight(TurnGunRight original, Cloner cloner) : base(original, cloner) { }
    4542
    4643    public TurnGunRight()
    4744      : base("TurnGunRight", "Immediately turns the robot's gun to the right by degrees.") {
    48       this.Prefix = "setTurnGunRight(";
    49       this.Suffix = ");";
     45      Prefix = "setTurnGunRight(";
     46      Suffix = ");";
    5047    }
    5148
     
    5451    }
    5552
    56     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5754      var enumerator = children.GetEnumerator();
     55      if (!enumerator.MoveNext()) throw new System.Exception("TurnGunRight was not given a child.");
    5856
    59       if (!enumerator.MoveNext()) throw new System.Exception("TurnGunRight was not given a child.");
    6057      var symbol = enumerator.Current.Symbol;
    61 
    62       if (!(symbol is Number || symbol is NumericalOperation || symbol is NumericalExpression))
    63         throw new System.Exception("TurnGunRight was given a child of type " + symbol.GetType().ToString() +
    64             ". The expected child must be of type " + typeof(Number).ToString() + " or " +
    65             typeof(NumericalOperation).ToString() + " or " +
    66             typeof(NumericalExpression).ToString() + ".");
     58      if (!(symbol is NumericalExpression))
     59        throw new System.Exception("TurnGunRight was given a child of type " + symbol.GetType() +
     60            ". The expected child must be of type " + typeof(NumericalExpression) + ".");
    6761
    6862      string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    6963      if (enumerator.MoveNext()) throw new System.Exception("TurnGunRight was given more than one child.");
    7064
    71       return this.Prefix + result + this.Suffix;
     65      return Prefix + result + Suffix;
    7266    }
    7367  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/TurnLeft.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3838
    3939    [StorableConstructor]
    40     private TurnLeft(bool deserializing) : base(deserializing) { }
    41     private TurnLeft(TurnLeft original, Cloner cloner)
    42       : base(original, cloner) {
    43     }
     40    protected TurnLeft(bool deserializing) : base(deserializing) { }
     41    protected TurnLeft(TurnLeft original, Cloner cloner) : base(original, cloner) { }
    4442
    4543    public TurnLeft()
    4644      : base("TurnLeft", "Immediately turns the robot's body to the left by degrees.") {
    47       this.Prefix = "setTurnLeft(";
    48       this.Suffix = ");";
     45      Prefix = "setTurnLeft(";
     46      Suffix = ");";
    4947    }
    5048
     
    5351    }
    5452
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5654      var enumerator = children.GetEnumerator();
     55      if (!enumerator.MoveNext()) throw new System.Exception("TurnLeft was not given a child.");
    5756
    58       if (!enumerator.MoveNext()) throw new System.Exception("TurnLeft was not given a child.");
    5957      var symbol = enumerator.Current.Symbol;
    60 
    61       if (!(symbol is Number || symbol is NumericalOperation || symbol is NumericalExpression))
    62         throw new System.Exception("TurnLeft was given a child of type " + symbol.GetType().ToString() +
    63             ". The expected child must be of type " + typeof(Number).ToString() + " or " +
    64             typeof(NumericalOperation).ToString() + " or " +
    65             typeof(NumericalExpression).ToString() + ".");
     58      if (!(symbol is NumericalExpression))
     59        throw new System.Exception("TurnLeft was given a child of type " + symbol.GetType() +
     60            ". The expected child must be of type " + typeof(NumericalExpression) + ".");
    6661
    6762      string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    6863      if (enumerator.MoveNext()) throw new System.Exception("TurnLeft was given more than one child.");
    6964
    70       return this.Prefix + result + this.Suffix;
     65      return Prefix + result + Suffix;
    7166    }
    7267  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/TurnRadarLeft.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3838
    3939    [StorableConstructor]
    40     private TurnRadarLeft(bool deserializing) : base(deserializing) { }
    41     private TurnRadarLeft(TurnRadarLeft original, Cloner cloner)
    42       : base(original, cloner) {
    43     }
     40    protected TurnRadarLeft(bool deserializing) : base(deserializing) { }
     41    protected TurnRadarLeft(TurnRadarLeft original, Cloner cloner) : base(original, cloner) { }
    4442
    4543    public TurnRadarLeft()
    4644      : base("TurnRadarLeft", "Immediately turns the robot's radar to the left by degrees.") {
    47       this.Prefix = "setTurnRadarLeft(";
    48       this.Suffix = ");";
     45      Prefix = "setTurnRadarLeft(";
     46      Suffix = ");";
    4947    }
    5048
     
    5351    }
    5452
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5654      var enumerator = children.GetEnumerator();
     55      if (!enumerator.MoveNext()) throw new System.Exception("TurnRadarLeft was not given a child.");
    5756
    58       if (!enumerator.MoveNext()) throw new System.Exception("TurnRadarLeft was not given a child.");
    5957      var symbol = enumerator.Current.Symbol;
    60 
    61       if (!(symbol is Number || symbol is NumericalOperation || symbol is NumericalExpression))
    62         throw new System.Exception("TurnRadarLeft was given a child of type " + symbol.GetType().ToString() +
    63             ". The expected child must be of type " + typeof(Number).ToString() + " or " +
    64             typeof(NumericalOperation).ToString() + " or " +
    65             typeof(NumericalExpression).ToString() + ".");
     58      if (!(symbol is NumericalExpression))
     59        throw new System.Exception("TurnRadarLeft was given a child of type " + symbol.GetType() +
     60            ". The expected child must be of type " + typeof(NumericalExpression) + ".");
    6661
    6762      string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    6863      if (enumerator.MoveNext()) throw new System.Exception("TurnRadarLeft was given more than one child.");
    6964
    70       return this.Prefix + result + this.Suffix;
     65      return Prefix + result + Suffix;
    7166    }
    7267  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/TurnRadarRight.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3838
    3939    [StorableConstructor]
    40     private TurnRadarRight(bool deserializing) : base(deserializing) { }
    41     private TurnRadarRight(TurnRadarRight original, Cloner cloner)
    42       : base(original, cloner) {
    43 
    44     }
     40    protected TurnRadarRight(bool deserializing) : base(deserializing) { }
     41    protected TurnRadarRight(TurnRadarRight original, Cloner cloner) : base(original, cloner) { }
    4542
    4643    public TurnRadarRight()
    4744      : base("TurnRadarRight", "Immediately turns the robot's radar to the right by degrees.") {
    48       this.Prefix = "setTurnRadarRight(";
    49       this.Suffix = ");";
     45      Prefix = "setTurnRadarRight(";
     46      Suffix = ");";
    5047    }
    5148
     
    5451    }
    5552
    56     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5754      var enumerator = children.GetEnumerator();
     55      if (!enumerator.MoveNext()) throw new System.Exception("TurnRadarRight was not given a child.");
    5856
    59       if (!enumerator.MoveNext()) throw new System.Exception("TurnRadarRight was not given a child.");
    6057      var symbol = enumerator.Current.Symbol;
    61 
    62       if (!(symbol is Number || symbol is NumericalOperation || symbol is NumericalExpression))
    63         throw new System.Exception("TurnRadarRight was given a child of type " + symbol.GetType().ToString() +
    64             ". The expected child must be of type " + typeof(Number).ToString() + " or " +
    65             typeof(NumericalOperation).ToString() + " or " +
    66             typeof(NumericalExpression).ToString() + ".");
     58      if (!(symbol is NumericalExpression))
     59        throw new System.Exception("TurnRadarRight was given a child of type " + symbol.GetType() +
     60            ". The expected child must be of type " + typeof(NumericalExpression) + ".");
    6761
    6862      string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    6963      if (enumerator.MoveNext()) throw new System.Exception("TurnRadarRight was given more than one child.");
    7064
    71       return this.Prefix + result + this.Suffix;
     65      return Prefix + result + Suffix;
    7266    }
    7367  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/TurnRight.cs

    r9790 r10011  
    2020#endregion
    2121
    22 
     22using System.Collections.Generic;
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    3838
    3939    [StorableConstructor]
    40     private TurnRight(bool deserializing) : base(deserializing) { }
    41     private TurnRight(TurnRight original, Cloner cloner)
    42       : base(original, cloner) {
    43 
    44     }
     40    protected TurnRight(bool deserializing) : base(deserializing) { }
     41    protected TurnRight(TurnRight original, Cloner cloner) : base(original, cloner) { }
    4542
    4643    public TurnRight()
    4744      : base("TurnRight", "Immediately turns the robot's body to the right by degrees.") {
    48       this.Prefix = "setTurnRight(";
    49       this.Suffix = ");";
     45      Prefix = "setTurnRight(";
     46      Suffix = ");";
    5047    }
    5148
     
    5451    }
    5552
    56     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     53    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5754      var enumerator = children.GetEnumerator();
     55      if (!enumerator.MoveNext()) throw new System.Exception("TurnRight was not given a child.");
    5856
    59       if (!enumerator.MoveNext()) throw new System.Exception("TurnRight was not given a child.");
    6057      var symbol = enumerator.Current.Symbol;
    61 
    62       if (!(symbol is Number || symbol is NumericalOperation || symbol is NumericalExpression))
    63         throw new System.Exception("TurnRight was given a child of type " + symbol.GetType().ToString() +
    64             ". The expected child must be of type " + typeof(Number).ToString() + " or " +
    65             typeof(NumericalOperation).ToString() + " or " +
    66             typeof(NumericalExpression).ToString() + ".");
     58      if (!(symbol is NumericalExpression))
     59        throw new System.Exception("TurnRight was given a child of type " + symbol.GetType() +
     60            ". The expected child must be of type " + typeof(NumericalExpression) + ".");
    6761
    6862      string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    6963      if (enumerator.MoveNext()) throw new System.Exception("TurnRight was given more than one child.");
    7064
    71       return this.Prefix + result + this.Suffix;
     65      return Prefix + result + Suffix;
    7266    }
    7367  }
Note: See TracChangeset for help on using the changeset viewer.