|
|
@@ -9,19 +9,12 @@ type LinkerStrategy struct { |
|
|
|
} |
|
|
|
|
|
|
|
func (ls *LinkerStrategy) Execute(stars []*models.Star, flights []models.Flight, links []models.Link) { |
|
|
|
friendly := make([]int, 10) |
|
|
|
friendlyDistanceMatrix := make(map[models.Star]*models.Star) |
|
|
|
for i, s := range stars { |
|
|
|
// Skip unowned and enemy stars |
|
|
|
if s.Unowned() || s.Enemy() { |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
if s.OwnedByMe() || s.Friendly() { |
|
|
|
friendly = append(friendly, i) |
|
|
|
} |
|
|
|
} |
|
|
|
// Link then attack |
|
|
|
ls.linkFriendlies(stars, flights, links) |
|
|
|
ls.attack(stars, flights, links) |
|
|
|
} |
|
|
|
|
|
|
|
func (ls *LinkerStrategy) attack(stars []*models.Star, flights []models.Flight, links []models.Link) { |
|
|
|
for i, s := range stars { |
|
|
|
// No more flights allowed for that node |
|
|
|
if s.FlightsAllowed <= 0 { |
|
|
@@ -73,11 +66,27 @@ func (ls *LinkerStrategy) Execute(stars []*models.Star, flights []models.Flight, |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func (ls *LinkerStrategy) linkFriendlies(stars []*models.Star, flights []models.Flight, links []models.Link) { |
|
|
|
friendly := make([]int, 10) |
|
|
|
friendlyDistanceMatrix := make(map[models.Star]*models.Star) |
|
|
|
for i, s := range stars { |
|
|
|
// Skip unowned and enemy stars |
|
|
|
if s.Unowned() || s.Enemy() { |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
if s.OwnedByMe() || s.Friendly() { |
|
|
|
friendly = append(friendly, i) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Let's try Linking first |
|
|
|
// Keep a map of all the distances |
|
|
|
for i := 0; i < len(friendly); i++ { |
|
|
|
src := stars[i] |
|
|
|
|
|
|
|
|
|
|
|
if src.FlightsAllowed <= 0 { |
|
|
|
continue |
|
|
|
} |