|
|
@@ -5,11 +5,16 @@ import ( |
|
|
|
"fmt" |
|
|
|
) |
|
|
|
|
|
|
|
const ( |
|
|
|
capturingShipThreshold int = 10 |
|
|
|
) |
|
|
|
|
|
|
|
type LinkerStrategy struct { |
|
|
|
} |
|
|
|
|
|
|
|
func (ls *LinkerStrategy) Execute(stars []*models.Star, flights []models.Flight, links []models.Link) { |
|
|
|
// Link then attack |
|
|
|
// Send back ships, link, then attack |
|
|
|
ls.sendHomiesBack(stars, flights, links) |
|
|
|
ls.linkFriendlies(stars, flights, links) |
|
|
|
ls.attack(stars, flights, links) |
|
|
|
} |
|
|
@@ -27,7 +32,7 @@ func (ls *LinkerStrategy) attack(stars []*models.Star, flights []models.Flight, |
|
|
|
} |
|
|
|
|
|
|
|
// Wait till we have a sufficient number of ships |
|
|
|
if s.Ships < 10 { |
|
|
|
if ls.insufficientShipsForCapturing(s) { |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
@@ -40,6 +45,11 @@ func (ls *LinkerStrategy) attack(stars []*models.Star, flights []models.Flight, |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
// In the process of capturing the star anyway |
|
|
|
if t.Capturing { |
|
|
|
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) |
|
|
@@ -62,6 +72,8 @@ func (ls *LinkerStrategy) attack(stars []*models.Star, flights []models.Flight, |
|
|
|
// 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) |
|
|
|
t.Capturing = true |
|
|
|
t.CapturedBy = s.Idx |
|
|
|
s.FlightsAllowed-- |
|
|
|
break |
|
|
|
} |
|
|
@@ -82,7 +94,6 @@ func (ls *LinkerStrategy) linkFriendlies(stars []*models.Star, flights []models. |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Let's try Linking first |
|
|
|
// Keep a map of all the distances |
|
|
|
for i := 0; i < len(friendly); i++ { |
|
|
|
src := stars[i] |
|
|
@@ -144,10 +155,34 @@ func (ls *LinkerStrategy) linkFriendlies(stars []*models.Star, flights []models. |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func (ls *LinkerStrategy) sendHomiesBack(stars []*models.Star, flights []models.Flight, links []models.Link) { |
|
|
|
for i, s := range stars { |
|
|
|
if s.OwnedByMe() && s.Captured() && ls.insufficientShipsForCapturing(s) && s.FlightsAllowed > 0 { |
|
|
|
richnessRoundsToCapture = capturingShipThreshold / s.Richness |
|
|
|
|
|
|
|
if richnessRoundsToCapture == 0 { |
|
|
|
richnessRoundsToCapture = 1 |
|
|
|
} |
|
|
|
|
|
|
|
timeToCapture = s.Turns + (richnessRoundsToCapture - 1) * 5 |
|
|
|
capturingStar = stars[s.CapturedBy] |
|
|
|
distanceToOrigin = flightTurnDistance(capturingStar, s) |
|
|
|
if flightTurnDistance < timeToCapture { |
|
|
|
s.FlightsAllowed-- |
|
|
|
fmt.Printf("fly %d %d %d\n", s.Idx, capturingStar.Idx, s.Ships) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func (s *LinkerStrategy) insufficientShipsForLinking(star *models.Star) bool { |
|
|
|
return star.Ships < 5 |
|
|
|
} |
|
|
|
|
|
|
|
func (s* LinkerStrategy) insufficientShipsForCapturing(star *models.Star) bool { |
|
|
|
return star.Ships < capturingShipThreshold |
|
|
|
} |
|
|
|
|
|
|
|
func (s *LinkerStrategy) linkedOrInProgress(src *models.Star, dst *models.Star, links []models.Link, flights []models.Flight) bool { |
|
|
|
linking := false |
|
|
|
|