예제 #1
0
        private static void Main(string[] args)
        {
            string[] inputs;
            int      surfaceN = int.Parse(Console.ReadLine()); // the number of points used to draw the surface of Mars.

            for (int i = 0; i < surfaceN; i++)
            {
                inputs = Console.ReadLine().Split(' ');
                int landX = int.Parse(inputs[0]); // X coordinate of a surface point. (0 to 6999)
                int landY = int.Parse(inputs[1]); // Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars.
                map.Add(new Point(landX, landY));
            }

            double maxDistance = 0;

            //find landing zone
            for (int i = 0; i < surfaceN - 1; i++)
            {
                if (map[i].Y == map[i + 1].Y) //flat
                {
                    var distance = map[i].Distance(map[i + 1]);
                    if (distance > maxDistance)
                    {
                        landingZone[0] = map[i];
                        landingZone[1] = map[i + 1];
                        maxDistance    = distance;
                    }
                }
            }
            landingZoneCenter = new Point((landingZone[1].X - landingZone[0].X) * 0.5 + landingZone[0].X, landingZone[0].Y);
            Console.Error.WriteLine("Zone: {0}, {1}: {2}", landingZone[0], landingZone[1], landingZoneCenter);

            Lander lander = new Lander(0, 0);
            int    t      = -1;

            // game loop
            while (true)
            {
                t++;

                inputs = Console.ReadLine().Split(' ');
                int X      = int.Parse(inputs[0]);
                int Y      = int.Parse(inputs[1]);
                int hSpeed = int.Parse(inputs[2]); // the horizontal speed (in m/s), can be negative.
                int vSpeed = int.Parse(inputs[3]); // the vertical speed (in m/s), can be negative.
                int fuel   = int.Parse(inputs[4]); // the quantity of remaining fuel in liters.
                int rotate = int.Parse(inputs[5]); // the rotation angle in degrees (-90 to 90).
                int power  = int.Parse(inputs[6]); // the thrust power (0 to 4).
                if (t == 0)
                {
                    initFuel = fuel;
                }
                lander.X = X;
                lander.Y = Y;
                lander.HorizontalVelocity = hSpeed;
                lander.VerticalVelocity   = vSpeed;
                lander.Fuel     = fuel;
                lander.Rotation = rotate;
                lander.Power    = power;
                lander.Save();
                stopwatch = Stopwatch.StartNew();
                //lander.Solve(140, t > 0);
                lander.Solve(140, t > 0);
                //if (t == 0)
                //{
                //Console.Error.WriteLine("Lander: {0} {1} {2} {3}", X, Y, rotate, power);
                //Console.Error.WriteLine("Solution: {0}\n{1}\nScore:{2}", string.Join(",", lander.sol.angles), string.Join(",", lander.sol.thrust), lander.sol.score);
                //for (int i = 0; i < Depth; i++)
                //{
                //    if (lander.CheckCollisions())
                //    {
                //        Console.Error.WriteLine("Col");
                //        break;
                //    }
                //    lander.Move(lander.sol.angles[i], lander.sol.thrust[i]);
                //    Console.Error.WriteLine("Lander Pos: {0} {1} V: {2} {3}", Math.Round(lander.X), Math.Round(lander.Y), Math.Round(lander.HorizontalVelocity), Math.Round(lander.VerticalVelocity));
                //}
                Console.WriteLine((int)lander.sol.angles[0] + " " + lander.sol.thrust[0]);

                //for (int i = 0; i < lander.sol.Time; i++)
                //{
                //    lander.sol.angles[i] = Math.Max(-90, Math.Min(lander.sol.angles[i], 90));
                //    lander.sol.thrust[i] = Math.Max(0, Math.Min(lander.sol.thrust[i], 4));
                //    Console.WriteLine((int)lander.sol.angles[i] + " " + lander.sol.thrust[i]);
                //}
                //}
                Console.Error.WriteLine("Score:{0} {1}", lander.sol.score, lander.sol.Time);
                Console.Error.WriteLine("Speed {0} {1}", lander.VerticalVelocity, lander.HorizontalVelocity);

                if (t > 0)
                {
                    Console.Error.WriteLine("Avg Sols: {0}, Avg Sims: {1}", solutionsTried / 1, solutionsTried * Depth / t);
                }

                //Console.WriteLine((int)lander.sol.angles[0] + " " + lander.sol.thrust[0]);

                /*
                 * if (lander.X < landingZone[0].X)
                 * {
                 *  //go right
                 *  if (lander.HorizontalVelocity < MaxHorizontalSpeed)
                 *  {
                 *      lander.Rotation = -21.9;
                 *  }
                 *  var distanceToDest = landingZone[0].X - lander.X;
                 *
                 *  lander.Power = 4;
                 * }
                 * else if (lander.X > landingZone[1].X)
                 * {
                 *  //go left
                 *  if (lander.HorizontalVelocity > -MaxHorizontalSpeed)
                 *  {
                 *      lander.Rotation = 21.9;
                 *  }
                 *  lander.Power = 4;
                 * }
                 * else
                 * {
                 *  //zero out horizontal velocity
                 *  var deltaRot = lander.HorizontalVelocity;
                 *  var error = 5;
                 *  if (deltaRot < 0)
                 *  {
                 *      lander.Rotation *= 0.50;
                 *  }
                 *  else if (deltaRot > 0)
                 *  {
                 *      lander.Rotation *= 0.50;
                 *  }
                 *
                 *  if (vSpeed < -40 && power < 4)
                 *  {
                 *      lander.Power += 1;
                 *  }
                 * }
                 *
                 * // 2 integers: rotate power. rotate is the desired rotation angle, power is the
                 * // desired thrust power (0 to 4).
                 * lander.Rotation = Math.Max(-90, Math.Min(90, (int)lander.Rotation));
                 * Console.WriteLine(lander.Rotation + " " + lander.Power);
                 * copy.Move(lander.Rotation, (int)lander.Power);
                 * Console.Error.WriteLine("Lander (SIM): {0} {1} {2} {3}", copy.X, copy.Y, copy.Rotation, copy.Power);
                 * */
            }
        }