Add broken obstacle collision

This commit is contained in:
Luke Meyers 2020-02-05 20:30:38 -08:00
parent d57e1e98e1
commit 14aabd1b45
2 changed files with 29 additions and 14 deletions

View File

@ -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 {

View File

@ -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
)