use abs for handoff; fix no-self-handoff
This commit is contained in:
parent
c37b31b8fa
commit
661244fec4
13
game.go
13
game.go
|
@ -69,11 +69,11 @@ func updateState(sOld state) state {
|
||||||
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
|
||||||
if h == &b {
|
if h == &t.bots[i] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if b.pos-h.pos == 10 {
|
if abs(b.pos-h.pos) <= 10 {
|
||||||
log.Printf("pass from %v to %v!", t.baton.holder, &t.bots[i])
|
log.Printf("pass from %p to %p!", t.baton.holder, &t.bots[i])
|
||||||
t.baton.holder.v = 0
|
t.baton.holder.v = 0
|
||||||
t.baton.holder.a = 0
|
t.baton.holder.a = 0
|
||||||
t.baton.holder = &t.bots[i]
|
t.baton.holder = &t.bots[i]
|
||||||
|
@ -101,3 +101,10 @@ const (
|
||||||
numBots = 10
|
numBots = 10
|
||||||
numTeams = 4
|
numTeams = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func abs(n int) int {
|
||||||
|
if n < 0 {
|
||||||
|
return -n
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue