lane change right
This commit is contained in:
parent
b113d52f66
commit
2ae124f59e
|
@ -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
|
||||
|
|
|
@ -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
|
||||
)
|
27
game/game.go
27
game/game.go
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue