Changeset 10011 for branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/NumericalExpression.cs
- Timestamp:
- 10/01/13 12:08:25 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.