Skip to content

Instantly share code, notes, and snippets.

@kartikkukreja
Created August 8, 2015 17:47
Show Gist options
  • Save kartikkukreja/eb94dc3a934a0f34060c to your computer and use it in GitHub Desktop.
Save kartikkukreja/eb94dc3a934a0f34060c to your computer and use it in GitHub Desktop.
Expectimax Search
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