Last active
August 29, 2015 14:24
-
-
Save kartikkukreja/99417a4262433e456697 to your computer and use it in GitHub Desktop.
Minimax search.py
This file contains hidden or 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
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