|
|
@@ -17,15 +17,71 @@ func (ls *LinkerStrategy) Execute(stars []*models.Star, flights []models.Flight, |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
// Keep track of friendly stars |
|
|
|
if s.OwnedByMe() || s.Friendly() { |
|
|
|
friendly = append(friendly, i) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for i, s := range stars { |
|
|
|
// No more flights allowed for that node |
|
|
|
if s.FlightsAllowed <= 0 { |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
// Only process owned stars |
|
|
|
if s.Owner != 0 || s.Ships == 0 { |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
// Wait till we have a sufficient number of ships |
|
|
|
if s.Ships < 10 { |
|
|
|
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 |
|
|
|
if t.Friendly() || t.OwnedByMe() { |
|
|
|
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 := flightTurnDistance(s, t) |
|
|
|
if flightTurnDistance > 6 { |
|
|
|
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 { |
|
|
|
insufficientShips := (s.Ships / 2) <= ((t.Ships + (flightTurnDistance * t.Richness)) + 5) |
|
|
|
if t.Enemy() && insufficientShips { |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
shipCount := s.Ships / 2 |
|
|
|
if shipCount < 6 { |
|
|
|
shipCount = 6 |
|
|
|
} |
|
|
|
|
|
|
|
// 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, shipCount) |
|
|
|
s.FlightsAllowed-- |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Keep a map of all the distances |
|
|
|
for i := 0; i < len(friendly); i++ { |
|
|
|
src := stars[i] |
|
|
|
|
|
|
|
if src.FlightsAllowed <= 0 { |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
for j := i + 1; j < len(friendly); j++ { |
|
|
|
dst, distance := stars[j], 0 |
|
|
|
if src.Idx == dst.Idx { |
|
|
@@ -60,8 +116,6 @@ func (ls *LinkerStrategy) Execute(stars []*models.Star, flights []models.Flight, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var nextLinkSource, nextLinkTarget *models.Star |
|
|
|
minDistance := 300 * 300 |
|
|
|
for src, dst := range friendlyDistanceMatrix { |
|
|
|
// If the source is not owned by me, must be a different closer commander |
|
|
|
// so skip it |
|
|
@@ -73,17 +127,12 @@ func (ls *LinkerStrategy) Execute(stars []*models.Star, flights []models.Flight, |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
distance := calculateDistanceCeiling(&src, dst) |
|
|
|
if distance < minDistance { |
|
|
|
nextLinkSource = &src |
|
|
|
nextLinkTarget = dst |
|
|
|
if src.FlightsAllowed > 0 { |
|
|
|
// Send a couple of ships out to link |
|
|
|
fmt.Printf("fly %d %d %d\n", src.Idx, dst.Idx, 2) |
|
|
|
src.FlightsAllowed-- |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if nextLinkSource != nil && nextLinkTarget != nil { |
|
|
|
// Send a ship out to link |
|
|
|
fmt.Printf("fly %d %d %d\n", nextLinkSource.Idx, nextLinkTarget.Idx, 2) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func (s *LinkerStrategy) insufficientShipsForLinking(star *models.Star) bool { |