adversarial*search* - northeastern universitychess checkers go othello! baleship! mastermind!...

36
Adversarial Search Chapter 5 (acknowledgement goes to Gillian Smith(NEU) and Hwee Tou Ng’s for slides used in this lecture)

Upload: others

Post on 23-Feb-2021

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

ì  Adversarial  Search  Chapter  5  (acknowledgement  goes  to  Gillian  Smith(NEU)  and  Hwee  Tou  Ng’s  for  slides  used  in  this  lecture)  

Page 2: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Game  Playing  

Perfect  Informa-on   Imperfect  Informa-on  

Determinis-c  

Chess  Checkers  

Go  Othello  

Ba2leship  Mastermind  

Stochas-c  Backgammon  Monopoly  

Snakes  and  Ladders  

Poker  Bridge  Scrabble  Civiliza@on  

Page 3: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Game  Playing  

Perfect  Informa-on   Imperfect  Informa-on  

Determinis-c  

Chess  Checkers  

Go  Othello  

Ba2leship  Mastermind  

Stochas-c  Backgammon  Monopoly  

Snakes  and  Ladders  

Poker  Bridge  Scrabble  Civiliza@on  

Page 4: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Game  Playing  

Perfect  Informa-on   Imperfect  Informa-on  

Determinis-c  

Chess  Checkers  

Go  Othello  

Ba2leship  Mastermind  

Stochas-c  Backgammon  Monopoly  

Snakes  and  Ladders  

Poker  Bridge  Scrabble  Civiliza@on  

Page 5: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Game  Playing  

Perfect  Informa-on   Imperfect  Informa-on  

Determinis-c  

Chess  Checkers  

Go  Othello  

Ba2leship  Mastermind  

Stochas-c  Backgammon  Monopoly  

Snakes  and  Ladders  

Poker  Bridge  Scrabble  Civiliza@on  

Page 6: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Game  Playing  

Perfect  Informa-on   Imperfect  Informa-on  

Determinis-c  

Chess  Checkers  

Go  Othello  

Ba2leship  Mastermind  

Stochas-c  Backgammon  Monopoly  

Snakes  and  Ladders  

Poker  Bridge  Scrabble  Civiliza@on  

Page 7: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Minimax  Algorithm  

ì  Two  player,  adversarial,  perfect  informa@on  game  ì  Tic  Tac  Toe  ì  Nim  ì  Chess  ì  Go  

ì  Two  players:  MAX  and  MIN  ì  MAX  moves  first  

Page 8: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Game tree (2-player, deterministic, turns)

How do we search this tree to find the optimal move?

Page 9: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

ì  Idea: choose a move to a position with the highest minimax value = best achievable payoff against a rational opponent.

ì  Example: deterministic 2-ply game:

Minimax

minimax value Minimax value is computed bottom up: -Leaf values are given. -3 is the best outcome for MIN in this branch. -3 is the best outcome for MAX in this game. -We explore this tree in depth-first manner.

Page 10: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Minimax:  Small  Example  

Page 11: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Minimax:  Small  Example  

Page 12: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Minimax:  Small  Example  

Page 13: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Minimax:  Small  Example  

Page 14: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Minimax:  Small  Example  

Page 15: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Minimax:  Small  Example  

Page 16: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Properties of minimax

ì  Complete? Yes (if tree is finite)

ì  Optimal? Yes (against an rational opponent)

ì  Time complexity? O(bm)

ì  Space complexity? O(bm) (depth-first exploration)

ì  For chess, b ≈ 35, m ≈100 for "reasonable" games à exact solution completely infeasible

Page 17: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Pruning

1.  Do we need to expand all nodes?

2. No: We can do better by pruning branches that will not lead to success.

α β−

Page 18: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

α-β pruning ex.

MAX knows that it can at least get “3” by playing this branch

MIN will choose “3”, because it minimizes the utility (which is good for MIN)

Page 19: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

α-β pruning example

MIN can certainly do as good as 2, but maybe better (= smaller)

MAX knows that the new branch will never be better than 2 for him. He can ignore it.

Page 20: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

α-β pruning example

MIN will do at least as good as 14 in this branch (which is very good for MAX!) so MAX will want to explore this branch more.

Page 21: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

α-β pruning example

MIN will do at least as good as 5 in this branch (which is still good for MAX) so MAX will want to explore this branch more.

Page 22: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

α-β pruning example

