Skip to content

Instantly share code, notes, and snippets.

@morgankenyon
Last active May 9, 2020 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morgankenyon/c0f48cefa0ae439bab726c0c6fd2e894 to your computer and use it in GitHub Desktop.
Save morgankenyon/c0f48cefa0ae439bab726c0c6fd2e894 to your computer and use it in GitHub Desktop.
# 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