using HeuristicLab.Common; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.Robocode { [StorableClass] public class WhileLoop : CodeNode { public override int MinimumArity { get { return 2; } } public override int MaximumArity { get { return 2; } } [Storable] public override string Prefix { get; set; } [Storable] public override string Suffix { get; set; } [StorableConstructor] private WhileLoop(bool deserializing) : base(deserializing) { } private WhileLoop(WhileLoop original, Cloner cloner) : base(original, cloner) { } public WhileLoop() : base("WhileLoop", "A WhileLoop.") { this.Prefix = "while("; this.Suffix = ")"; } public override IDeepCloneable Clone(Cloner cloner) { return new WhileLoop(this, cloner); } public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable children) { string condition = "", ifTrue = ""; foreach (ISymbolicExpressionTreeNode c in children) { if (c.Symbol is LogicalExpression) condition = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees); else if (c.Symbol is Block) ifTrue = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees); else throw new System.Exception("Unexpected Child node."); } return this.Prefix + " " + condition + " " + this.Suffix + "\r\n" + ifTrue + "\r\n"; } } }