Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/17/13 12:07:20 (11 years ago)
Author:
ascheibe
Message:

#2069 simplified Interpret methods of symbols

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/NumericalExpression.cs

    r10011 r10046  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
     24using System.Linq;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    4850
    4951    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    50       var enumerator = children.GetEnumerator();
    51       if (!enumerator.MoveNext()) throw new System.Exception("NumericalExpression was not given a child.");
     52      if (children.Count() != 1)
     53        throw new ArgumentException("Expected 1 child in NumericalExpression.", "children");
    5254
    53       var symbol = enumerator.Current.Symbol;
     55      var exprTree = children.Single();
     56      var symbol = exprTree.Symbol;
    5457      if (!(symbol is Number || symbol is INumericalMethod || symbol is INumericalOperator))
    5558        throw new System.Exception("NumericalExpression was given a child of type " + symbol.GetType() +
     
    5861                                           + " or " + typeof(INumericalOperator) + ".");
    5962
    60       string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    61       if (enumerator.MoveNext()) throw new System.Exception("NumericalExpression was given more than one child.");
    62 
    63       return result;
     63      return Prefix + ((CodeNode)symbol).Interpret(exprTree, exprTree.Subtrees) + Suffix;
    6464    }
    6565  }
Note: See TracChangeset for help on using the changeset viewer.