Created
August 8, 2015 17:47
-
-
Save kartikkukreja/eb94dc3a934a0f34060c to your computer and use it in GitHub Desktop.
Expectimax Search
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): | |
if problem.isTerminalState(state): return problem.getTerminalUtility(state) | |
if state is a MAX node: return maxValue(problem, state) | |
if state is a MIN node: return minValue(problem, state) | |
if state is an EXP node: return expValue(problem, state) | |
def expValue(problem, state): | |
v = 0 | |
for successor in problem.getSuccessors(state): | |
v += problem.getProbability(state, successor) * value(problem, successor) | |
return v | |
def maxValue(problem, state): | |
v = -infinity | |
for successor in problem.getSuccessors(state): | |
v = max(v, value(problem, successor)) | |
return v | |
def minValue(problem, state): | |
v = +infinity | |
for successor in problem.getSuccessors(state): | |
v = min(v, value(problem, successor)) | |
return v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment