Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Robocode/HeuristicLab.Problems.Robocode/Symbols/Branches/WhileLoop.cs @ 9565

Last change on this file since 9565 was 9565, checked in by melkaref, 11 years ago

Robocode Plugin code without Mutation Operators

File size: 1.9 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
3using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
4
5namespace HeuristicLab.Problems.Robocode
6{
7    [StorableClass]
8    public class WhileLoop : CodeNode
9    {
10        public override int MinimumArity { get { return 2; } }
11        public override int MaximumArity { get { return 2; } }
12
13        [Storable]
14        public override string Prefix { get; set; }
15
16        [Storable]
17        public override string Suffix { get; set; }
18
19        [StorableConstructor]
20        private WhileLoop(bool deserializing) : base(deserializing) { }
21        private WhileLoop(WhileLoop original, Cloner cloner)
22            : base(original, cloner)
23        {
24            this.Prefix = "while(";
25            this.Suffix = ")";
26        }
27
28        public WhileLoop()
29            : base("WhileLoop", "A WhileLoop.")
30        {
31            this.Prefix = "while(";
32            this.Suffix = ")";
33        }
34
35        public override IDeepCloneable Clone(Cloner cloner)
36        {
37            return new WhileLoop(this, cloner);
38        }
39
40        public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children)
41        {
42            string condition = "", ifTrue = "";
43            foreach (ISymbolicExpressionTreeNode c in children)
44            {
45                if (c.Symbol is LogicalExpression)
46                    condition = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
47                else if (c.Symbol is Block)
48                    ifTrue = ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
49                else
50                    throw new System.Exception("Unexpected Child node.");
51            }
52            return this.Prefix + " " + condition + " " + this.Suffix +
53                "\r\n" + ifTrue + "\r\n";
54        }
55    }
56}
Note: See TracBrowser for help on using the repository browser.