Changeset 10046 for branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Statements
- Timestamp:
- 10/17/13 12:07:20 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Statements/IfThenElseStat.cs
r10043 r10046 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 51 52 ISymbolicExpressionTreeNode condition = null, truePart = null, falsePart = null; 52 53 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]; 65 63 66 64 parts[0] = ((CodeNode)condition.Symbol).Interpret(condition, condition.Subtrees); 67 65 parts[1] = ((CodeNode)truePart.Symbol).Interpret(truePart, truePart.Subtrees); 68 if (child Count == 3) parts[2] = ((CodeNode)falsePart.Symbol).Interpret(falsePart, falsePart.Subtrees);66 if (childLst.Count == 3) parts[2] = ((CodeNode)falsePart.Symbol).Interpret(falsePart, falsePart.Subtrees); 69 67 70 68 string result = "if (" + parts[0] + ") {" + parts[1] + "}";
Note: See TracChangeset
for help on using the changeset viewer.