Extract ai.go
This commit is contained in:
parent
bce4758dfd
commit
797886b42b
|
@ -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
|
||||
}
|
26
game/game.go
26
game/game.go
|
@ -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
|
||||
|
||||
const (
|
||||
|
|
Loading…
Reference in New Issue