public int CompareTo(SlopedLocation other) { int result = Angle.CompareTo(other.Angle); if (result == 0) { return(ManhattanDistance.CompareTo(other.ManhattanDistance)); } return(result); }
private int Part2GeneralFunction(AsteroidGrid asteroids, AsteroidGrid bestSolution) { asteroids.PrintGrid(); if (asteroids.AsteroidCount < 200) { return(0); } asteroids.SetBestLocation(false); var sorted = new List <SlopedLocation>(); for (int x = 0; x < asteroids.Width; x++) { for (int y = 0; y < asteroids.Height; y++) { if (asteroids[x, y]) { var location = new Location2D(x, y); var degrees = AddDegrees(asteroids.BestLocation.GetSlopeDegrees(location), -90); var slopedLocation = new SlopedLocation(location, degrees, asteroids.BestLocation); sorted.Add(slopedLocation); } } } sorted.Sort(); int consecutive = 1; for (int i = 1; i < sorted.Count; i++) { if (sorted[i].HasEqualAbsoluteAngle(sorted[i - 1])) { sorted[i].AddFullCircleRotations(consecutive++); } else { consecutive = 1; } } sorted.Sort(); var l = sorted[199].Location; return(l.X * 100 + l.Y); }
public bool HasEqualAbsoluteAngle(SlopedLocation other) => Abs(AbsoluteAngle - other.AbsoluteAngle) < epsilon;