Add broken obstacle collision
This commit is contained in:
parent
d57e1e98e1
commit
14aabd1b45
22
game/game.go
22
game/game.go
|
@ -16,8 +16,9 @@ func NewState() State {
|
||||||
var bots []Bot
|
var bots []Bot
|
||||||
for j := 0; j < numBots; j++ {
|
for j := 0; j < numBots; j++ {
|
||||||
b := Bot{
|
b := Bot{
|
||||||
id: i*NumTeams + j,
|
id: i*NumTeams + j,
|
||||||
Pos: j * (Steps / numBots),
|
Lane: i,
|
||||||
|
Pos: j * (Steps / numBots),
|
||||||
}
|
}
|
||||||
bots = append(bots, b)
|
bots = append(bots, b)
|
||||||
}
|
}
|
||||||
|
@ -45,10 +46,11 @@ type Team struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Bot struct {
|
type Bot struct {
|
||||||
id int
|
id int
|
||||||
Pos int
|
Lane int
|
||||||
v int
|
Pos int
|
||||||
a int
|
v int
|
||||||
|
a int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Baton struct {
|
type Baton struct {
|
||||||
|
@ -64,7 +66,7 @@ func UpdateState(sOld State) State {
|
||||||
s := sOld
|
s := sOld
|
||||||
|
|
||||||
for i, t := range s.Teams {
|
for i, t := range s.Teams {
|
||||||
moveBot(t.Baton.Holder)
|
moveBot(t.Baton.Holder, sOld)
|
||||||
maybePassBaton(&s.Teams[i])
|
maybePassBaton(&s.Teams[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,11 +110,11 @@ func gameOver(s State) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Steps = 400
|
Steps = 50
|
||||||
numBots = 10
|
numBots = 5
|
||||||
NumTeams = 2
|
NumTeams = 2
|
||||||
maxA = 3
|
maxA = 3
|
||||||
maxV = 20
|
maxV = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
func abs(n int) int {
|
func abs(n int) int {
|
||||||
|
|
|
@ -2,7 +2,7 @@ package game
|
||||||
|
|
||||||
import "math/rand"
|
import "math/rand"
|
||||||
|
|
||||||
func moveBot(b *Bot) {
|
func moveBot(b *Bot, s State) {
|
||||||
if b.a == 0 {
|
if b.a == 0 {
|
||||||
b.a = 1
|
b.a = 1
|
||||||
}
|
}
|
||||||
|
@ -21,10 +21,23 @@ func moveBot(b *Bot) {
|
||||||
if b.v < -maxV {
|
if b.v < -maxV {
|
||||||
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 (
|
const (
|
||||||
passDistance = 10
|
passDistance = 2
|
||||||
baseAccel = 10
|
baseAccel = 1
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue