Ejemplo n.º 1
0
        private double GetAsteroidAngle(KeyValuePair <Point, List <AsteroidInfo> > asteroidGroup)
        {
            double angle = VectorAssist.GetAngleBetween(asteroidGroup.Key, new Point(0, -1));

            if (asteroidGroup.Key.X < 0)
            {
                angle = 360 - angle;
            }
            return(angle);
        }
Ejemplo n.º 2
0
        public new string ToString()
        {
            Point  direction = Direction == null ? new Point(0, -1) : Direction;
            double angle     = VectorAssist.GetAngleBetween(direction, new Point(0, -1));

            if (direction.X < 0)
            {
                angle = 360 - angle;
            }

            return(string.Format("Base @:({0}|{1} Detects: {2} Angle: {3}°)", Position.X, Position.Y, Detections, angle));
        }
Ejemplo n.º 3
0
 public override string Solve(string input, bool part2)
 {
     foreach (string instruction in GetLines(input))
     {
         if (part2)
         {
             WaypointInstruction(instruction);
         }
         else
         {
             DoInstruction(instruction);
         }
         Console.WriteLine("Changing Course: " + instruction);
     }
     return("Distance to Start: " + VectorAssist.ManhattanDistance(new Point(), position).ToString());
 }
Ejemplo n.º 4
0
        public int CompareTo(object obj)
        {
            if (obj.GetType() != typeof(AsteroidInfo))
            {
                throw new ArgumentException("Can only compare against AsteroidInfo instances");
            }
            Point        startDir = new Point(0, -1);
            AsteroidInfo compare  = (AsteroidInfo)obj;

            if (compare.Direction == Direction)
            {
                return(Math.Sign(Distance - compare.Distance));
            }
            else
            {
                double angle1 = VectorAssist.GetAngleBetween(Direction, startDir);
                double angle2 = VectorAssist.GetAngleBetween(compare.Direction, startDir);
                if (double.IsNaN(angle1))
                {
                    angle1 = 0;
                }
                if (double.IsNaN(angle2))
                {
                    angle2 = 0;
                }
                if (Direction.X < 0)
                {
                    angle1 += 180;
                }
                if (compare.Direction.X < 0)
                {
                    angle2 += 180;
                }
                return(Math.Sign(angle1 - angle2));
            }
        }