using HeuristicLab.Common; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.Robocode { [StorableClass] public class TurnRadarLeft : CodeNode { public override int MinimumArity { get { return 1; } } public override int MaximumArity { get { return 1; } } [Storable] public override string Prefix { get; set; } [Storable] public override string Suffix { get; set; } [StorableConstructor] private TurnRadarLeft(bool deserializing) : base(deserializing) { } private TurnRadarLeft(TurnRadarLeft original, Cloner cloner) : base(original, cloner) { this.Prefix = "setTurnRadarLeft("; this.Suffix = ");"; } public TurnRadarLeft() : base("TurnRadarLeft", "Immediately turns the robot's radar to the left by degrees.") { this.Prefix = "setTurnRadarLeft("; this.Suffix = ");"; } public override IDeepCloneable Clone(Cloner cloner) { return new TurnRadarLeft(this, cloner); } public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable children) { var enumerator = children.GetEnumerator(); if (!enumerator.MoveNext()) throw new System.Exception("TurnRadarLeft was not given a child."); var symbol = enumerator.Current.Symbol; if (!(symbol is Number || symbol is NumericalOperation || symbol is NumericalExpression)) throw new System.Exception("TurnRadarLeft was given a child of type " + symbol.GetType().ToString() + ". The expected child must be of type " + typeof(Number).ToString() + " or " + typeof(NumericalOperation).ToString() + " or " + typeof(NumericalExpression).ToString() + "."); string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees); if (enumerator.MoveNext()) throw new System.Exception("TurnRadarLeft was given more than one child."); return this.Prefix + result + this.Suffix; } } }