lane change right

This commit is contained in:
Luke Meyers 2020-02-05 21:47:15 -08:00
parent b113d52f66
commit 2ae124f59e
3 changed files with 36 additions and 26 deletions

View File

@ -5,7 +5,10 @@ import "log"
func chooseCommand(t Team, s State) command {
h := t.Baton.Holder
if collide(h.Pos+1, h.Lane, s) {
return left
if h.Lane <= t.Lane {
return left
}
return right
}
var nextBot *Bot

30
game/commands.go Normal file
View File

@ -0,0 +1,30 @@
package game
import "math/rand"
func doCommand(cmd command, b *Bot) {
da := 1
da += rand.Intn(3) - 1
switch cmd {
case speedUp:
b.a += da
accelerate(b)
case slowDown:
b.a -= da
accelerate(b)
case left:
b.Lane++
case right:
b.Lane--
}
}
type command int
const (
speedUp command = iota
slowDown
left
right
)

View File

@ -2,7 +2,6 @@ package game
import (
"log"
"math/rand"
)
type State struct {
@ -26,6 +25,7 @@ func NewState() State {
teams = append(teams, Team{
Bots: bots,
Baton: Baton{Holder: &bots[0]},
Lane: i,
})
}
@ -48,6 +48,7 @@ type Team struct {
Bots []Bot
Baton Baton
won bool
Lane int
}
type Bot struct {
@ -85,30 +86,6 @@ func UpdateState(sOld State) State {
return s
}
func doCommand(cmd command, b *Bot) {
da := 1
da += rand.Intn(3) - 1
switch cmd {
case speedUp:
b.a += da
accelerate(b)
case slowDown:
b.a -= da
accelerate(b)
case left:
b.Lane++
}
}
type command int
const (
speedUp command = iota
slowDown
left
)
func maybePassBaton(t *Team) {
for i, b := range t.Bots {
h := t.Baton.Holder