refactor ai
This commit is contained in:
parent
24eb2c6143
commit
5f41d263cd
11
game/ai.go
11
game/ai.go
|
@ -40,8 +40,7 @@ func smartChooseHelper(s State, teamID int, depth int) command {
|
||||||
if !legalMove(s, teamID, cmd) {
|
if !legalMove(s, teamID, cmd) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ss := doCommand(cmd, s, teamID)
|
n := score(cmd, s, teamID, depth)
|
||||||
n := score(ss, teamID, depth)
|
|
||||||
if n > bestN {
|
if n > bestN {
|
||||||
bestCmd, bestN = cmd, n
|
bestCmd, bestN = cmd, n
|
||||||
}
|
}
|
||||||
|
@ -50,7 +49,8 @@ func smartChooseHelper(s State, teamID int, depth int) command {
|
||||||
return bestCmd
|
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 {
|
if depth == 0 {
|
||||||
t := s.Teams[teamID]
|
t := s.Teams[teamID]
|
||||||
b := ActiveRacer(t)
|
b := ActiveRacer(t)
|
||||||
|
@ -60,7 +60,6 @@ func score(s State, teamID int, depth int) int {
|
||||||
return b.Position.Pos
|
return b.Position.Pos
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := smartChooseHelper(s, teamID, depth-1)
|
cmd2 := smartChooseHelper(s, teamID, depth-1)
|
||||||
ss := doCommand(cmd, s, teamID)
|
return score(cmd2, s, teamID, depth-1)
|
||||||
return score(ss, teamID, depth-1)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue