[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 OnScannedRobot : CodeNode
|
---|
| 9 | {
|
---|
| 10 | public override int MinimumArity { get { return 2; } }
|
---|
| 11 | public override int MaximumArity { get { return 10; } }
|
---|
| 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 OnScannedRobot(bool deserializing) : base(deserializing) { }
|
---|
| 21 | private OnScannedRobot(OnScannedRobot original, Cloner cloner)
|
---|
| 22 | : base(original, cloner)
|
---|
| 23 | {
|
---|
| 24 | this.Prefix = "\r\npublic void onScannedRobot(ScannedRobotEvent e) {" +
|
---|
| 25 | "\r\ndouble absoluteBearing = getHeading() + e.getBearing();" +
|
---|
| 26 | "\r\ndouble bearingFromGun = normalRelativeAngleDegrees(absoluteBearing - getGunHeading());" +
|
---|
| 27 | "\r\nsetTurnGunRight(bearingFromGun);\r\n";
|
---|
| 28 | this.Suffix = "\r\nexecute();\r\n}\r\n";
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | public OnScannedRobot()
|
---|
| 32 | : base("OnScannedRobot", "This method is called when your robot sees another robot, i.e. when the robot's radar scan \"hits\" another robot.")
|
---|
| 33 | {
|
---|
| 34 | this.Prefix = "\r\npublic void onScannedRobot(ScannedRobotEvent e) {" +
|
---|
| 35 | "\r\ndouble absoluteBearing = getHeading() + e.getBearing();" +
|
---|
| 36 | "\r\ndouble bearingFromGun = normalRelativeAngleDegrees(absoluteBearing - getGunHeading());" +
|
---|
| 37 | "\r\nsetTurnGunRight(bearingFromGun);\r\n";
|
---|
| 38 | this.Suffix = "\r\nexecute();\r\n}\r\n";
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | public override IDeepCloneable Clone(Cloner cloner)
|
---|
| 42 | {
|
---|
| 43 | return new OnScannedRobot(this, cloner);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children)
|
---|
| 47 | {
|
---|
| 48 | string result = "";
|
---|
| 49 | foreach (ISymbolicExpressionTreeNode c in children)
|
---|
| 50 | result += "\r\n" + ((CodeNode)c.Symbol).Interpret(c, c.Subtrees);
|
---|
| 51 | return this.Prefix + "\r\n" + result + "\r\n" + this.Suffix;
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | } |
---|