public static Turn ControlRocket(Rocket rocket, Vector target) { double targetAngle = Math.Atan2((target - rocket.Location).Y, (target - rocket.Location).X); double rocketDirectionAngle = Math.Atan2(Math.Sin(rocket.Direction), Math.Cos(rocket.Direction)); double velocityAngle = rocket.Velocity.Angle; double difBetweenTargetAndVelocity = DifferenceBetweenAngles(targetAngle, velocityAngle); double idealRocketDirectionAngle; if (Math.Abs(difBetweenTargetAndVelocity) < Math.PI / 4) { idealRocketDirectionAngle = targetAngle + difBetweenTargetAndVelocity; } else { idealRocketDirectionAngle = targetAngle + Math.PI / 8; } idealRocketDirectionAngle = Math.Atan2(Math.Sin(idealRocketDirectionAngle), Math.Cos(idealRocketDirectionAngle)); // «десь необходим угол без дополнительных кругов. double difBetweenIdealAndRealRocketDir = DifferenceBetweenAngles(idealRocketDirectionAngle, rocketDirectionAngle); return(difBetweenIdealAndRealRocketDir > 0 ? Turn.Right : difBetweenIdealAndRealRocketDir < 0 ? Turn.Left : Turn.None); }
private static Dictionary <String, Gravity> CreateLevelsDictionary(Rocket rocket, Vector target) { var levelGravity = new Dictionary <string, Gravity>(); levelGravity.Add("Zero", (size, v) => Vector.Zero); levelGravity.Add("Heavy", (size, v) => new Vector(0, 0.9)); levelGravity.Add("Up", (size, v) => new Vector(0, -300 / (size.Height - v.Y + 300.0))); levelGravity.Add("WhiteHole", (size, v) => { var toWhiteHole = v - target; return(toWhiteHole.Normalize() * 140 * toWhiteHole.Length / (toWhiteHole.Length * toWhiteHole.Length + 1)); }); levelGravity.Add("BlackHole", (size, v) => { var toBlackHole = v - (target + rocket.Location) / 2; return(toBlackHole.Normalize() * -300 * toBlackHole.Length / (toBlackHole.Length * toBlackHole.Length + 1)); }); levelGravity.Add("BlackAndWhite", (size, v) => (levelGravity["WhiteHole"](size, v) + levelGravity["BlackHole"](size, v)) / 2); return(levelGravity); }
public static Turn ControlRocket(Rocket rocket, Vector target) { var distanceVector = target - rocket.Location; double totalAngle = distanceVector.Angle - rocket.Direction; if (Math.Abs(distanceVector.Angle - rocket.Direction) < 0.5 || Math.Abs(distanceVector.Angle - rocket.Velocity.Angle) < 0.5) { totalAngle = (totalAngle + distanceVector.Angle - rocket.Velocity.Angle) / 2; } if (totalAngle > 0) { return(Turn.Right); } else if (totalAngle < 0) { return(Turn.Left); } else { return(Turn.None); } }
private static IEnumerable <Level> LevelsWithHoles() { var rocket = new Rocket(new Vector(200, 500), Vector.Zero, -0.5 * Math.PI); var target = new Vector(700, 500); var blackhole = (target + rocket.Location) * 0.5; Gravity whiteGravity = (size, v) => { var dir = target - v; var d = dir.Length; return(dir.Normalize() * -140 * d / (d * d + 1)); }; Gravity blackGravity = (size, v) => { var dir = blackhole - v; var d = dir.Length; return(dir.Normalize() * 300 * d / (d * d + 1)); }; Gravity mixedGravity = (size, v) => (whiteGravity(size, v) + blackGravity(size, v)) * 0.5; yield return(new Level("WhiteHole", rocket, target, whiteGravity, standardPhysics)); yield return(new Level("BlackHole", rocket, target, blackGravity, standardPhysics)); yield return(new Level("BlackAndWhite", rocket, target, mixedGravity, standardPhysics)); }
static IEnumerable <Level> HolesThere() { var rocket = new Rocket(new Vector(220, 520), Vector.Zero, -0.5 * Math.PI); var finishDot = new Vector(700, 500); var black = 0.5 * (finishDot + rocket.Location); Gravity blackAttr = (size, v) => { var dir = black - v; var d = dir.Length; return(d * dir.Normalize() * 300 / (1 + d * d)); }; Gravity whiteAttr = (size, v) => { var comm = finishDot - v; var c = comm.Length; return(c * comm.Normalize() * -140 / (1 + c * c)); }; Gravity summAttr = (size, v) => (blackAttr(size, v) + whiteAttr(size, v)) * 0.5; yield return(new Level("WhiteHole", rocket, finishDot, whiteAttr, standardPhysics)); yield return(new Level("BlackHole", rocket, finishDot, blackAttr, standardPhysics)); yield return(new Level("BlackAndWhite", rocket, finishDot, summAttr, standardPhysics)); }
private static Level CreateLevel(string name, Rocket rocket, Vector target, Gravity gravity) => new Level(name, rocket, target, gravity, standardPhysics);
public static Turn ControlRocket(Rocket rocket, Vector target) { return(Turn.None); }
public void Reset() { Rocket = InitialRocket; }
public void Move(Size spaceSize, Turn turn) { var force = My_ForcesTask.Sum(My_ForcesTask.GetThrustForce(1.0), My_ForcesTask.ConvertGravityToForce(Gravity, spaceSize)); Rocket = physics.MoveRocket(Rocket, force, turn, spaceSize, 0.3); }
private static bool IsTooFast(Rocket rocket) => Math.Abs(rocket.Velocity.Angle - rocket.Direction) > SpeedLimit;