Free cookie consent management tool by TermsFeed Policy Generator

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

#2069:

  • refactored grammar and symbols
  • fixed cloning and storable ctors
  • fixed plugin dependencies
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/LessThan.cs

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