|
|
@@ -11,7 +11,7 @@ type SimpleStrategy struct { |
|
|
|
} |
|
|
|
|
|
|
|
func (s *SimpleStrategy) Execute(stars[] models.Star, flights[] models.Flight, links[] models.Link) { |
|
|
|
|
|
|
|
|
|
|
|
for i, s := range stars { |
|
|
|
// Maximum flights per star per round is 3 |
|
|
|
total := 0 |
|
|
@@ -37,6 +37,8 @@ func (s *SimpleStrategy) Execute(stars[] models.Star, flights[] models.Flight, l |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
//fmt.Printf("Links: %d\n", len(links)) |
|
|
|
//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) |
|
|
|
// Determine target for this source |
|
|
|
for j, t := range stars { |
|
|
|
// Only target non-owned or enemy stars |
|
|
@@ -44,11 +46,21 @@ func (s *SimpleStrategy) Execute(stars[] models.Star, flights[] models.Flight, l |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
// Check if ship is within distance |
|
|
|
//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) |
|
|
|
//flightTurnDistance := calculateDistanceCeiling(&t, &s) |
|
|
|
////fmt.Println(flightTurnDistance) |
|
|
|
//if flightTurnDistance > 60 { |
|
|
|
// continue |
|
|
|
//} |
|
|
|
|
|
|
|
// If enemy star, make sure we have enough ships to attack it |
|
|
|
//if t.Owner == 2 && (s.Ships - (t.Ships + (flightTurnDistance * t.Richness))) <= 1 { |
|
|
|
if t.Owner == 2 && (s.Ships/2) - (t.Ships + (6 * t.Richness)) < 0 { |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
// TODO: Find best destination |
|
|
|
// Fly to this target, and skip processing all remaining potential target stars |
|
|
|
fmt.Printf("fly %d %d %d\n", i, j, s.Ships / 2) |
|
|
|
total++ |
|
|
@@ -64,6 +76,23 @@ func (s *SimpleStrategy) Execute(stars[] models.Star, flights[] models.Flight, l |
|
|
|
fmt.Println("done") |
|
|
|
} |
|
|
|
|
|
|
|
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 lb |
|
|
|
} |
|
|
|
|
|
|
|
func flightTurnDistance(x, y int, star *models.Star) int { |
|
|
|
pointDistance := distanceBetweenPoints(x, y, star.X, star.Y) |
|
|
|
|