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
|
bestCmd, bestN := speedUp, 0
|
||||||
|
|
||||||
log.Printf("team %d base score: %d", teamID, score(s, teamID))
|
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) {
|
if !legalMove(s, teamID, cmd) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,11 @@ const (
|
||||||
slowDown
|
slowDown
|
||||||
left
|
left
|
||||||
right
|
right
|
||||||
|
clearObstacle
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var validCommands = []command{speedUp, slowDown, left, right, clearObstacle}
|
||||||
|
|
||||||
func doCommand(cmd command, s State, teamID int) State {
|
func doCommand(cmd command, s State, teamID int) State {
|
||||||
da := 1
|
da := 1
|
||||||
//da += rand.Intn(3) - 1
|
//da += rand.Intn(3) - 1
|
||||||
|
@ -22,17 +25,23 @@ func doCommand(cmd command, s State, teamID int) State {
|
||||||
case speedUp:
|
case speedUp:
|
||||||
b.a += da
|
b.a += da
|
||||||
*b = accelerate(*b)
|
*b = accelerate(*b)
|
||||||
|
s = updateBot(s, *b)
|
||||||
case slowDown:
|
case slowDown:
|
||||||
b.a -= da
|
b.a -= da
|
||||||
*b = accelerate(*b)
|
*b = accelerate(*b)
|
||||||
|
s = updateBot(s, *b)
|
||||||
case left:
|
case left:
|
||||||
b.Position.Lane++
|
b.Position.Lane++
|
||||||
|
s = updateBot(s, *b)
|
||||||
case right:
|
case right:
|
||||||
b.Position.Lane--
|
b.Position.Lane--
|
||||||
|
s = updateBot(s, *b)
|
||||||
|
case clearObstacle:
|
||||||
|
pos := b.Position
|
||||||
|
pos.Pos++
|
||||||
|
s = removeObstacle(s, pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
s = updateBot(s, *b)
|
|
||||||
|
|
||||||
if b := ActiveBot(s.Teams[teamID]); b != nil {
|
if b := ActiveBot(s.Teams[teamID]); b != nil {
|
||||||
s = moveBot(s, *b)
|
s = moveBot(s, *b)
|
||||||
}
|
}
|
||||||
|
@ -51,6 +60,8 @@ func (c command) String() string {
|
||||||
return "go left"
|
return "go left"
|
||||||
case right:
|
case right:
|
||||||
return "go right"
|
return "go right"
|
||||||
|
case clearObstacle:
|
||||||
|
return "clear obstacle"
|
||||||
}
|
}
|
||||||
return "(unknown)"
|
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)
|
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 {
|
func won(b Bot, s State) bool {
|
||||||
return b.Position.Pos >= Steps
|
return b.Position.Pos >= Steps
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue