Changeset 10011 for branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/LessThan.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/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 }
Note: See TracChangeset
for help on using the changeset viewer.