bots clear obstacles
This commit is contained in:
parent
2c660f07d5
commit
eac373c444
|
@ -35,7 +35,7 @@ func smartChooseCommand(s State, teamID int) command {
|
|||
bestCmd, bestN := speedUp, 0
|
||||
|
||||
log.Printf("team %d base score: %d", teamID, score(s, teamID))
|
||||
for _, cmd := range []command{speedUp, slowDown, left, right} {
|
||||
for _, cmd := range validCommands {
|
||||
if !legalMove(s, teamID, cmd) {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -7,8 +7,11 @@ const (
|
|||
slowDown
|
||||
left
|
||||
right
|
||||
clearObstacle
|
||||
)
|
||||
|
||||
var validCommands = []command{speedUp, slowDown, left, right, clearObstacle}
|
||||
|
||||
func doCommand(cmd command, s State, teamID int) State {
|
||||
da := 1
|
||||
//da += rand.Intn(3) - 1
|
||||
|
@ -22,16 +25,22 @@ func doCommand(cmd command, s State, teamID int) State {
|
|||
case speedUp:
|
||||
b.a += da
|
||||
*b = accelerate(*b)
|
||||
s = updateBot(s, *b)
|
||||
case slowDown:
|
||||
b.a -= da
|
||||
*b = accelerate(*b)
|
||||
s = updateBot(s, *b)
|
||||
case left:
|
||||
b.Position.Lane++
|
||||
s = updateBot(s, *b)
|
||||
case right:
|
||||
b.Position.Lane--
|
||||
}
|
||||
|
||||
s = updateBot(s, *b)
|
||||
case clearObstacle:
|
||||
pos := b.Position
|
||||
pos.Pos++
|
||||
s = removeObstacle(s, pos)
|
||||
}
|
||||
|
||||
if b := ActiveBot(s.Teams[teamID]); b != nil {
|
||||
s = moveBot(s, *b)
|
||||
|
@ -51,6 +60,8 @@ func (c command) String() string {
|
|||
return "go left"
|
||||
case right:
|
||||
return "go right"
|
||||
case clearObstacle:
|
||||
return "clear obstacle"
|
||||
}
|
||||
return "(unknown)"
|
||||
}
|
||||
|
|
10
game/game.go
10
game/game.go
|
@ -94,6 +94,16 @@ func destroyBot(s State, b Bot) State {
|
|||
return updateBot(s, b)
|
||||
}
|
||||
|
||||
func removeObstacle(s State, pos Position) State {
|
||||
for i, o := range s.Obstacles {
|
||||
if o.Position == pos {
|
||||
s.Obstacles = append(s.Obstacles[:i], s.Obstacles[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func won(b Bot, s State) bool {
|
||||
return b.Position.Pos >= Steps
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue