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.

66 lines
1.6KB

  1. package strategies
  2. import (
  3. "botg/models"
  4. "fmt"
  5. )
  6. type SimpleStrategy struct {
  7. }
  8. func (s *SimpleStrategy) Execute(stars []*models.Star, flights []models.Flight, links []models.Link) {
  9. for i, s := range stars {
  10. // No more flights allowed for that node
  11. if s.FlightsAllowed <= 0 {
  12. continue
  13. }
  14. // Only process owned stars
  15. if s.Owner != 0 || s.Ships == 0 {
  16. continue
  17. }
  18. // Wait till we have a sufficient number of ships
  19. if s.Ships < 10 {
  20. continue
  21. }
  22. //fmt.Printf("Links: %d\n", len(links))
  23. //fmt.Printf("SOURCE => IDX=%d, X=%d, Y=%d, OWNER=%d, RICH=%d, SHIPS=%d\n", s.Idx, s.X, s.Y, s.Owner, s.Richness, s.Ships)
  24. // Determine target for this source
  25. for j, t := range stars {
  26. // Only target non-owned or enemy stars
  27. if t.Friendly() || t.OwnedByMe() {
  28. continue
  29. }
  30. // Check if ship is within distance
  31. //fmt.Printf("TARGET => IDX=%d, X=%d, Y=%d, OWNER=%d, RICH=%d, SHIPS=%d\n", t.Idx, t.X, t.Y, t.Owner, t.Richness, t.Ships)
  32. flightTurnDistance := flightTurnDistance(s, t)
  33. if flightTurnDistance > 6 {
  34. continue
  35. }
  36. // If enemy star, make sure we have enough ships to attack it
  37. //if t.Owner == 2 && (s.Ships - (t.Ships + (flightTurnDistance * t.Richness))) <= 1 {
  38. insufficientShips := (s.Ships / 2) <= ((t.Ships + (flightTurnDistance * t.Richness)) + 5)
  39. if t.Enemy() && insufficientShips {
  40. continue
  41. }
  42. shipCount := s.Ships / 2
  43. if shipCount < 6 {
  44. shipCount = 6
  45. }
  46. // TODO: Find best destination
  47. // Fly to this target, and skip processing all remaining potential target stars
  48. fmt.Printf("fly %d %d %d\n", i, j, shipCount)
  49. s.FlightsAllowed--
  50. break
  51. }
  52. }
  53. }