C463 / B551 Artificial Intelligence

Adversarial Search

Adversarial Search

Game Problem Setup

Minmax

Minmax

Example: Sticks Game

The players have piles of sticks. They can remove any number of sticks from any one pile. The one removing the last stick loses.

Minmax Algorithm

; Lisp version
def minmax(n, what):
  if n is a terminal node:
    return its score
  else:
    compute the score of all of
    its children using 1-what
    if what == 1:
      return the max score of the children
    else:
      return the min score of the children

# Python version
(defun minmax (n, what)
  (if (terminalp n) (score n)
    (let ((scores nil))
      (dolist (s (expand n))
	      (push (cons s 
               (minmax s (- 1 what)))
          scores))
      (if (= what 1) (max scores)
        (min scores)))))

Alpha-Beta

Alpha-Beta

Alpha-Beta for a MAX node

def MAX_AB (N, A, B):
  if N is a leaf: 
    return its score;
  else: 
    alpha = -infinity 
    for each successor S of N :
      val = MIN_AB(S, max(A, alpha), B) 
      if val > alpha:
        alpha = val 
      if alpha >= B: ]: #prune the subtree
        return alpha 
    return alpha

Alpha-Beta for a MIN node

def MIN_AB (N, A, B):
  if N is a leaf :
    return its score
  else :
    beta = +infinity 
    for each successor S of N:
      val = MAX_AB(S, A, min(B, beta)) 
      if val < beta:
        beta = val
      if A >= beta: #prune the subtree
        return beta 
    return beta

Example:
+infinity = 20, -infinity = -20

Pruning a min subtree

Applet: http://www.ocf.berkeley.edu/~yosenl/extras/alphabeta/alphabeta.html
->
As 3 < 7, we know the opponent will choose something equal or smaller, so we can discard the rest of the tree because we already have a better move (7).

Pruning a max subtree
When we find 8 at the bottom, the parent was (-15, -3) and 8 replaces -15. As 8 > -3 we update alpha of the parent (the red node above), and it becomes (8, -3) before. Since that is the opponent, it will notice that we got a better move and not give us a chance to take it. So the opponent discards that node, which means that we don't have to evaluate the rest of the subtree. Since this was the last green child at this level, we can finalize the red node above with alpha = beta = -3.

Cutoff Methods

Cutoff

Games Involving Chance

Othello

Legal Moves
->

Heuristic Payoff