diff --git a/game/ai.go b/game/ai.go index cb9ea52..50e53f4 100644 --- a/game/ai.go +++ b/game/ai.go @@ -36,6 +36,9 @@ func smartChooseCommand(s State, teamID int) command { log.Printf("team %d base score: %d", teamID, score(s, teamID)) for _, cmd := range []command{speedUp, slowDown, left, right} { + if !legalMove(s, teamID, cmd) { + continue + } ss := doCommand(cmd, s, teamID) n := score(ss, teamID) log.Printf("team %d score %s: %d", teamID, cmd, n) diff --git a/game/game.go b/game/game.go index ca68e01..b6d9309 100644 --- a/game/game.go +++ b/game/game.go @@ -107,6 +107,22 @@ func gameOver(s State) bool { return false } +func legalMove(s State, teamID int, cmd command) bool { + b := ActiveBot(s.Teams[teamID]) + if b == nil { + return false + } + + switch cmd { + case left: + return b.Position.Lane < NumLanes-1 + case right: + return b.Position.Lane > 0 + + } + return true +} + func abs(n int) int { if n < 0 { return -n