Browse Source

Butchered linking and attacking together

master
Khaled Nassar 4 years ago
parent
commit
1dda0fff3c
2 changed files with 25 additions and 16 deletions
  1. +3
    -3
      main.go
  2. +22
    -13
      strategies/linker.go

+ 3
- 3
main.go View File

@@ -35,7 +35,7 @@ func main() {
var roundComplete bool = false

// Run strategy
strategy := strategies.SimpleStrategy{}
strategy := strategies.LinkerStrategy{}
//strategy := strategies.NoneStrategy {}

for gameComplete == false {
@@ -132,9 +132,9 @@ func parseLine(text string) bool {
}

// Update star flight data
for i, s := range stars {
for _, s := range stars {
for _, f := range flights {
if f.SourceStar == i {
if f.SourceStar == s.Idx {
s.FlightsAllowed--
}
}

+ 22
- 13
strategies/linker.go View File

@@ -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
}

Loading…
Cancel
Save