package tictactoe
func Minimax(depth, nodeIndex int, isMax bool, scores []int, height int) int {
if depth == height {
return scores[nodeIndex]
}
if isMax {
left := Minimax(depth+1, nodeIndex*2, false, scores, height)
right := Minimax(depth+1, nodeIndex*2+1, false, scores, height)
return max(left, right)
}
left := Minimax(depth+1, nodeIndex*2, true, scores, height)
right := Minimax(depth+1, nodeIndex*2+1, true, scores, height)
return min(left, right)
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
func min(a, b int) int {
if a < b {
return a
}
return b
}