Created
October 22, 2022 07:07
-
-
Save Tracer1337/f8a172137dfe11cd87898efa3baa42d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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