Last active
May 9, 2020 20:56
-
-
Save morgankenyon/c0f48cefa0ae439bab726c0c6fd2e894 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
# https://en.wikipedia.org/wiki/Alpha%E2%80%93beta_pruning#Pseudocode | |
# gist is saved as a .py file, but that's just for highlighting | |
# this isn't valid python code. | |
function alphabeta(node, depth, α, β, maximizingPlayer) is | |
if depth = 0 or node is a terminal node then | |
return the heuristic value of node | |
if maximizingPlayer then | |
value := −∞ | |
for each child of node do | |
value := max(value, alphabeta(child, depth − 1, α, β, FALSE)) | |
α := max(α, value) | |
if α ≥ β then | |
break (* β cut-off *) | |
return value | |
else | |
value := +∞ | |
for each child of node do | |
value := min(value, alphabeta(child, depth − 1, α, β, TRUE)) | |
β := min(β, value) | |
if α ≥ β then | |
break (* α cut-off *) | |
return value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment