Changeset 10011 for branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Statements/WhileStat.cs
- Timestamp:
- 10/01/13 12:08:25 (11 years ago)
- Location:
- branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Statements
- Files:
-
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Statements/WhileStat.cs
r9999 r10011 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 22 24 using HeuristicLab.Common; 23 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 28 namespace HeuristicLab.Problems.Robocode { 27 29 [StorableClass] 28 public class While Loop: CodeNode {30 public class WhileStat : CodeNode { 29 31 public override int MinimumArity { get { return 2; } } 30 32 public override int MaximumArity { get { return 2; } } … … 37 39 38 40 [StorableConstructor] 39 private WhileLoop(bool deserializing) : base(deserializing) { } 40 private WhileLoop(WhileLoop original, Cloner cloner) 41 : base(original, cloner) { 41 protected WhileStat(bool deserializing) : base(deserializing) { } 42 protected WhileStat(WhileStat original, Cloner cloner) : base(original, cloner) { } 42 43 43 } 44 45 public WhileLoop() 46 : base("WhileLoop", "A WhileLoop.") { 47 this.Prefix = "while("; 48 this.Suffix = ")"; 44 public WhileStat() 45 : base("WhileStat", "A while statement.") { 46 Prefix = "while ("; 47 Suffix = ")"; 49 48 } 50 49 51 50 public override IDeepCloneable Clone(Cloner cloner) { 52 return new While Loop(this, cloner);51 return new WhileStat(this, cloner); 53 52 } 54 53 55 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {56 string condition = "", ifTrue = "";57 foreach ( ISymbolicExpressionTreeNodec in children) {54 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 55 string condition = string.Empty, ifTrue = string.Empty; 56 foreach (var c in children) { 58 57 if (c.Symbol is LogicalExpression) 59 58 condition = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees); 60 else if (c.Symbol is Block)59 else if (c.Symbol is Stat || c.Symbol is EmptyEvent || c.Symbol is DoNothing) 61 60 ifTrue = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees); 62 else 63 throw new System.Exception("Unexpected Child node."); 61 else throw new ArgumentException("Unexpected children.", "children"); 64 62 } 65 return this.Prefix + " " + condition + " " + this.Suffix + 66 "\r\n" + ifTrue + "\r\n"; 63 return Prefix + condition + Suffix + Environment.NewLine + ifTrue + Environment.NewLine; 67 64 } 68 65 }
Note: See TracChangeset
for help on using the changeset viewer.