- Timestamp:
- 10/01/13 12:08:25 (11 years ago)
- Location:
- branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3
- Files:
-
- 3 added
- 6 deleted
- 52 edited
- 3 copied
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/EnemyCollection.cs ¶
r9971 r10011 37 37 38 38 [StorableConstructor] 39 pr ivateEnemyCollection(bool deserializing) : base(deserializing) { }40 pr ivateEnemyCollection(EnemyCollection original, Cloner cloner)39 protected EnemyCollection(bool deserializing) : base(deserializing) { } 40 protected EnemyCollection(EnemyCollection original, Cloner cloner) 41 41 : base(original, cloner) { 42 42 RobocodePath = original.RobocodePath; … … 69 69 robotList.SetItemCheckedState(robot, false); 70 70 } 71 } 72 catch { } 71 } catch { } 73 72 74 73 return robotList; -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Grammar.cs ¶
r9879 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic;23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; … … 31 30 public class Grammar : SymbolicExpressionGrammar { 32 31 [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) { } 37 34 38 35 public Grammar() … … 50 47 #region Symbols 51 48 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 58 73 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(); 78 75 79 76 var ahead = new Ahead(); 80 77 var back = new Back(); 81 var doNothing = new DoNothing();82 78 var fire = new Fire(); 83 79 var shotPower = new ShotPower(); … … 108 104 var onHitWall = new OnHitWall(); 109 105 var onScannedRobot = new OnScannedRobot(); 110 var emptyEvent = new EmptyEvent();111 106 112 107 var run = new Run(); 113 108 var tank = new Tank(); 114 var program = new Program(); 109 110 var doNothing = new DoNothing(); 111 var emptyEvent = new EmptyEvent(); 115 112 #endregion 116 113 117 114 #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 }; 165 125 #endregion 166 126 167 127 #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); 175 138 foreach (var s in numericalExpressions) 176 139 AddSymbol(s); … … 178 141 AddSymbol(s); 179 142 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); 190 184 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); 210 208 211 209 // 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 } 216 219 } 217 foreach (var s in numericalOperators)218 AddAllowedChildSymbol(numOp, s, 0);219 220 220 221 // 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); 226 230 } 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 247 235 foreach (var f in functionSymbols) { 248 236 if (f is Fire) 249 237 AddAllowedChildSymbol(f, shotPower); 250 238 else 251 AddAllowedChildSymbol(f, numExpr); 252 239 AddAllowedChildSymbol(f, numericalExpr); 253 240 } 254 255 // Add all Event Methods to Tank. Run and OnScannedEvent are not optional,256 // so EmptyEvent cannot take their places257 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);269 241 #endregion 270 242 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/HeuristicLab.Problems.Robocode-3.3.csproj ¶
r9983 r10011 109 109 <Compile Include="Solution.cs" /> 110 110 <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" /> 111 113 <Compile Include="Symbols\Numerical Methods\INumericalMethod.cs" /> 114 <Compile Include="Symbols\Stat.cs" /> 112 115 <Compile Include="Symbols\Void Methods\Ahead.cs" /> 113 116 <Compile Include="Symbols\Void Methods\Back.cs" /> 114 117 <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" /> 118 121 <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" /> 121 124 <Compile Include="Symbols\Logical Expressions\Logical Comparators\Equal.cs" /> 122 125 <Compile Include="Symbols\Logical Expressions\Logical Comparators\GreaterThan.cs" /> … … 124 127 <Compile Include="Symbols\Logical Expressions\Logical Comparators\LessThan.cs" /> 125 128 <Compile Include="Symbols\Logical Expressions\Logical Comparators\LessThanOrEqual.cs" /> 126 <Compile Include="Symbols\Logical Expressions\LogicalComparison.cs" />127 129 <Compile Include="Symbols\Logical Expressions\LogicalExpression.cs" /> 128 130 <Compile Include="Symbols\Logical Expressions\LogicalValue.cs" /> 129 131 <Compile Include="Symbols\Logical Expressions\Negation.cs" /> 130 <Compile Include="Symbols\Logical Expressions\NumericalComparison.cs" />131 132 <Compile Include="Symbols\Numerical Expressions\NumberTreeNode.cs" /> 132 133 <Compile Include="Symbols\Numerical Expressions\Number.cs" /> … … 137 138 <Compile Include="Symbols\Numerical Expressions\Numerical Operators\Subtraction.cs" /> 138 139 <Compile Include="Symbols\Numerical Expressions\NumericalExpression.cs" /> 139 <Compile Include="Symbols\Numerical Expressions\NumericalOperation.cs" />140 140 <Compile Include="Symbols\CodeNode.cs" /> 141 141 <Compile Include="Symbols\Tank.cs" /> -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/RobocodeProblem.cs ¶
r9985 r10011 83 83 robotList.RobocodePath = robocodeDir.Value; 84 84 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))); 86 86 Parameters.Add(new FixedValueParameter<IntValue>(MaxTankProgramLengthParameterName, "Maximal length of the tank program.", new IntValue(1000))); 87 87 Parameters.Add(new ValueParameter<Grammar>(TankGrammarParameterName, "Grammar for the tank program.", new Grammar())); -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Block.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 29 30 public class Block : CodeNode { 30 31 public override int MinimumArity { get { return 1; } } 31 public override int MaximumArity { get { return 10; } }32 public override int MaximumArity { get { return byte.MaxValue; } } 32 33 33 34 [Storable] … … 38 39 39 40 [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) { } 44 43 45 44 public Block() 46 45 : 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 = "}"; 49 48 } 50 49 … … 54 53 55 54 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; 60 57 } 61 58 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/CodeNode.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 35 35 protected CodeNode(CodeNode original, Cloner cloner) 36 36 : base(original, cloner) { 37 this.Prefix = original.Prefix;38 this.Suffix = original.Suffix;37 Prefix = original.Prefix; 38 Suffix = original.Suffix; 39 39 } 40 40 protected CodeNode(string name, string description) 41 41 : base(name, description) { 42 Prefix = string.Empty; 43 Suffix = string.Empty; 42 44 } 43 45 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); 57 47 } 58 48 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Event Methods/Events/EmptyEvent.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 37 38 38 39 [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) { } 43 42 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.") { } 49 44 50 45 public override IDeepCloneable Clone(Cloner cloner) { … … 52 47 } 53 48 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 ";"; 56 51 } 57 52 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Event Methods/Events/OnBulletHit.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 37 40 38 41 [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) { } 44 44 45 45 public OnBulletHit() 46 46 : 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 }"; 49 51 } 50 52 … … 53 55 } 54 56 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; 60 60 } 61 61 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Event Methods/Events/OnBulletMissed.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 37 40 38 41 [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) { } 44 44 45 45 public OnBulletMissed() 46 46 : 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 }"; 49 51 } 50 52 … … 53 55 } 54 56 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; 60 60 } 61 61 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Event Methods/Events/OnHitByBullet.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 37 40 38 41 [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) { } 44 44 45 45 public OnHitByBullet() 46 46 : 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 }"; 49 51 } 50 52 … … 53 55 } 54 56 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; 60 60 } 61 61 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Event Methods/Events/OnHitRobot.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 37 40 38 41 [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) { } 43 44 44 45 public OnHitRobot() 45 46 : 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 }"; 48 51 } 49 52 … … 52 55 } 53 56 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; 59 60 } 60 61 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Event Methods/Events/OnHitWall.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 37 40 38 41 [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) { } 44 44 45 45 public OnHitWall() 46 46 : 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 }"; 49 51 } 50 52 … … 53 55 } 54 56 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; 60 60 } 61 61 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Event Methods/Events/OnScannedRobot.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 37 40 38 41 [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) { } 44 44 45 45 public OnScannedRobot() 46 46 : 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) { 49 double absoluteBearing = getHeading() + e.getBearing(); 50 double bearingFromGun = normalRelativeAngleDegrees(absoluteBearing - getGunHeading()); 51 setTurnGunRight(bearingFromGun);"; 52 Suffix = 53 @"execute(); 54 }"; 52 55 } 53 56 … … 56 59 } 57 60 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; 63 64 } 64 65 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Event Methods/Run.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 27 30 [StorableClass] 28 31 public class Run : CodeNode { 29 public override int MinimumArity { get { return 2; } }32 public override int MinimumArity { get { return 1; } } 30 33 public override int MaximumArity { get { return 10; } } 31 34 … … 37 40 38 41 [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) { } 43 44 44 45 public Run() 45 46 : 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() { 49 setAdjustGunForRobotTurn(true); 50 turnRadarRightRadians(Double.POSITIVE_INFINITY);"; 51 Suffix = 52 @"execute(); 53 }"; 48 54 } 49 55 … … 52 58 } 53 59 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; 59 63 } 60 64 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/BooleanTreeNode.cs ¶
r9790 r10011 36 36 37 37 [StorableConstructor] 38 pr ivateBooleanTreeNode(bool deserializing) : base(deserializing) { }39 pr ivateBooleanTreeNode(BooleanTreeNode original, Cloner cloner)38 protected BooleanTreeNode(bool deserializing) : base(deserializing) { } 39 protected BooleanTreeNode(BooleanTreeNode original, Cloner cloner) 40 40 : base(original, cloner) { 41 this.value = original.value;41 value = original.value; 42 42 } 43 43 44 public BooleanTreeNode() 45 : base(new LogicalValue()) { 46 } 44 public BooleanTreeNode() : base(new LogicalValue()) { } 47 45 48 46 public override IDeepCloneable Clone(Cloner cloner) { … … 55 53 56 54 public override void ResetLocalParameters(IRandom random) { 57 value = (bool)(random.Next(0, 1) == 1);55 value = random.Next(0, 2) == 1; 58 56 } 59 57 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Conjunction.cs ¶
r9999 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 27 30 [StorableClass] 28 31 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; } } 31 34 32 35 [Storable] … … 37 40 38 41 [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) { } 43 44 44 45 public Conjunction() 45 46 : base("Conjunction", "Conjunction comparator.") { 46 this.Prefix = "&&";47 this.Suffix = "";47 Prefix = "("; 48 Suffix = ")"; 48 49 } 49 50 … … 52 53 } 53 54 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; 56 61 } 57 62 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Disjunction.cs ¶
r9999 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 23 using System.Linq; 22 24 using HeuristicLab.Common; 23 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 27 29 [StorableClass] 28 30 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; } } 31 33 32 34 [Storable] … … 37 39 38 40 [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) { } 43 43 44 44 public Disjunction() 45 45 : base("Disjunction", "Disjunction comparator.") { 46 this.Prefix = "||";47 this.Suffix = "";46 Prefix = "("; 47 Suffix = ")"; 48 48 } 49 49 … … 52 52 } 53 53 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; 56 57 } 57 58 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/Equal.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 27 namespace HeuristicLab.Problems.Robocode { 27 28 [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; } } 31 32 32 33 [Storable] … … 37 38 38 39 [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) { } 43 42 44 public Equal() 45 : base("Equal", "Equal comparator.") { 46 this.Prefix = "=="; 47 this.Suffix = ""; 48 } 43 public Equal() : base("Equal", "Equal comparator.") { } 49 44 50 45 public override IDeepCloneable Clone(Cloner cloner) { … … 52 47 } 53 48 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]; 56 69 } 57 70 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/GreaterThan.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 27 namespace HeuristicLab.Problems.Robocode { 27 28 [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; } } 31 32 32 33 [Storable] … … 37 38 38 39 [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) { } 43 42 44 public GreaterThan() 45 : base("GreaterThan", "GreaterThan comparator.") { 46 this.Prefix = ">"; 47 this.Suffix = ""; 48 } 43 public GreaterThan() : base("GreaterThan", "GreaterThan comparator.") { } 49 44 50 45 public override IDeepCloneable Clone(Cloner cloner) { … … 52 47 } 53 48 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]; 56 69 } 57 70 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/GreaterThanOrEqual.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 27 namespace HeuristicLab.Problems.Robocode { 27 28 [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; } } 31 32 32 33 [Storable] … … 37 38 38 39 [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) { } 43 42 44 public GreaterThanOrEqual() 45 : base("GreaterThanOrEqual", "GreaterThanOrEqual comparator.") { 46 this.Prefix = ">="; 47 this.Suffix = ""; 48 } 43 public GreaterThanOrEqual() : base("GreaterThanOrEqual", "GreaterThanOrEqual comparator.") { } 49 44 50 45 public override IDeepCloneable Clone(Cloner cloner) { … … 52 47 } 53 48 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]; 56 69 } 57 70 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/LessThan.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 27 namespace HeuristicLab.Problems.Robocode { 27 28 [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; } } 31 32 32 33 [Storable] … … 37 38 38 39 [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) { } 42 42 43 } 44 45 public LessThan() 46 : base("LessThan", "LessThan comparator.") { 47 this.Prefix = "<"; 48 this.Suffix = ""; 49 } 43 public LessThan() : base("LessThan", "LessThan comparator.") { } 50 44 51 45 public override IDeepCloneable Clone(Cloner cloner) { … … 53 47 } 54 48 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]; 57 69 } 58 70 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/LessThanOrEqual.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 27 namespace HeuristicLab.Problems.Robocode { 27 28 [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; } } 31 32 32 33 [Storable] … … 37 38 38 39 [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) { } 43 42 44 public LessThanOrEqual() 45 : base("LessThanOrEqual", "LessThanOrEqual comparator.") { 46 this.Prefix = "<="; 47 this.Suffix = ""; 48 } 43 public LessThanOrEqual() : base("LessThanOrEqual", "LessThanOrEqual comparator.") { } 49 44 50 45 public override IDeepCloneable Clone(Cloner cloner) { … … 52 47 } 53 48 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]; 56 69 } 57 70 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/LogicalExpression.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 37 38 38 39 [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) { } 43 42 44 public LogicalExpression() 45 : base("LogicalExpression", "A LogicalExpression.") { 46 this.Prefix = ""; 47 this.Suffix = ""; 48 } 43 public LogicalExpression() : base("LogicalExpression", "A logical expression.") { } 49 44 50 45 public override IDeepCloneable Clone(Cloner cloner) { … … 52 47 } 53 48 54 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {49 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 55 50 var enumerator = children.GetEnumerator(); 51 if (!enumerator.MoveNext()) throw new System.Exception("LogicalExpression was not given a child."); 56 52 57 if (!enumerator.MoveNext()) throw new System.Exception("LogicalExpression was not given a child.");58 53 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) + "."); 66 60 67 61 string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees); 68 62 if (enumerator.MoveNext()) throw new System.Exception("LogicalExpression was given more than one child."); 69 63 70 return this.Prefix + result + this.Suffix;64 return result; 71 65 } 72 66 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/LogicalValue.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 37 38 38 39 [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) { } 43 42 44 public LogicalValue() 45 : base("LogicalValue", "A LogicalValue.") { 46 this.Prefix = ""; 47 this.Suffix = ""; 48 } 43 public LogicalValue() : base("LogicalValue", "A logical value.") { } 49 44 50 45 public override ISymbolicExpressionTreeNode CreateTreeNode() { 51 52 46 return new BooleanTreeNode(); 53 47 } … … 57 51 } 58 52 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(); 61 55 } 62 56 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Negation.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 37 38 38 39 [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) { } 43 42 44 43 public Negation() 45 : base("Negation", "A Negation.") {46 this.Prefix = "!(";47 this.Suffix = ")";44 : base("Negation", "A negation.") { 45 Prefix = "!("; 46 Suffix = ")"; 48 47 } 49 48 … … 52 51 } 53 52 54 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {53 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 55 54 var enumerator = children.GetEnumerator(); 56 55 if (!enumerator.MoveNext()) throw new System.Exception("Negation was not given a child."); 57 56 58 57 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) + "."); 65 65 66 66 string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees); 67 67 if (enumerator.MoveNext()) throw new System.Exception("LogicalExpression was given more than one child."); 68 68 69 return this.Prefix + result + this.Suffix;69 return Prefix + result + Suffix; 70 70 } 71 71 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Number.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 37 38 38 39 [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) { } 43 42 44 public Number() 45 : base("Number", "A Number.") { 46 this.Prefix = ""; 47 this.Suffix = ""; 48 } 43 public Number() : base("Number", "A number.") { } 49 44 50 45 public override ISymbolicExpressionTreeNode CreateTreeNode() { 51 52 46 return new NumberTreeNode(); 53 47 } … … 57 51 } 58 52 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(); 61 55 } 62 56 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/NumberTreeNode.cs ¶
r9790 r10011 36 36 37 37 [StorableConstructor] 38 pr ivateNumberTreeNode(bool deserializing) : base(deserializing) { }39 pr ivateNumberTreeNode(NumberTreeNode original, Cloner cloner)38 protected NumberTreeNode(bool deserializing) : base(deserializing) { } 39 protected NumberTreeNode(NumberTreeNode original, Cloner cloner) 40 40 : base(original, cloner) { 41 41 this.value = original.value; 42 42 } 43 43 44 public NumberTreeNode() 45 : base(new Number()) { 46 } 44 public NumberTreeNode() : base(new Number()) { } 47 45 48 46 public override IDeepCloneable Clone(Cloner cloner) { -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Addition.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 29 namespace HeuristicLab.Problems.Robocode { 27 30 [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; } } 31 34 32 35 [Storable] … … 37 40 38 41 [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) { } 44 44 45 45 public Addition() 46 46 : base("Addition", "Addition operator.") { 47 this.Prefix = "+";48 this.Suffix = "";47 Prefix = "("; 48 Suffix = ")"; 49 49 } 50 50 … … 53 53 } 54 54 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; 57 61 } 58 62 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Division.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 29 namespace HeuristicLab.Problems.Robocode { 27 30 [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; } } 31 34 32 35 [Storable] … … 37 40 38 41 [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) { } 44 44 45 45 public Division() 46 46 : base("Division", "Division operator.") { 47 this.Prefix = "/";48 this.Suffix = "";47 Prefix = "("; 48 Suffix = ")"; 49 49 } 50 50 … … 53 53 } 54 54 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; 57 61 } 58 62 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Modulus.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 29 namespace HeuristicLab.Problems.Robocode { 27 30 [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; } } 31 34 32 35 [Storable] … … 37 40 38 41 [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) { } 44 44 45 45 public Modulus() 46 46 : base("Modulus", "Modulus operator.") { 47 this.Prefix = "%";48 this.Suffix = "";47 Prefix = "("; 48 Suffix = ")"; 49 49 } 50 50 … … 53 53 } 54 54 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; 57 61 } 58 62 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Multiplication.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 29 namespace HeuristicLab.Problems.Robocode { 27 30 [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; } } 31 34 32 35 [Storable] … … 37 40 38 41 [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) { } 44 44 45 45 public Multiplication() 46 46 : base("Multiplication", "Multiplication operator.") { 47 this.Prefix = "*";48 this.Suffix = "";47 Prefix = "("; 48 Suffix = ")"; 49 49 } 50 50 … … 53 53 } 54 54 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; 57 61 } 58 62 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Subtraction.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 29 namespace HeuristicLab.Problems.Robocode { 27 30 [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; } } 31 34 32 35 [Storable] … … 37 40 38 41 [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) { } 44 44 45 45 public Subtraction() 46 46 : base("Subtraction", "Subtraction operator.") { 47 this.Prefix = "-";48 this.Suffix = "";47 Prefix = "("; 48 Suffix = ")"; 49 49 } 50 50 … … 53 53 } 54 54 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; 57 61 } 58 62 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/NumericalExpression.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 37 38 38 39 [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) { } 43 42 44 public NumericalExpression() 45 : base("NumericalExpression", "A NumericalExpression.") { 46 this.Prefix = ""; 47 this.Suffix = ""; 48 } 43 public NumericalExpression() : base("NumericalExpression", "A numerical expression.") { } 49 44 50 45 public override IDeepCloneable Clone(Cloner cloner) { … … 52 47 } 53 48 54 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {49 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 55 50 var enumerator = children.GetEnumerator(); 51 if (!enumerator.MoveNext()) throw new System.Exception("NumericalExpression was not given a child."); 56 52 57 if (!enumerator.MoveNext()) throw new System.Exception("NumericalExpression was not given a child.");58 53 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) + "."); 65 59 66 60 string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees); 67 61 if (enumerator.MoveNext()) throw new System.Exception("NumericalExpression was given more than one child."); 68 62 69 return this.Prefix + result + this.Suffix;63 return result; 70 64 } 71 65 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/ShotPower.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 37 38 38 39 [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) { } 43 42 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.") { } 47 44 48 45 public override ISymbolicExpressionTreeNode CreateTreeNode() { … … 54 51 } 55 52 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(); 58 55 } 59 56 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/ShotPowerTreeNode.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 36 37 37 38 [StorableConstructor] 38 pr ivateShotPowerTreeNode(bool deserializing) : base(deserializing) { }39 pr ivateShotPowerTreeNode(ShotPowerTreeNode original, Cloner cloner)39 protected ShotPowerTreeNode(bool deserializing) : base(deserializing) { } 40 protected ShotPowerTreeNode(ShotPowerTreeNode original, Cloner cloner) 40 41 : base(original, cloner) { 41 42 this.value = original.value; 42 43 } 43 44 44 public ShotPowerTreeNode() 45 : base(new ShotPower()) { 46 } 45 public ShotPowerTreeNode() : base(new ShotPower()) { } 47 46 48 47 public override IDeepCloneable Clone(Cloner cloner) { … … 55 54 56 55 public override void ResetLocalParameters(IRandom random) { 57 value = (double)random.Next(1,3);56 value = Math.Max(0.1, random.NextDouble() * 3); 58 57 } 59 58 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Methods/GetEnergy.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 38 38 39 39 [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) { } 45 42 46 43 public GetEnergy() 47 44 : base("GetEnergy", "Returns the robot's current energy.") { 48 this.Prefix = "getEnergy(";49 this.Suffix = ")";45 Prefix = "getEnergy("; 46 Suffix = ")"; 50 47 } 51 48 … … 54 51 } 55 52 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; 58 55 } 59 56 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Methods/GetGunHeading.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 38 38 39 39 [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) { } 45 42 46 43 public GetGunHeading() 47 44 : 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 = ")"; 50 47 } 51 48 … … 54 51 } 55 52 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; 58 55 } 59 56 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Methods/GetHeading.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 38 38 39 39 [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) { } 45 42 46 43 public GetHeading() 47 44 : 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 = ")"; 50 47 } 51 48 … … 54 51 } 55 52 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; 58 55 } 59 56 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Methods/GetRadarHeading.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 38 38 39 39 [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) { } 44 42 45 43 public GetRadarHeading() 46 44 : 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 = ")"; 49 47 } 50 48 … … 53 51 } 54 52 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; 57 55 } 58 56 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Methods/GetX.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 38 38 39 39 [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) { } 45 42 46 43 public GetX() 47 44 : 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 = ")"; 50 47 } 51 48 … … 54 51 } 55 52 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; 58 55 } 59 56 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Methods/GetY.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 38 38 39 39 [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) { } 45 42 46 43 public GetY() 47 44 : 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 = ")"; 50 47 } 51 48 … … 54 51 } 55 52 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; 58 55 } 59 56 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Methods/INumericalMethod.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 23 24 22 namespace HeuristicLab.Problems.Robocode { 25 public interface INumericalMethod { 26 } 23 public interface INumericalMethod { } 27 24 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Program.cs ¶
r9790 r10011 32 32 33 33 [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) { } 38 36 39 37 public Program() -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Statements/ElseStat.cs ¶
r9999 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 29 namespace HeuristicLab.Problems.Robocode { 27 30 [StorableClass] 28 public class ElseStat ement: CodeNode {31 public class ElseStat : CodeNode { 29 32 public override int MinimumArity { get { return 1; } } 30 33 public override int MaximumArity { get { return 1; } } … … 37 40 38 41 [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) { } 42 44 43 } 44 45 public ElseStatement() 45 public ElseStat() 46 46 : base("ElseStatement", "An ElseStatement.") { 47 this.Prefix = "else";48 this.Suffix = "";47 Prefix = "else"; 48 Suffix = ""; 49 49 } 50 50 51 51 public override IDeepCloneable Clone(Cloner cloner) { 52 return new ElseStat ement(this, cloner);52 return new ElseStat(this, cloner); 53 53 } 54 54 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; 60 60 } 61 61 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Statements/IfStat.cs ¶
r9999 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 22 24 using HeuristicLab.Common; 23 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 28 namespace HeuristicLab.Problems.Robocode { 27 29 [StorableClass] 28 public class IfStat ement: CodeNode {30 public class IfStat : CodeNode { 29 31 public override int MinimumArity { get { return 2; } } 30 32 public override int MaximumArity { get { return 3; } } … … 37 39 38 40 [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) { } 43 43 44 public IfStat ement()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 = ")"; 48 48 } 49 49 50 50 public override IDeepCloneable Clone(Cloner cloner) { 51 return new IfStat ement(this, cloner);51 return new IfStat(this, cloner); 52 52 } 53 53 54 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {55 string condition = "", ifTrue = "", ifElse = "";56 foreach ( ISymbolicExpressionTreeNodec 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) { 57 57 if (c.Symbol is LogicalExpression) 58 58 condition = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees); 59 else if (c.Symbol is Block)59 else if (c.Symbol is Stat) 60 60 ifTrue = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees); 61 else if (c.Symbol is ElseStat ement || c.Symbol is DoNothing)61 else if (c.Symbol is ElseStat || c.Symbol is EmptyEvent || c.Symbol is DoNothing) 62 62 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"); 65 64 } 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; 68 66 } 69 67 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Statements/WhileStat.cs ¶
r9999 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 22 24 using HeuristicLab.Common; 23 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 28 namespace HeuristicLab.Problems.Robocode { 27 29 [StorableClass] 28 public class While Loop: CodeNode {30 public class WhileStat : CodeNode { 29 31 public override int MinimumArity { get { return 2; } } 30 32 public override int MaximumArity { get { return 2; } } … … 37 39 38 40 [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) { } 42 43 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 = ")"; 49 48 } 50 49 51 50 public override IDeepCloneable Clone(Cloner cloner) { 52 return new While Loop(this, cloner);51 return new WhileStat(this, cloner); 53 52 } 54 53 55 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {56 string condition = "", ifTrue = "";57 foreach ( ISymbolicExpressionTreeNodec 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) { 58 57 if (c.Symbol is LogicalExpression) 59 58 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) 61 60 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"); 64 62 } 65 return this.Prefix + " " + condition + " " + this.Suffix + 66 "\r\n" + ifTrue + "\r\n"; 63 return Prefix + condition + Suffix + Environment.NewLine + ifTrue + Environment.NewLine; 67 64 } 68 65 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Tank.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 28 30 [StorableClass] 29 31 public class Tank : CodeNode { 30 public override int MinimumArity { get { return 7; } }32 public override int MinimumArity { get { return 2; } } 31 33 public override int MaximumArity { get { return 7; } } 32 34 … … 38 40 39 41 [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) { } 44 44 45 45 public Tank() 46 46 : 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; 49 import robocode.*; 50 import robocode.Robot; 51 import robocode.util.*; 52 import static robocode.util.Utils.normalRelativeAngleDegrees; 53 import java.awt.*; 54 55 public class output extends AdvancedRobot {"; 56 Suffix = "}"; 56 57 } 57 58 … … 60 61 } 61 62 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; 67 66 } 68 67 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/Ahead.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 38 38 39 39 [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) { } 44 42 45 43 public Ahead() 46 44 : 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 = ");"; 49 47 } 50 48 … … 53 51 } 54 52 55 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {53 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 56 54 var enumerator = children.GetEnumerator(); 55 if (!enumerator.MoveNext()) throw new System.Exception("Ahead was not given a child."); 57 56 58 if (!enumerator.MoveNext()) throw new System.Exception("Ahead was not given a child.");59 57 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) + "."); 66 61 67 62 string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees); 68 63 if (enumerator.MoveNext()) throw new System.Exception("Ahead was given more than one child."); 69 64 70 return this.Prefix + result + this.Suffix;65 return Prefix + result + Suffix; 71 66 } 72 67 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/Back.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 38 38 39 39 [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) { } 43 42 44 43 public Back() 45 44 : base("Back", "Immediately moves your robot backward by distance measured in pixels.") { 46 this.Prefix = "setBack(";47 this.Suffix = ");";45 Prefix = "setBack("; 46 Suffix = ");"; 48 47 } 49 48 … … 52 51 } 53 52 54 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {53 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 55 54 var enumerator = children.GetEnumerator(); 55 if (!enumerator.MoveNext()) throw new System.Exception("Back was not given a child."); 56 56 57 if (!enumerator.MoveNext()) throw new System.Exception("Back was not given a child.");58 57 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) + "."); 65 61 66 62 string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees); 67 63 if (enumerator.MoveNext()) throw new System.Exception("Back was given more than one child."); 68 64 69 return this.Prefix + result + this.Suffix;65 return Prefix + result + Suffix; 70 66 } 71 67 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/DoNothing.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 38 38 39 39 [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) { } 44 42 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.") { } 48 44 49 45 public override IDeepCloneable Clone(Cloner cloner) { … … 51 47 } 52 48 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 ";"; 55 51 } 56 52 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/Fire.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 38 38 39 39 [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) { } 43 42 44 43 public Fire() 45 44 : base("Fire", "Immediately fires a bullet.") { 46 this.Prefix = "setFire(";47 this.Suffix = ");";45 Prefix = "setFire("; 46 Suffix = ");"; 48 47 } 49 48 … … 52 51 } 53 52 54 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {53 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 55 54 var enumerator = children.GetEnumerator(); 55 if (!enumerator.MoveNext()) throw new System.Exception("Fire was not given a child."); 56 56 57 if (!enumerator.MoveNext()) throw new System.Exception("Fire was not given a child.");58 57 var symbol = enumerator.Current.Symbol; 59 60 58 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) + "."); 63 61 64 62 string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees); 65 63 if (enumerator.MoveNext()) throw new System.Exception("Fire was given more than one child."); 66 64 67 return this.Prefix + result + this.Suffix;65 return Prefix + result + Suffix; 68 66 } 69 67 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/TurnGunLeft.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 38 38 39 39 [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) { } 44 42 45 43 public TurnGunLeft() 46 44 : 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 = ");"; 49 47 } 50 48 … … 53 51 } 54 52 55 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {53 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 56 54 var enumerator = children.GetEnumerator(); 55 if (!enumerator.MoveNext()) throw new System.Exception("TurnGunLeft was not given a child."); 57 56 58 if (!enumerator.MoveNext()) throw new System.Exception("TurnGunLeft was not given a child.");59 57 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) + "."); 66 61 67 62 string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees); 68 63 if (enumerator.MoveNext()) throw new System.Exception("TurnGunLeft was given more than one child."); 69 64 70 return this.Prefix + result + this.Suffix;65 return Prefix + result + Suffix; 71 66 } 72 67 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/TurnGunRight.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 38 38 39 39 [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) { } 45 42 46 43 public TurnGunRight() 47 44 : 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 = ");"; 50 47 } 51 48 … … 54 51 } 55 52 56 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {53 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 57 54 var enumerator = children.GetEnumerator(); 55 if (!enumerator.MoveNext()) throw new System.Exception("TurnGunRight was not given a child."); 58 56 59 if (!enumerator.MoveNext()) throw new System.Exception("TurnGunRight was not given a child.");60 57 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) + "."); 67 61 68 62 string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees); 69 63 if (enumerator.MoveNext()) throw new System.Exception("TurnGunRight was given more than one child."); 70 64 71 return this.Prefix + result + this.Suffix;65 return Prefix + result + Suffix; 72 66 } 73 67 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/TurnLeft.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 38 38 39 39 [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) { } 44 42 45 43 public TurnLeft() 46 44 : 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 = ");"; 49 47 } 50 48 … … 53 51 } 54 52 55 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {53 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 56 54 var enumerator = children.GetEnumerator(); 55 if (!enumerator.MoveNext()) throw new System.Exception("TurnLeft was not given a child."); 57 56 58 if (!enumerator.MoveNext()) throw new System.Exception("TurnLeft was not given a child.");59 57 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) + "."); 66 61 67 62 string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees); 68 63 if (enumerator.MoveNext()) throw new System.Exception("TurnLeft was given more than one child."); 69 64 70 return this.Prefix + result + this.Suffix;65 return Prefix + result + Suffix; 71 66 } 72 67 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/TurnRadarLeft.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 38 38 39 39 [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) { } 44 42 45 43 public TurnRadarLeft() 46 44 : 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 = ");"; 49 47 } 50 48 … … 53 51 } 54 52 55 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {53 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 56 54 var enumerator = children.GetEnumerator(); 55 if (!enumerator.MoveNext()) throw new System.Exception("TurnRadarLeft was not given a child."); 57 56 58 if (!enumerator.MoveNext()) throw new System.Exception("TurnRadarLeft was not given a child.");59 57 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) + "."); 66 61 67 62 string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees); 68 63 if (enumerator.MoveNext()) throw new System.Exception("TurnRadarLeft was given more than one child."); 69 64 70 return this.Prefix + result + this.Suffix;65 return Prefix + result + Suffix; 71 66 } 72 67 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/TurnRadarRight.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 38 38 39 39 [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) { } 45 42 46 43 public TurnRadarRight() 47 44 : 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 = ");"; 50 47 } 51 48 … … 54 51 } 55 52 56 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {53 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 57 54 var enumerator = children.GetEnumerator(); 55 if (!enumerator.MoveNext()) throw new System.Exception("TurnRadarRight was not given a child."); 58 56 59 if (!enumerator.MoveNext()) throw new System.Exception("TurnRadarRight was not given a child.");60 57 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) + "."); 67 61 68 62 string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees); 69 63 if (enumerator.MoveNext()) throw new System.Exception("TurnRadarRight was given more than one child."); 70 64 71 return this.Prefix + result + this.Suffix;65 return Prefix + result + Suffix; 72 66 } 73 67 } -
TabularUnified branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/TurnRight.cs ¶
r9790 r10011 20 20 #endregion 21 21 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 38 38 39 39 [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) { } 45 42 46 43 public TurnRight() 47 44 : 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 = ");"; 50 47 } 51 48 … … 54 51 } 55 52 56 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {53 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 57 54 var enumerator = children.GetEnumerator(); 55 if (!enumerator.MoveNext()) throw new System.Exception("TurnRight was not given a child."); 58 56 59 if (!enumerator.MoveNext()) throw new System.Exception("TurnRight was not given a child.");60 57 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) + "."); 67 61 68 62 string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees); 69 63 if (enumerator.MoveNext()) throw new System.Exception("TurnRight was given more than one child."); 70 64 71 return this.Prefix + result + this.Suffix;65 return Prefix + result + Suffix; 72 66 } 73 67 }
Note: See TracChangeset
for help on using the changeset viewer.