track bot speed
This commit is contained in:
parent
f6be2d14d6
commit
eae865cee8
12
game.go
12
game.go
|
@ -32,7 +32,8 @@ type team struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type bot struct {
|
type bot struct {
|
||||||
pos int
|
pos int
|
||||||
|
speed int
|
||||||
}
|
}
|
||||||
|
|
||||||
type baton struct {
|
type baton struct {
|
||||||
|
@ -44,7 +45,12 @@ 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
|
||||||
b.pos++
|
|
||||||
|
if b.speed == 0 {
|
||||||
|
b.speed = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
b.pos += b.speed
|
||||||
maybePassBaton(&s.teams[i])
|
maybePassBaton(&s.teams[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +71,9 @@ 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 = &t.bots[i]
|
t.baton.holder = &t.bots[i]
|
||||||
|
t.bots[i].speed = 1
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue