Over The Wire Advent 2019 Battle of the Galaxies
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
707B

  1. package strategies
  2. import (
  3. "botg/models"
  4. "math"
  5. )
  6. type StarAffiliation int
  7. const (
  8. Own StarAffiliation = 0
  9. Friend StarAffiliation = 1
  10. Enemy StarAffiliation = 2
  11. )
  12. func calculateDistanceCeiling(source *models.Star, target *models.Star) int {
  13. squareDist := (source.X - target.X) * (source.X - target.X) + int(source.Y - target.Y) * (source.Y - target.Y)
  14. lb := 1
  15. ub := 300 * 2
  16. for lb < ub {
  17. mb := (lb + ub) / 2
  18. if int(mb*mb) >= squareDist {
  19. ub = mb
  20. } else {
  21. lb = mb + 1
  22. }
  23. }
  24. return lb
  25. }
  26. func flightTurnDistance(source, target *models.Star) int {
  27. if source.Idx == target.Idx {
  28. return 0
  29. }
  30. return int(math.Ceil(float64(calculateDistanceCeiling(source, target)) / 10.0))
  31. }