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/Logical Expressions/LogicalExpression.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("LogicalExpression was not given a child.");
     52      if (children.Count() != 1)
     53        throw new ArgumentException("Expected 1 child in LogicalExpression.", "children");
    5254
    53       var symbol = enumerator.Current.Symbol;
     55      var exprTree = children.Single();
     56      var symbol = exprTree.Symbol;
    5457      if (!(symbol is LogicalValue || symbol is Conjunction || symbol is Disjunction || symbol is Negation))
    5558        throw new System.Exception("LogicalExpression was given a child of type " + symbol.GetType() +
     
    5962                                           + " or " + typeof(Negation) + ".");
    6063
    61       string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    62       if (enumerator.MoveNext()) throw new System.Exception("LogicalExpression was given more than one child.");
    63 
    64       return result;
     64      return Prefix + ((CodeNode)symbol).Interpret(exprTree, exprTree.Subtrees) + Suffix;
    6565    }
    6666  }
Note: See TracChangeset for help on using the changeset viewer.