Skip to content

Instantly share code, notes, and snippets.

@Tracer1337
Created October 22, 2022 07:07
Show Gist options
  • Save Tracer1337/f8a172137dfe11cd87898efa3baa42d4 to your computer and use it in GitHub Desktop.
Save Tracer1337/f8a172137dfe11cd87898efa3baa42d4 to your computer and use it in GitHub Desktop.
import math
def minimax(resultList):
results = resultList[len(resultList) - 1]
if len(results) == 1:
return results[0], resultList
depth = math.log2(len(results))
newResults = []
for i in range(0, len(results), 2):
a, b = results[i], results[i + 1]
newResults.append(min(a, b) if depth % 2 == 0 else max(a, b))
resultList.append(newResults)
return minimax(resultList)
print(minimax([[4, 7, 5, 6]]))
print(minimax([[8, 7, 3, 9, 9, 8, 2, 4, 1, 8, 8, 9, 9, 9, 3, 4]]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment