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

Location:
branches/Robocode.TrunkInt
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode.Views/3.3/BattleRunnerDialog.cs

    r9985 r10046  
    1 using System.IO;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System.IO;
    223using System.Windows.Forms;
    324using HeuristicLab.Common;
     
    4061      if (string.IsNullOrEmpty(robocodePath)) {
    4162        e.Cancel = true;
    42         errorProvider.SetError(robocodePathTextBox, "Robocode Directory has to be set");
     63        errorProvider.SetError(robocodePathTextBox, "Robocode directory has to be set");
    4364        robocodePathTextBox.SelectAll();
    4465        return;
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Grammar.cs

    r10043 r10046  
    5959      var ifThenElseStat = new IfThenElseStat();
    6060      var whileStat = new WhileStat();
     61      whileStat.Enabled = false;
    6162
    6263      var logicalExpr = new LogicalExpression();
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Disjunction.cs

    r10011 r10046  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    5354
    5455    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     56      if (children.Count() < 2)
     57        throw new ArgumentException("Expected at leaset 2 children.", "children");
     58
    5559      string result = string.Join(" || ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
    5660      return Prefix + result + Suffix;
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/Equal.cs

    r10011 r10046  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
     24using System.Linq;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    4951    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5052      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.");
     53      if (children.Count() != 2)
     54        throw new Exception("Unexpected number of children. Expected 2 children.");
     55
     56      lhs = children.First();
     57      rhs = children.Last();
    6258
    6359      var result = new[] {
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/GreaterThan.cs

    r10011 r10046  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
     24using System.Linq;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    4951    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5052      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.");
     53      if (children.Count() != 2)
     54        throw new Exception("Unexpected number of children. Expected 2 children.");
     55
     56      lhs = children.First();
     57      rhs = children.Last();
    6258
    6359      var result = new[] {
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/GreaterThanOrEqual.cs

    r10011 r10046  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
     24using System.Linq;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    4951    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5052      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.");
     53      if (children.Count() != 2)
     54        throw new Exception("Unexpected number of children. Expected 2 children.");
     55
     56      lhs = children.First();
     57      rhs = children.Last();
    6258
    6359      var result = new[] {
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/LessThan.cs

    r10011 r10046  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
     24using System.Linq;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    4951    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5052      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.");
     53      if (children.Count() != 2)
     54        throw new Exception("Unexpected number of children. Expected 2 children.");
     55
     56      lhs = children.First();
     57      rhs = children.Last();
    6258
    6359      var result = new[] {
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/LessThanOrEqual.cs

    r10011 r10046  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
     24using System.Linq;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    4951    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    5052      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.");
     53      if (children.Count() != 2)
     54        throw new Exception("Unexpected number of children. Expected 2 children.");
     55
     56      lhs = children.First();
     57      rhs = children.Last();
    6258
    6359      var result = new[] {
  • 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  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/LogicalValue.cs

    r10011 r10046  
    5252
    5353    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
    54       return ((BooleanTreeNode)node).Value.ToString().ToLower();
     54      return Prefix + ((BooleanTreeNode)node).Value.ToString().ToLower() + Suffix;
    5555    }
    5656  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Negation.cs

    r10011 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("Negation was not given a child.");
     56      if (children.Count() != 1)
     57        throw new ArgumentException("Expected 1 child in Negation.", "children");
    5658
    57       var symbol = enumerator.Current.Symbol;
     59      var exprTree = children.Single();
     60      var symbol = exprTree.Symbol;
    5861      if (!(symbol is LogicalValue || symbol is Conjunction || symbol is Disjunction || symbol is Negation || symbol is ILogicalComparator))
    5962        throw new System.Exception("Negation was given a child of type " + symbol.GetType() +
     
    6467                                           + " or " + typeof(ILogicalComparator) + ".");
    6568
    66       string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    67       if (enumerator.MoveNext()) throw new System.Exception("LogicalExpression was given more than one child.");
    68 
    69       return Prefix + result + Suffix;
     69      return Prefix + ((CodeNode)symbol).Interpret(exprTree, exprTree.Subtrees) + Suffix;
    7070    }
    7171  }
  • 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  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Statements/IfThenElseStat.cs

    r10043 r10046  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    5152      ISymbolicExpressionTreeNode condition = null, truePart = null, falsePart = null;
    5253      string[] parts = new string[3];
    53       var enumerator = children.GetEnumerator();
    54       int childCount = 0;
    55       while (enumerator.MoveNext()) {
    56         childCount++;
    57         switch (childCount) {
    58           case 1: condition = enumerator.Current; break;
    59           case 2: truePart = enumerator.Current; break;
    60           case 3: falsePart = enumerator.Current; break;
    61           default: throw new ArgumentException("Unexpected number of children. Expected a maximum of 3 children.");
    62         }
    63       }
    64       if (childCount < 2) throw new ArgumentException("Unexpected number of children. Expected at least 2 children.");
     54
     55      if (children.Count() < 2 || children.Count() > 3)
     56        throw new Exception("Unexpected number of children. Expected 2 or 3 children.");
     57
     58      var childLst = children.ToList();
     59      condition = childLst[0];
     60      truePart = childLst[1];
     61      if (childLst.Count == 3)
     62        falsePart = childLst[2];
    6563
    6664      parts[0] = ((CodeNode)condition.Symbol).Interpret(condition, condition.Subtrees);
    6765      parts[1] = ((CodeNode)truePart.Symbol).Interpret(truePart, truePart.Subtrees);
    68       if (childCount == 3) parts[2] = ((CodeNode)falsePart.Symbol).Interpret(falsePart, falsePart.Subtrees);
     66      if (childLst.Count == 3) parts[2] = ((CodeNode)falsePart.Symbol).Interpret(falsePart, falsePart.Subtrees);
    6967
    7068      string result = "if (" + parts[0] + ") {" + parts[1] + "}";
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/Ahead.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("Ahead was not given a child.");
     56      if (children.Count() != 1)
     57        throw new ArgumentException("Expected 1 child in Ahead.", "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("Ahead was given a child of type " + symbol.GetType() +
     62        throw new Exception("Ahead 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("Ahead was given more than one child.");
    64 
     65      string result = ((CodeNode)symbol).Interpret(exprTree, exprTree.Subtrees);
    6566      return Prefix + result + Suffix;
    6667    }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/Back.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("Back was not given a child.");
     56      if (children.Count() != 1)
     57        throw new ArgumentException("Expected 1 child in Back.", "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("Back was given a child of type " + symbol.GetType() +
     62        throw new Exception("Back 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("Back was given more than one child.");
    64 
     65      string result = ((CodeNode)symbol).Interpret(exprTree, exprTree.Subtrees);
    6566      return Prefix + result + Suffix;
    6667    }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/Fire.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("Fire was not given a child.");
     56      if (children.Count() != 1)
     57        throw new ArgumentException("Expected 1 child in Fire.", "children");
    5658
    57       var symbol = enumerator.Current.Symbol;
     59      var exprTree = children.Single();
     60      var symbol = exprTree.Symbol;
    5861      if (!(symbol is ShotPower))
    59         throw new System.Exception("Fire was given a child of type " + symbol.GetType() +
     62        throw new Exception("Fire was given a child of type " + symbol.GetType() +
    6063            ". The expected child must be of type " + typeof(ShotPower) + ".");
    6164
    62       string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    63       if (enumerator.MoveNext()) throw new System.Exception("Fire was given more than one child.");
    64 
     65      string result = ((CodeNode)symbol).Interpret(exprTree, exprTree.Subtrees);
    6566      return Prefix + result + Suffix;
    6667    }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/TurnGunLeft.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("TurnGunLeft was not given a child.");
     56      if (children.Count() != 1)
     57        throw new ArgumentException("Expected 1 child in TurnGunLeft.", "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("TurnGunLeft was given a child of type " + symbol.GetType() +
     62        throw new Exception("TurnGunLeft 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("TurnGunLeft was given more than one child.");
    64 
     65      string result = ((CodeNode)symbol).Interpret(exprTree, exprTree.Subtrees);
    6566      return Prefix + result + Suffix;
    6667    }
  • 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    }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/TurnLeft.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("TurnLeft was not given a child.");
     56      if (children.Count() != 1)
     57        throw new ArgumentException("Expected 1 child in TurnLeft.", "children");
    5658
    57       var symbol = enumerator.Current.Symbol;
     59      var exprTree = children.Single();
     60      var symbol = exprTree.Symbol;
    5861      if (!(symbol is NumericalExpression))
    5962        throw new System.Exception("TurnLeft 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("TurnLeft was given more than one child.");
    64 
     65      string result = ((CodeNode)symbol).Interpret(exprTree, exprTree.Subtrees);
    6566      return Prefix + result + Suffix;
    6667    }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/TurnRadarLeft.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("TurnRadarLeft was not given a child.");
     56      if (children.Count() != 1)
     57        throw new ArgumentException("Expected 1 child in TurnRadarLeft.", "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("TurnRadarLeft was given a child of type " + symbol.GetType() +
     62        throw new Exception("TurnRadarLeft 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("TurnRadarLeft was given more than one child.");
    64 
     65      string result = ((CodeNode)symbol).Interpret(exprTree, exprTree.Subtrees);
    6566      return Prefix + result + Suffix;
    6667    }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/TurnRadarRight.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("TurnRadarRight was not given a child.");
     56      if (children.Count() != 1)
     57        throw new ArgumentException("Expected 1 child in TurnRadarRight.", "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("TurnRadarRight was given a child of type " + symbol.GetType() +
     62        throw new Exception("TurnRadarRight 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("TurnRadarRight was given more than one child.");
    64 
     65      string result = ((CodeNode)symbol).Interpret(exprTree, exprTree.Subtrees);
    6566      return Prefix + result + Suffix;
    6667    }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Void Methods/TurnRight.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("TurnRight was not given a child.");
     56      if (children.Count() != 1)
     57        throw new ArgumentException("Expected 1 child in TurnRight.", "children");
    5658
    57       var symbol = enumerator.Current.Symbol;
     59      var exprTree = children.Single();
     60      var symbol = exprTree.Symbol;
    5861      if (!(symbol is NumericalExpression))
    5962        throw new System.Exception("TurnRight 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("TurnRight 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.