예제 #1
0
    static void Main(string[] args)
    {
        string[] inputs;
        bool     thrustUsed = false;
        // game loop
        var        checkPoints         = new List <CheckPoint>();
        var        allCheckPointsFound = false;
        var        currentId           = 0;
        var        numberOfCheckPoints = 0;
        CheckPoint nextCheckPoint      = null;
        CheckPoint nextNextCheckPoint  = null;
        var        turn      = 0;
        var        gameBoard = new Point()
        {
            X = 16000, Y = 9000
        };
        var topLeft = new Point()
        {
            X = 0, Y = 0
        };

        double xToGo = 0;
        double yToGo = 0;

        var checkPointRadius = 600;
        var MaxTimeout       = 100;
        var MaxThrust        = 100;

        var timeout = MaxTimeout;

        Pod myLastPod = null;

        var isDecelerate     = false;
        var isStillOrienting = false;

        var stillOrientingThrust = 60;                                                                       //70;                                          //10
        var currentCheckPointLargeAngleThrust      = Math.Floor((double)(MaxThrust / 1.5));                  //20
        var podDriftingFromCurrentCheckPointThrust = 80;                                                     //30
        var nextCheckPointLargeAngleAsApproachCurrentCheckPointThrust = Math.Floor((double)(MaxThrust / 3)); //60
        var approachingCurrentCheckPointThrust = 85;                                                         //70
        var maxProportionalApproachThrust      = 20;                                                         //80

        var isShortCircuitMidpointOnBigAngle = false;
        var isMadKnightTrick          = false;
        var isAdjustForNextCheckpoint = false;
        var isOverrideBasedOnAngle    = true;

        while (true)
        {
            var    pods     = new List <Pod>();
            var    lastPods = new List <Pod>();
            string thrust;

            turn++;

            for (var i = 0; i < 4; i++)
            {
                inputs = Console.ReadLine().Split(' ');
                double x  = double.Parse(inputs[0]);
                double y  = double.Parse(inputs[1]);
                double vx = double.Parse(inputs[2]);               // x position of the next check point
                double vy = double.Parse(inputs[3]);               // y position of the next check point
                int    nextCheckpointAngle = int.Parse(inputs[4]); // angle between your pod orientation and the direction of the next checkpoint
                int    nextCheckPointId    = int.Parse(inputs[5]); // distance to the next checkpoint

                pods.Add(new Pod()
                {
                    Id = i, X = x, Y = y, Vx = vx, Vy = vy, Angle = angle, NextCheckPointId = nextCheckPointId
                });
            }

            /*
             * var otherPod = new Pod() { Id = 1, X = opponentX, Y = opponentY };
             *
             * inputs = Console.ReadLine().Split(' ');
             * int opponentX = int.Parse(inputs[0]);
             * int opponentY = int.Parse(inputs[1]);
             */
            double velocity  = 0;
            double velocityX = 0;
            double velocityY = 0;

            var point = new Point()
            {
                X = xToGo, Y = yToGo
            };
            var pointNextCheckpoint = new Unit()
            {
                X = nextCheckpointX, Y = nextCheckpointY
            };

            var myPod = new Pod()
            {
                Id = 0, X = x, Y = y
            };
            var otherPod = new Pod()
            {
                Id = 1, X = opponentX, Y = opponentY
            };
            //var myPod = new Pod() { Id = 0, X = x, Y = y, Vector = new Vector(x, y) };
            //var otherPod = new Pod() { Id = 1, X = opponentX, Y = opponentY, Vector = new Vector(opponentX, opponentY) };

            myPod.Angle             = myPod.GetAngle(point);
            myPod.AngleToCheckPoint = nextCheckpointAngle;

            if (myLastPod != null)
            {
                velocity  = myPod.Distance(myLastPod);
                velocityX = myPod.X - myLastPod.X;
                velocityY = myPod.Y - myLastPod.Y;

                myPod.Vx = velocityX;
                myPod.Vy = velocityY;
            }

            pods.Add(myPod);
            pods.Add(otherPod);

            var checkPoint = new CheckPoint()
            {
                X = nextCheckpointX, Y = nextCheckpointY
            };
            var isSameCheckPoint = checkPoint.IsEqual(nextCheckPoint);

            timeout--;
            double angleToPoint     = 0;
            double angleToNextPoint = 0;

            if (!isSameCheckPoint)
            {
                timeout = MaxTimeout;

                nextCheckPoint = checkPoints.FirstOrDefault(cp => cp.X == nextCheckpointX && cp.Y == nextCheckpointY);

                nextNextCheckPoint = null;

                if (nextCheckPoint != null)
                {
                    allCheckPointsFound = true;
                    nextCheckPoint.TimesVisited++;
                    currentId          = nextCheckPoint.Id;
                    nextNextCheckPoint = checkPoints.FirstOrDefault(cp => cp.Id == (currentId == numberOfCheckPoints - 1 ? 0 : currentId + 1));

                    Console.Error.WriteLine(nextCheckPoint.ToString());
                    Console.Error.WriteLine(nextNextCheckPoint == null ? "No Next Next Checkpoint Yet" : nextNextCheckPoint.ToString());
                }
                else
                {
                    nextCheckPoint = new CheckPoint()
                    {
                        Id = currentId++, X = nextCheckpointX, Y = nextCheckpointY, TimesVisited = 1
                    };
                    checkPoints.Add(nextCheckPoint);
                    numberOfCheckPoints++;
                }

                if (numberOfCheckPoints > 1 && isShortCircuitMidpointOnBigAngle)
                {
                    isStillOrienting = true;
                }
            }

            if (isStillOrienting && (nextCheckpointAngle > 10 || nextCheckpointAngle < -10))
            {
                //var midPointOfNextCheckPoint = new Point() { X = Math.Abs(nextCheckpointX + myPod.X ) / 2, Y = Math.Abs(nextCheckpointY + myPod.Y) / 2 };
                var midPointOfNextCheckPoint = nextCheckPoint.GetMidpoint(myPod);
                xToGo = Math.Floor(midPointOfNextCheckPoint.X);
                yToGo = Math.Floor(midPointOfNextCheckPoint.Y);
                //thrust = "70";
                thrust = stillOrientingThrust.ToString();

                Console.Error.WriteLine("Printing from 10");
                Console.Error.WriteLine(string.Format("{0} degrees and {1} units from next Checkpoint.", nextCheckpointAngle, nextCheckpointDist));

                Console.WriteLine(string.Format("{0} {1} {2} Big Angle, still orienting!!!", xToGo, yToGo, thrust));
                continue;
            }
            else
            {
                isStillOrienting = false;
            }

            if (nextNextCheckPoint != null)
            {
                angleToPoint = myPod.GetAngleToPoint(nextCheckPoint, myLastPod);
                //angleToNextPoint = myPod.GetAngle(nextNextCheckPoint);
                //angleToNextPoint = myPod.GetAngleFromPoints(nextCheckPoint, nextNextCheckPoint);
                angleToNextPoint = myPod.CalculateAngleFromPoints(nextCheckPoint, nextNextCheckPoint);

                if (isAdjustForNextCheckpoint)
                {
                    //Adjust the target, to go to the side of the current checkpoint that is opposite of the next checkpoint.
                    var newTargetPoint = myPod.AdjustedCoordinates(nextNextCheckPoint, pointNextCheckpoint);
                    pointNextCheckpoint.X = newTargetPoint.X;
                    pointNextCheckpoint.Y = newTargetPoint.Y;
                }

                Console.Error.WriteLine(string.Format("{0} degrees and {1} units from current Checkpoint.", angleToPoint, myPod.Distance(nextCheckPoint)));
                Console.Error.WriteLine(string.Format("{0} degrees and {1} units from next Checkpoint.", angleToNextPoint, myPod.Distance(nextNextCheckPoint)));
            }
            else
            {
                var midPoint = topLeft.GetMidpoint(gameBoard);
                angleToNextPoint = myPod.CalculateAngleFromPoints(nextCheckPoint, midPoint);
                Console.Error.WriteLine(string.Format("{0} degrees from current Checkpoint, and Next CheckPoint Unknown.", myPod.Angle));
                Console.Error.WriteLine(string.Format("{0} degrees and {1} units from next Checkpoint (approxmiated Midpoint).", angleToNextPoint, myPod.Distance(midPoint)));
            }

            xToGo = pointNextCheckpoint.X;
            yToGo = pointNextCheckpoint.Y;
            var checkPointsVisitedThreeTimes = checkPoints.Count(cp => cp.TimesVisited == 3);
            var checkPointsCount             = checkPoints.Count();
            var isFinalCheckPoint            = checkPointsVisitedThreeTimes == checkPointsCount;

            Console.Error.WriteLine(string.Format("{0} out of {1} CheckPoints have been Visited 3 Times.", checkPointsVisitedThreeTimes, checkPointsCount));

            if (isFinalCheckPoint)
            {
                Console.Error.WriteLine(string.Format("Last Checkpoint.  Balls to the Wall!!!!!"));
            }

            if (nextCheckpointAngle > 60 || nextCheckpointAngle < -60)
            {
                //thrust = (MaxThrust/3).ToString();
                thrust = currentCheckPointLargeAngleThrust.ToString();
                Console.Error.WriteLine("Printing from 20");
                //} else if (myLastPod != null && Math.Abs(myPod.AngleToCheckPoint) > Math.Abs(myLastPod.AngleToCheckPoint))
                //{
                //thrust = "80";
                //    thrust = podDriftingFromCurrentCheckPointThrust.ToString();
                //    Console.Error.WriteLine("Printing from 30");
            }
            else if (isFinalCheckPoint || nextCheckpointDist >= myPod.TurningRadius)
            {
                thrust = MaxThrust.ToString();
                Console.Error.WriteLine("Printing from 40");
            }
            else if (nextCheckpointDist < myPod.TurningRadius && nextCheckpointAngle == 0)
            {
                thrust = MaxThrust.ToString();
                Console.Error.WriteLine("Printing from 50");
                //} //else if ( nextNextCheckPoint != null && nextCheckpointDist < myPod.TurningRadius && angleToNextPoint != 0 && ((angleToNextPoint >= 170 && angleToNextPoint <= 180)|| (angleToNextPoint <= -170 && angleToNextPoint >= -180 )))
                //{
                //    thrust = MaxThrust.ToString();
                //    xToGo = nextNextCheckPoint.X;
                //    yToGo = nextNextCheckPoint.Y;

/*
 *          } else if ( nextCheckpointDist < myPod.TurningRadius
 *                      && angleToNextPoint != 0
 *                      && (
 *                          (angleToNextPoint > 60 && angleToNextPoint < 120)
 || (angleToNextPoint < -60 && angleToNextPoint > -120 )
 || (angleToNextPoint < 15 && angleToNextPoint > -15 && nextNextCheckPoint != null && myPod.IsBehind(nextNextCheckPoint))
 ||                   ))
 ||         {
 ||             Console.Error.WriteLine("Printing from 60");
 ||
 ||             if (nextNextCheckPoint != null)
 ||             {
 ||                 var midPointOfCheckpoints = nextNextCheckPoint.GetMidpoint(nextCheckPoint);
 ||                 xToGo = Math.Floor(midPointOfCheckpoints.X);
 ||                 yToGo = Math.Floor(midPointOfCheckpoints.Y);
 ||             }
 ||             //thrust = (MaxThrust / 6).ToString();
 ||             thrust = nextCheckPointLargeAngleAsApproachCurrentCheckPointThrust.ToString();
 */
            }
            else if (nextCheckpointDist < myPod.TurningRadius && nextCheckpointAngle < 5)
            {
                Console.Error.WriteLine("Printing from 70");

                //thrust = (MaxThrust / 2).ToString();
                //thrust = "70";
                thrust = approachingCurrentCheckPointThrust.ToString();
            }
            else
            {
                var proportionalThrust = (nextCheckpointDist / myPod.TurningRadius) * 100.0 * .2;
                var roundedThrust      = Math.Round(proportionalThrust, 0);
                thrust = Math.Max(roundedThrust, maxProportionalApproachThrust).ToString();

                Console.Error.WriteLine("Printing from 80");
                Console.Error.WriteLine(string.Format("Proportional Thust: {0}, Rounded Thrust: {1}, Final Thrust: {2}.", proportionalThrust, roundedThrust, thrust));
            }

            if (velocity > 500)
            {
                isDecelerate = true;
            }

            //if (isDecelerate)
            //    thrust = "0";

            Console.Error.WriteLine(string.Format("NextCPDist: {0}, NextCPAngle: {1}, Vx: {2}, Vy: {3}, Timeout: {4}.", nextCheckpointDist, nextCheckpointAngle, velocityX, velocityY, timeout));

            //if (Math.Abs(opponentX - x) < 5 && Math.Abs(opponentY - y) < 5 && !thrustUsed) {
            if (!thrustUsed && ((nextCheckpointAngle == 0 && nextCheckpointDist >= 5000) || isFinalCheckPoint))
            {
                thrust     = "BOOST";
                thrustUsed = true;
            }


            if (isMadKnightTrick && thrust != "BOOST")
            {
                if (nextCheckpointAngle > 30 || nextCheckpointAngle < -30)
                {
                    xToGo  = Convert.ToInt32(nextCheckpointX - (velocityX * 3));
                    yToGo  = Convert.ToInt32(nextCheckpointY - (velocityY * 3));
                    thrust = "100";
                }
                else
                {
                    xToGo  = nextCheckpointX;
                    yToGo  = nextCheckpointY;
                    thrust = "100";
                }
            }

            if (isOverrideBasedOnAngle && thrust != "BOOST")
            {
                xToGo  = Convert.ToInt32(nextCheckpointX - (velocityX * 3));
                yToGo  = Convert.ToInt32(nextCheckpointY - (velocityY * 3));
                thrust = "100";

                /*
                 * if (nextCheckpointAngle > 120 || nextCheckpointAngle < -120)
                 *  thrust = "15";
                 * else if (nextCheckpointAngle > 110 || nextCheckpointAngle < -110)
                 *  thrust = "25";
                 * else if (nextCheckpointAngle > 100 || nextCheckpointAngle < -100)
                 *  thrust = "35";
                 * else if (nextCheckpointAngle > 90 || nextCheckpointAngle < -90)
                 *  thrust = "45";
                 * else if (nextCheckpointAngle > 80 || nextCheckpointAngle < -80)
                 *  thrust = "55";
                 * else if (nextCheckpointAngle > 70 || nextCheckpointAngle < -70)
                 *  thrust = "65";
                 * else if (nextCheckpointAngle > 60 || nextCheckpointAngle < -60)
                 *  thrust = "75";
                 * else if (nextCheckpointAngle > 50 || nextCheckpointAngle < -50)
                 *  thrust = "85";
                 * else if (nextCheckpointAngle > 40 || nextCheckpointAngle < -40)
                 *  thrust = "95";
                 * else
                 * {
                 *  xToGo = nextCheckpointX;
                 *  yToGo = nextCheckpointY;
                 *
                 *  thrust = "100";
                 * }
                 */
            }

            //Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5} {6} {7}", xToGo, yToGo, thrust, thrust, nextCheckpointAngle, myPod.Vx, myPod.Vy, myPod.R));
            Console.WriteLine(string.Format("{0} {1} {2} {3} {4} {5} {6}", xToGo, yToGo, thrust, thrust, nextCheckpointAngle, angleToPoint, angleToNextPoint));

            myLastPod = myPod;
        }
    }