AI don't attempt illegal moves
This commit is contained in:
parent
5b45dad1bb
commit
2c660f07d5
|
@ -36,6 +36,9 @@ func smartChooseCommand(s State, teamID int) command {
|
||||||
|
|
||||||
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 []command{speedUp, slowDown, left, right} {
|
||||||
|
if !legalMove(s, teamID, cmd) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
ss := doCommand(cmd, s, teamID)
|
ss := doCommand(cmd, s, teamID)
|
||||||
n := score(ss, teamID)
|
n := score(ss, teamID)
|
||||||
log.Printf("team %d score %s: %d", teamID, cmd, n)
|
log.Printf("team %d score %s: %d", teamID, cmd, n)
|
||||||
|
|
16
game/game.go
16
game/game.go
|
@ -107,6 +107,22 @@ func gameOver(s State) bool {
|
||||||
return false
|
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 {
|
func abs(n int) int {
|
||||||
if n < 0 {
|
if n < 0 {
|
||||||
return -n
|
return -n
|
||||||
|
|
Loading…
Reference in New Issue