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/Void Methods/TurnGunRight.cs

    r10014 r10046  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
     24using System.Linq;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    5254
    5355    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    54       var enumerator = children.GetEnumerator();
    55       if (!enumerator.MoveNext()) throw new System.Exception("TurnGunRight was not given a child.");
     56      if (children.Count() != 1)
     57        throw new ArgumentException("Expected 1 child in TurnGunRight.", "children");
    5658
    57       var symbol = enumerator.Current.Symbol;
     59      var exprTree = children.Single();
     60      var symbol = exprTree.Symbol;
    5861      if (!(symbol is NumericalExpression))
    59         throw new System.Exception("TurnGunRight was given a child of type " + symbol.GetType() +
     62        throw new Exception("TurnGunRight was given a child of type " + symbol.GetType() +
    6063            ". The expected child must be of type " + typeof(NumericalExpression) + ".");
    6164
    62       string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    63       if (enumerator.MoveNext()) throw new System.Exception("TurnGunRight was given more than one child.");
    64 
     65      string result = ((CodeNode)symbol).Interpret(exprTree, exprTree.Subtrees);
    6566      return Prefix + result + Suffix;
    6667    }
Note: See TracChangeset for help on using the changeset viewer.