track bot speed

This commit is contained in:
Luke Meyers 2020-02-05 17:56:41 -08:00
parent f6be2d14d6
commit eae865cee8
1 changed files with 10 additions and 2 deletions

12
game.go
View File

@ -32,7 +32,8 @@ type team struct {
}
type bot struct {
pos int
pos int
speed int
}
type baton struct {
@ -44,7 +45,12 @@ func updateState(sOld state) state {
for i, t := range s.teams {
b := t.baton.holder
b.pos++
if b.speed == 0 {
b.speed = 1
}
b.pos += b.speed
maybePassBaton(&s.teams[i])
}
@ -65,7 +71,9 @@ func maybePassBaton(t *team) {
}
if b.pos-h.pos == 1 {
log.Printf("pass from %v to %v!", t.baton.holder, &t.bots[i])
t.baton.holder.speed = 0
t.baton.holder = &t.bots[i]
t.bots[i].speed = 1
return
}
}