public void DistanceBetweenTwoPointShouldReturnExpectedDistance() { Assert.AreEqual(6, EuclidianTools.DistanceBetweenTwoPoint(B, E)); Assert.AreEqual(6, EuclidianTools.DistanceBetweenTwoPoint(E, B)); Assert.AreEqual(12.083045973594572d, EuclidianTools.DistanceBetweenTwoPoint(E, D)); Assert.AreEqual(17.088007490635061d, EuclidianTools.DistanceBetweenTwoPoint(A, C)); }
private static bool DoINeedActivateShield(EuclidianVector speedVector, Point currentPosition, Point opPosition, Point nextCheckPoint) { if (speedVector == null) { return(false); } var distanceToOp = EuclidianTools.DistanceBetweenTwoPoint(currentPosition, opPosition); var OpDirection = new EuclidianVector(opPosition, nextCheckPoint); var MyDirectiobn = new EuclidianVector(currentPosition, nextCheckPoint); var angleBetweenMeAndOp = (MyDirectiobn.AngleInDegreeWith(OpDirection)) % 360; return(false);// (distanceToOp < 810 ); }
static void Main(string[] args) { string[] inputs; bool isBoostUsed = false; Point lastPoint = new Point(); Point lastTarget = new Point(); EuclidianVector speedVector = null; Point myTarget = new Point(); bool firstRound = true; Dictionary <Point, Point> Targets = new Dictionary <Point, Point>(); // game loop while (true) { inputs = Console.ReadLine().Split(' '); int x = int.Parse(inputs[0]); int y = int.Parse(inputs[1]); int nextCheckpointX = int.Parse(inputs[2]); // x position of the next check point int nextCheckpointY = int.Parse(inputs[3]); // y position of the next check point int nextCheckpointDist = int.Parse(inputs[4]); // distance to the next checkpoint int nextCheckpointAngle = int.Parse(inputs[5]); // angle between your pod orientation and the direction of the next checkpoint inputs = Console.ReadLine().Split(' '); int opponentX = int.Parse(inputs[0]); int opponentY = int.Parse(inputs[1]); // Write an action using Console.WriteLine() // To debug: Console.Error.WriteLine("Debug messages..."); var nextCheckPoint = new Point(nextCheckpointX, nextCheckpointY); if (firstRound && !lastTarget.IsEmpty && lastTarget != nextCheckPoint) { if (!Targets.ContainsKey(lastTarget)) { Targets.Add(lastTarget, nextCheckPoint); } else { firstRound = false; } } var opPosition = new Point(opponentX, opponentY); var currentPosition = new Point(x, y); if (!lastPoint.IsEmpty) { speedVector = new EuclidianVector(lastPoint, currentPosition); var angleBetweenSpeedAndDirection = (speedVector.AngleInDegreeWith(new EuclidianVector(currentPosition, nextCheckPoint))) % 360; if (!isBoostUsed && nextCheckpointDist > 5000 && (nextCheckpointAngle < 5 && nextCheckpointAngle > -5)) { Console.Error.WriteLine("Angle when Boost: " + nextCheckpointAngle); Console.WriteLine(nextCheckpointX + " " + nextCheckpointY + " BOOST"); isBoostUsed = true; lastPoint = new Point(x, y); continue; } } var thrust = 100.0d; var target = CalcIdealTarget(nextCheckpointAngle, nextCheckPoint, currentPosition, nextCheckpointDist, speedVector, Targets, firstRound); var posTNextCheckPoint = new EuclidianVector(currentPosition, nextCheckPoint); var posToIdealTarget = new EuclidianVector(currentPosition, target); var IdealTargetAngle = target.Equals(nextCheckPoint) ? nextCheckpointAngle : posToIdealTarget.AngleInDegreeWith(posTNextCheckPoint) - nextCheckpointAngle; thrust = CalculatePerfectThrust(currentPosition, nextCheckpointAngle, nextCheckPoint, nextCheckpointDist, speedVector); var distOponant = EuclidianTools.DistanceBetweenTwoPoint(currentPosition, opPosition); if (DoINeedActivateShield(speedVector, currentPosition, opPosition, nextCheckPoint)) { Console.WriteLine(nextCheckpointX + " " + nextCheckpointY + " SHIELD"); continue; } Console.WriteLine(target.X + " " + target.Y + " " + (int)thrust); lastPoint = new Point(x, y); lastTarget = nextCheckPoint; // You have to output the target position // followed by the power (0 <= thrust <= 100) // i.e.: "x y thrust" } }