Browse Source

Fix the stupid demorgan rule fup

master
Khaled Nassar 4 years ago
parent
commit
fa2f7d801d
1 changed files with 9 additions and 14 deletions
  1. +9
    -14
      strategies/linker.go

+ 9
- 14
strategies/linker.go View File

@@ -15,8 +15,8 @@ type LinkerStrategy struct {
func (ls *LinkerStrategy) Execute(stars []*models.Star, flights []models.Flight, links []models.Link) int {
// Send back ships, link, then attack
issuedCommands := 0
issuedCommands += ls.sendHomiesBack(stars, flights, links)
issuedCommands += ls.linkFriendlies(stars, flights, links)
issuedCommands += ls.sendHomiesBack(stars, flights, links)
issuedCommands += ls.attack(stars, flights, links)
// Do something randomly, whatever now
if issuedCommands == 0 {
@@ -27,7 +27,7 @@ func (ls *LinkerStrategy) Execute(stars []*models.Star, flights []models.Flight,

func (ls *LinkerStrategy) attack(stars []*models.Star, flights []models.Flight, links []models.Link) int {
issuedCommands := 0
for i, s := range stars {
for _, s := range stars {
// No more flights allowed for that node
if s.FlightsAllowed <= 0 {
continue
@@ -46,9 +46,9 @@ func (ls *LinkerStrategy) attack(stars []*models.Star, flights []models.Flight,
//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 {
for _, t := range stars {
// Only target non-owned or enemy stars
if !t.Unowned() || !t.Enemy() {
if !t.Unowned() && !t.Enemy() {
continue
}

@@ -78,7 +78,7 @@ 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)
fmt.Printf("fly %d %d %d\n", s.Idx, t.Idx, shipCount)
t.Capturing = true
t.CapturedBy = s.Idx
issuedCommands++
@@ -92,13 +92,8 @@ func (ls *LinkerStrategy) attack(stars []*models.Star, flights []models.Flight,
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)
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)
}
@@ -129,7 +124,7 @@ func (ls *LinkerStrategy) linkFriendlies(stars []*models.Star, flights []models.
}

distance = calculateDistanceCeiling(src, dst)
currentLowest, exists := friendlyDistanceMatrix[*src]
currentLowest, exists := friendlyDistanceMatrix[src]
if exists {
currentDistance := calculateDistanceCeiling(src, currentLowest)
if currentDistance < distance {
@@ -137,7 +132,7 @@ func (ls *LinkerStrategy) linkFriendlies(stars []*models.Star, flights []models.
}
}
// Only add it if it's the currently closest friendly star from source
friendlyDistanceMatrix[*src] = dst
friendlyDistanceMatrix[src] = dst
}
}

@@ -148,7 +143,7 @@ func (ls *LinkerStrategy) linkFriendlies(stars []*models.Star, flights []models.
continue
}

if ls.insufficientShipsForLinking(&src) {
if ls.insufficientShipsForLinking(src) {
continue
}


Loading…
Cancel
Save