diff --git a/game/game.go b/game/game.go index 027d2e0..f7ca2ff 100644 --- a/game/game.go +++ b/game/game.go @@ -16,8 +16,9 @@ func NewState() State { var bots []Bot for j := 0; j < numBots; j++ { b := Bot{ - id: i*NumTeams + j, - Pos: j * (Steps / numBots), + id: i*NumTeams + j, + Lane: i, + Pos: j * (Steps / numBots), } bots = append(bots, b) } @@ -45,10 +46,11 @@ type Team struct { } type Bot struct { - id int - Pos int - v int - a int + id int + Lane int + Pos int + v int + a int } type Baton struct { @@ -64,7 +66,7 @@ func UpdateState(sOld State) State { s := sOld for i, t := range s.Teams { - moveBot(t.Baton.Holder) + moveBot(t.Baton.Holder, sOld) maybePassBaton(&s.Teams[i]) } @@ -108,11 +110,11 @@ func gameOver(s State) bool { } const ( - Steps = 400 - numBots = 10 + Steps = 50 + numBots = 5 NumTeams = 2 maxA = 3 - maxV = 20 + maxV = 2 ) func abs(n int) int { diff --git a/game/physics.go b/game/physics.go index e178bc5..fcb87c9 100644 --- a/game/physics.go +++ b/game/physics.go @@ -2,7 +2,7 @@ package game import "math/rand" -func moveBot(b *Bot) { +func moveBot(b *Bot, s State) { if b.a == 0 { b.a = 1 } @@ -21,10 +21,23 @@ func moveBot(b *Bot) { if b.v < -maxV { b.v = -maxV } - b.Pos += b.v + + newPos := b.Pos + b.v + if !collide(b.id, newPos, b.Lane, s) { + b.Pos = newPos + } +} + +func collide(id, pos, lane int, s State) bool { + for _, o := range s.Obstacles { + if o.Pos == pos && o.Lane == lane { + return true + } + } + return false } const ( - passDistance = 10 - baseAccel = 10 + passDistance = 2 + baseAccel = 1 )