|
|
@@ -13,21 +13,27 @@ const ( |
|
|
|
Enemy StarAffiliation = 2 |
|
|
|
) |
|
|
|
|
|
|
|
func flightTurnDistance(x, y int, star *models.Star) int { |
|
|
|
pointDistance := distanceBetweenPoints(x, y, star.X, star.Y) |
|
|
|
|
|
|
|
if pointDistance == 0 { |
|
|
|
return 0 |
|
|
|
func calculateDistanceCeiling(source *models.Star, target *models.Star) int { |
|
|
|
squareDist := ((source.X - target.X) * (source.X - target.X)) + ((source.Y - target.Y) * (source.Y - target.Y)) |
|
|
|
|
|
|
|
lb := 1 |
|
|
|
ub := 300 * 2 |
|
|
|
for lb < ub { |
|
|
|
mb := (lb + ub) / 2 |
|
|
|
if mb*mb >= squareDist { |
|
|
|
ub = mb |
|
|
|
} else { |
|
|
|
lb = mb + 1 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return int(math.Ceil(pointDistance / 10)) |
|
|
|
return lb |
|
|
|
} |
|
|
|
|
|
|
|
func distanceBetweenPoints(x1, y1, x2, y2 int) float64 { |
|
|
|
// Is it the same point? The distance is defined as 0 |
|
|
|
if x1 == x2 && y1 == y2 { |
|
|
|
return 0 |
|
|
|
func flightTurnDistance(source, target *models.Star) int { |
|
|
|
if source.Idx == target.Idx { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
return math.Sqrt(math.Pow(float64(x1-x2), 2) + math.Pow(float64(y1-y2), 2)) |
|
|
|
return int(math.Ceil(float64(calculateDistanceCeiling(source, target)) / 10.0)) |
|
|
|
} |