Skip to content

Instantly share code, notes, and snippets.

@kartikkukreja
Last active August 29, 2015 14:24
Show Gist options
  • Save kartikkukreja/99417a4262433e456697 to your computer and use it in GitHub Desktop.
Save kartikkukreja/99417a4262433e456697 to your computer and use it in GitHub Desktop.
Minimax search.py
def value(problem, state, player):
if problem.isTerminalState(state): return problem.getTerminalUtility(state)
if player == "MAX": return maxValue(problem, state, player)
if player == "MIN": return minValue(problem, state, player)
def maxValue(problem, state, player):
v = -infinity
for successor in problem.getSuccessors(state):
v = max(v, value(problem, successor, "MIN"))
return v
def minValue(problem, state, player):
v = +infinity
for successor in problem.getSuccessors(state):
v = min(v, value(problem, successor, "MAX"))
return v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment