Browse Source

See if we've issued a certain number of commands

master
Khaled Nassar 4 years ago
parent
commit
8901f817fb
1 changed files with 22 additions and 7 deletions
  1. +22
    -7
      strategies/linker.go

+ 22
- 7
strategies/linker.go View File

@@ -12,14 +12,21 @@ const (
type LinkerStrategy struct {
}

func (ls *LinkerStrategy) Execute(stars []*models.Star, flights []models.Flight, links []models.Link) {
func (ls *LinkerStrategy) Execute(stars []*models.Star, flights []models.Flight, links []models.Link) int {
// Send back ships, link, then attack
ls.sendHomiesBack(stars, flights, links)
ls.linkFriendlies(stars, flights, links)
ls.attack(stars, flights, links)
issuedCommands := 0
issuedCommands += ls.sendHomiesBack(stars, flights, links)
issuedCommands += ls.linkFriendlies(stars, flights, links)
issuedCommands += ls.attack(stars, flights, links)
// Do something randomly, whatever now
if issuedCommands == 0 {
// Not sure what
}
return issuedCommands
}

func (ls *LinkerStrategy) attack(stars []*models.Star, flights []models.Flight, links []models.Link) {
func (ls *LinkerStrategy) attack(stars []*models.Star, flights []models.Flight, links []models.Link) int {
issuedCommands := 0
for i, s := range stars {
// No more flights allowed for that node
if s.FlightsAllowed <= 0 {
@@ -74,13 +81,16 @@ func (ls *LinkerStrategy) attack(stars []*models.Star, flights []models.Flight,
fmt.Printf("fly %d %d %d\n", i, j, shipCount)
t.Capturing = true
t.CapturedBy = s.Idx
issuedCommands++
s.FlightsAllowed--
break
}
}
return issuedCommands
}

func (ls *LinkerStrategy) linkFriendlies(stars []*models.Star, flights []models.Flight, links []models.Link) {
func (ls *LinkerStrategy) linkFriendlies(stars []*models.Star, flights []models.Flight, links []models.Link) int {
issuedCommands := 0
friendly := make([]int, 10)
friendlyDistanceMatrix := make(map[models.Star]*models.Star)
for i, s := range stars {
@@ -144,13 +154,16 @@ func (ls *LinkerStrategy) linkFriendlies(stars []*models.Star, flights []models.

if src.FlightsAllowed > 0 {
// Send a couple of ships out to link
issuedCommands++
fmt.Printf("fly %d %d %d\n", src.Idx, dst.Idx, 2)
src.FlightsAllowed--
}
}
return issuedCommands
}

func (ls *LinkerStrategy) sendHomiesBack(stars []*models.Star, flights []models.Flight, links []models.Link) {
func (ls *LinkerStrategy) sendHomiesBack(stars []*models.Star, flights []models.Flight, links []models.Link) int {
issuedCommands := 0
for _, s := range stars {
if s.OwnedByMe() && s.Captured() && ls.insufficientShipsForCapturing(s) && s.FlightsAllowed > 0 {

@@ -174,10 +187,12 @@ func (ls *LinkerStrategy) sendHomiesBack(stars []*models.Star, flights []models.
distanceToOrigin := flightTurnDistance(capturingStar, s)
if distanceToOrigin < timeToCapture {
s.FlightsAllowed--
issuedCommands++
fmt.Printf("fly %d %d %d\n", s.Idx, capturingStar.Idx, s.Ships - 3)
}
}
}
return issuedCommands
}

func (s *LinkerStrategy) insufficientShipsForLinking(star *models.Star) bool {

Loading…
Cancel
Save