From 5f41d263cdb10c3186d8ede310186d3566499a94 Mon Sep 17 00:00:00 2001 From: Luke Meyers Date: Sat, 8 Feb 2020 11:50:05 -0800 Subject: [PATCH] refactor ai --- game/ai.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/game/ai.go b/game/ai.go index 7857315..3b49286 100644 --- a/game/ai.go +++ b/game/ai.go @@ -40,8 +40,7 @@ func smartChooseHelper(s State, teamID int, depth int) command { if !legalMove(s, teamID, cmd) { continue } - ss := doCommand(cmd, s, teamID) - n := score(ss, teamID, depth) + n := score(cmd, s, teamID, depth) if n > bestN { bestCmd, bestN = cmd, n } @@ -50,7 +49,8 @@ func smartChooseHelper(s State, teamID int, depth int) command { return bestCmd } -func score(s State, teamID int, depth int) int { +func score(cmd command, s State, teamID int, depth int) int { + s = doCommand(cmd, s, teamID) if depth == 0 { t := s.Teams[teamID] b := ActiveRacer(t) @@ -60,7 +60,6 @@ func score(s State, teamID int, depth int) int { return b.Position.Pos } - cmd := smartChooseHelper(s, teamID, depth-1) - ss := doCommand(cmd, s, teamID) - return score(ss, teamID, depth-1) + cmd2 := smartChooseHelper(s, teamID, depth-1) + return score(cmd2, s, teamID, depth-1) }