[9565] | 1 | using HeuristicLab.Common;
|
---|
| 2 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 3 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 4 |
|
---|
| 5 | namespace HeuristicLab.Problems.Robocode
|
---|
| 6 | {
|
---|
| 7 | [StorableClass]
|
---|
| 8 | public class TurnRight : CodeNode
|
---|
| 9 | {
|
---|
| 10 | public override int MinimumArity { get { return 1; } }
|
---|
| 11 | public override int MaximumArity { get { return 1; } }
|
---|
| 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 TurnRight(bool deserializing) : base(deserializing) { }
|
---|
| 21 | private TurnRight(TurnRight original, Cloner cloner)
|
---|
| 22 | : base(original, cloner)
|
---|
| 23 | {
|
---|
| 24 | this.Prefix = "setTurnRight(";
|
---|
| 25 | this.Suffix = ");";
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | public TurnRight()
|
---|
| 29 | : base("TurnRight", "Immediately turns the robot's body to the right by degrees.")
|
---|
| 30 | {
|
---|
| 31 | this.Prefix = "setTurnRight(";
|
---|
| 32 | this.Suffix = ");";
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | public override IDeepCloneable Clone(Cloner cloner)
|
---|
| 36 | {
|
---|
| 37 | return new TurnRight(this, cloner);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children)
|
---|
| 41 | {
|
---|
| 42 | var enumerator = children.GetEnumerator();
|
---|
| 43 |
|
---|
| 44 | if (!enumerator.MoveNext()) throw new System.Exception("TurnRight was not given a child.");
|
---|
| 45 | var symbol = enumerator.Current.Symbol;
|
---|
| 46 |
|
---|
| 47 | if (!(symbol is Number || symbol is NumericalOperation || symbol is NumericalExpression))
|
---|
| 48 | throw new System.Exception("TurnRight was given a child of type " + symbol.GetType().ToString() +
|
---|
| 49 | ". The expected child must be of type " + typeof(Number).ToString() + " or " +
|
---|
| 50 | typeof(NumericalOperation).ToString() + " or " +
|
---|
| 51 | typeof(NumericalExpression).ToString() + ".");
|
---|
| 52 |
|
---|
| 53 | string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
|
---|
| 54 | if (enumerator.MoveNext()) throw new System.Exception("TurnRight was given more than one child.");
|
---|
| 55 |
|
---|
| 56 | return this.Prefix + result + this.Suffix;
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 | } |
---|