From 794c54764e9ee75781204fd4e824139581a21b05 Mon Sep 17 00:00:00 2001 From: Luke Meyers Date: Sat, 8 Feb 2020 11:52:26 -0800 Subject: [PATCH] refactor ai --- game/ai.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/game/ai.go b/game/ai.go index 3b49286..806b80f 100644 --- a/game/ai.go +++ b/game/ai.go @@ -37,9 +37,6 @@ func smartChooseHelper(s State, teamID int, depth int) command { bestCmd, bestN := speedUp, 0 for _, cmd := range validCommands { - if !legalMove(s, teamID, cmd) { - continue - } n := score(cmd, s, teamID, depth) if n > bestN { bestCmd, bestN = cmd, n @@ -50,6 +47,9 @@ func smartChooseHelper(s State, teamID int, depth int) command { } func score(cmd command, s State, teamID int, depth int) int { + if !legalMove(s, teamID, cmd) { + return -1 + } s = doCommand(cmd, s, teamID) if depth == 0 { t := s.Teams[teamID] @@ -60,6 +60,7 @@ func score(cmd command, s State, teamID int, depth int) int { return b.Position.Pos } - cmd2 := smartChooseHelper(s, teamID, depth-1) - return score(cmd2, s, teamID, depth-1) + depth-- + cmd2 := smartChooseHelper(s, teamID, depth) + return score(cmd2, s, teamID, depth) }