Adversarial Search

Minimax, alpha-beta pruning, and expectimax

Open in Colab
## Minimax Pseudocode function minimax(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, minimax(child, depth − 1, FALSE)) return value else (* minimizing player *) value := +∞ for each child of node do value := min(value, minimax(child, depth − 1, TRUE)) return value ## alpha-beta pruning Pseudocode # alpha: MAX nodes best option on the path to root # beta: MIN nodes best option on the path to root def max-value(state, α, β): initialize v = -∞ for each successor of state: v = max(v,min-value(successor, α, β)) if v ≥ β return v # new line: pruning α = max(α, v) # new line: updating alpha return v def min-value(state, α, β): initialize v = +∞ for each successor of state: v = min(v, max-value(successor, α, β)) if v ≤ α return v # new line: pruning β = min(β, v) # new line: updating alpha return v ## Expectimax Pseudocode def value(state): If the state is a terminal state: return the state's utility If the next agent is MAX: return max-value(state) If the next agent is EXP: return exp-value(state) def max-value(state): initialize v = - inf for each successor of state: v = max(v, value(successor)) return v def exp-value(state): initialize v = 0 for each successor of state: p = probability(successor) v += p * value(successor) return v

Hossein Aghamohammadi

Supervisor