fix issues from random accel

This commit is contained in:
Luke Meyers 2020-02-05 18:33:52 -08:00
parent 78f7e4f55c
commit 9fe5108133
1 changed files with 16 additions and 2 deletions

18
game.go
View File

@ -56,11 +56,23 @@ func updateState(sOld state) state {
b := t.baton.holder
if b.a == 0 {
b.a = 10
b.a = 1
}
b.a += rand.Intn(3) - 1
if b.a < -maxA {
b.a = -maxA
}
if b.a > maxA {
b.a = maxA
}
b.v += b.a
if b.v > maxV {
b.v = maxV
}
if b.v < -maxV {
b.v = -maxV
}
b.pos += b.v
maybePassBaton(&s.teams[i])
@ -78,7 +90,7 @@ func updateState(sOld state) state {
func maybePassBaton(t *team) {
for i, b := range t.bots {
h := t.baton.holder
if h == &t.bots[i] {
if h.id >= b.id {
continue
}
if abs(b.pos-h.pos) <= 10 {
@ -109,6 +121,8 @@ const (
steps = 400
numBots = 10
numTeams = 1
maxA = 3
maxV = 20
)
func abs(n int) int {