track acceleration

This commit is contained in:
Luke Meyers 2020-02-05 18:02:28 -08:00
parent eae865cee8
commit f57f87fc58
1 changed files with 11 additions and 7 deletions

18
game.go
View File

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