Extract moveBot
This commit is contained in:
parent
33650b2e39
commit
f91a975bf1
45
game.go
45
game.go
|
@ -65,28 +65,7 @@ func updateState(sOld state) state {
|
||||||
s := sOld
|
s := sOld
|
||||||
|
|
||||||
for i, t := range s.teams {
|
for i, t := range s.teams {
|
||||||
b := t.baton.holder
|
moveBot(t.baton.holder)
|
||||||
|
|
||||||
if b.a == 0 {
|
|
||||||
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])
|
maybePassBaton(&s.teams[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +78,28 @@ func updateState(sOld state) state {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func moveBot(b *bot) {
|
||||||
|
if b.a == 0 {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
func maybePassBaton(t *team) {
|
func maybePassBaton(t *team) {
|
||||||
for i, b := range t.bots {
|
for i, b := range t.bots {
|
||||||
h := t.baton.holder
|
h := t.baton.holder
|
||||||
|
|
Loading…
Reference in New Issue