randomize acceleration

This commit is contained in:
Luke Meyers 2020-02-05 18:27:27 -08:00
parent 661244fec4
commit 78f7e4f55c
2 changed files with 16 additions and 4 deletions

17
game.go
View File

@ -1,6 +1,9 @@
package main
import "log"
import (
"log"
"math/rand"
)
type state struct {
teams []team
@ -12,7 +15,11 @@ func newState() state {
for i := 0; i < numTeams; i++ {
var bots []bot
for j := 0; j < numBots; j++ {
bots = append(bots, bot{pos: j * (steps / numBots)})
b := bot{
id: i*numTeams + j,
pos: j * (steps / numBots),
}
bots = append(bots, b)
}
teams = append(teams, team{
bots: bots,
@ -32,6 +39,7 @@ type team struct {
}
type bot struct {
id int
pos int
v int
a int
@ -50,6 +58,7 @@ func updateState(sOld state) state {
if b.a == 0 {
b.a = 10
}
b.a += rand.Intn(3) - 1
b.v += b.a
b.pos += b.v
@ -73,7 +82,7 @@ func maybePassBaton(t *team) {
continue
}
if abs(b.pos-h.pos) <= 10 {
log.Printf("pass from %p to %p!", t.baton.holder, &t.bots[i])
log.Printf("pass from %v to %v!", h.id, b.id)
t.baton.holder.v = 0
t.baton.holder.a = 0
t.baton.holder = &t.bots[i]
@ -99,7 +108,7 @@ func gameOver(s state) bool {
const (
steps = 400
numBots = 10
numTeams = 4
numTeams = 1
)
func abs(n int) int {

View File

@ -1,6 +1,7 @@
package main
import (
"math/rand"
"time"
"github.com/faiface/pixel"
@ -20,6 +21,8 @@ func run() {
panic(err)
}
rand.Seed(time.Now().UnixNano())
s := newState()
colors := teamColors(s.teams)