Bummer (for MAX): MIN will be able to play this last branch and get 2. This is worse than 3, so MAX will play 3.

Page 23: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Properties of α-β

ì  Pruning does not affect final result (it is exact).

ì  Order is important

ì  With "perfect ordering," time complexity = O(bm/2) à doubles depth of search

Page 24: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

The Algorithm

ì  Visit the nodes in a depth-first manner

ì  Maintain bounds on nodes.

ì  A bound may change if one of its children obtains a unique value.

ì  A bound becomes a unique value when all its children have been checked or pruned.

ì  When a bound changes into a tighter bound or a unique value, it may become inconsistent with its parent.

ì  When an inconsistency occurs, prune the sub-tree by cutting the edge between the inconsistent bounds/values.

à This is like propagating changes bottom-up in the tree.

Page 25: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Practical Implementation

How do we make this practical?

Standard approach:

ì  cutoff test: (where do we stop descending the tree) ì  depth limit ì  better: iterative deepening ì  cutoff only when no big changes are expected to

occur next (quiescence search).

Page 26: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Practical Implementation

ì  evaluation function/heuristics ì  When the search is cut off, we evaluate the current state by estimating its utility. This estimate is captured by the evaluation function. ì  Run α-β pruning minimax with these estimated values at

the leaves instead.

Page 27: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Evaluation functions

ì  For chess, typically linear weighted sum of features

Eval(s) = w1 f1(s) + w2 f2(s) + … + wn fn(s)

ì  e.g., w1 = 9 with

f1(s) = (number of white queens) – (number of black queens), etc.

Page 28: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Forward Pruning & Lookup

ì  Humans don’t consider all possible moves.

ì  Can we prune certain branches immediately?

ì  “ProbCut” estimates (from past experience) the uncertainty in the estimate of the node’s value and uses that to decide if a node can be pruned.

ì  Instead of search one can also store game states.

ì  Openings in chess are played from a library

Page 29: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

In  Practice  

Perfect  Informa-on   Imperfect  Informa-on  

Determinis-c  

Chess  Checkers  

Go  Othello  

Ba2leship  Mastermind  

Stochas-c  Backgammon  Monopoly  

Snakes  and  Ladders  

Poker  Bridge  Scrabble  Civiliza@on  

Page 30: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Deterministic games in practice

ì  Checkers: Chinook defeated champion in 1990 (Schaeffer)

ì  Chess: Deep Blue defeated human world champion Garry Kasparov in a six-game match in 1997.

ì  Othello: Logistello (Buro 2002) beat champion

ì  Poker: Machine was better than best human poker players in 2008.

Page 31: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

What  about  chance  games?    

Perfect  Informa-on   Imperfect  Informa-on  

Determinis-c  

Chess  Checkers  

Go  Othello  

Ba2leship  Mastermind  

Stochas-c  Backgammon  Monopoly  

Snakes  and  Ladders  

Poker  Bridge  Scrabble  Civiliza@on  

Page 32: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Chance Games

Backgammon

your element of chance

Page 33: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Expected Minimax

( ) Minimax( )

3 0.5 4 0.5 2chance nodes

v P n n= ×

= × + ×

Again, the tree is constructed bottom-up.

Now we have even more nodes to search!

Page 34: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

What  about  imperfect  Information?  

Perfect  Informa-on   Imperfect  Informa-on  

Determinis-c  

Chess  Checkers  

Go  Othello  

Ba2leship  Mastermind  

Stochas-c  Backgammon  Monopoly  

Snakes  and  Ladders  

Poker  Bridge  Scrabble  Civiliza@on  

Page 35: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Class  Assignment  

ì  Blackjack,  see  h2p://en.wikipedia.org/wiki/Blackjack  

ì  First  iden@fy  if  the  game  is  determinis@c/stochas@c,  with  perfect  or  imperfect  informa@on  

ì  Then  figure  out  an  algorithm  to  develop  it  

ì  When  you  are  done,  write  it  up  and  call  me  to  discuss  

Page 36: Adversarial*Search* - Northeastern UniversityChess Checkers Go Othello! Baleship! Mastermind! Stochasc’ Backgammon! Monopoly! Snakes!and!Ladders! Poker Bridge Scrabble! Civilizaon

Class  Assignment  

ì  Read    

h2p://www.eng.ysu.edu/~drwallac/ENGR1550AU10/ENGR%201550%20-­‐%20IE%20Blackjack%20Lab.pdf