Extract ai.go

This commit is contained in:
Luke Meyers 2020-02-05 21:21:25 -08:00
parent bce4758dfd
commit 797886b42b
2 changed files with 29 additions and 26 deletions

29
game/ai.go Normal file
View File

@ -0,0 +1,29 @@
package game
import "log"
func chooseCommand(t Team, s State) command {
h := t.Baton.Holder
if collide(h.Pos+1, h.Lane, s) {
return left
}
var nextBot *Bot
for i, b := range t.Bots {
if b.id == h.id+1 {
nextBot = &t.Bots[i]
break
}
}
if nextBot != nil {
if h.Lane != nextBot.Lane {
if abs(nextBot.Pos-h.Pos) < h.v {
log.Println("WHOOOOOOA")
return slowDown
}
}
}
return speedUp
}

View File

@ -101,32 +101,6 @@ func doCommand(cmd command, b *Bot) {
} }
} }
func chooseCommand(t Team, s State) command {
h := t.Baton.Holder
if collide(h.Pos+1, h.Lane, s) {
return left
}
var nextBot *Bot
for i, b := range t.Bots {
if b.id == h.id+1 {
nextBot = &t.Bots[i]
break
}
}
if nextBot != nil {
if h.Lane != nextBot.Lane {
if abs(nextBot.Pos-h.Pos) < h.v {
log.Println("WHOOOOOOA")
return slowDown
}
}
}
return speedUp
}
type command int type command int
const ( const (