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 {
|
func chooseCommand(t Team, s State) command {
|
||||||
h := t.Baton.Holder
|
h := t.Baton.Holder
|
||||||
if collide(h.Pos+1, h.Lane, s) {
|
if collide(h.Pos+1, h.Lane, s) {
|
||||||
return left
|
if h.Lane <= t.Lane {
|
||||||
|
return left
|
||||||
|
}
|
||||||
|
return right
|
||||||
}
|
}
|
||||||
|
|
||||||
var nextBot *Bot
|
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 (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type State struct {
|
type State struct {
|
||||||
|
@ -26,6 +25,7 @@ func NewState() State {
|
||||||
teams = append(teams, Team{
|
teams = append(teams, Team{
|
||||||
Bots: bots,
|
Bots: bots,
|
||||||
Baton: Baton{Holder: &bots[0]},
|
Baton: Baton{Holder: &bots[0]},
|
||||||
|
Lane: i,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,7 @@ type Team struct {
|
||||||
Bots []Bot
|
Bots []Bot
|
||||||
Baton Baton
|
Baton Baton
|
||||||
won bool
|
won bool
|
||||||
|
Lane int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Bot struct {
|
type Bot struct {
|
||||||
|
@ -85,30 +86,6 @@ func UpdateState(sOld State) State {
|
||||||
return s
|
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) {
|
func maybePassBaton(t *Team) {
|
||||||
for i, b := range t.Bots {
|
for i, b := range t.Bots {
|
||||||
h := t.Baton.Holder
|
h := t.Baton.Holder
|
||||||
|
|
Loading…
Reference in New Issue