0% found this document useful (0 votes)
60 views21 pages

Week15 16 PDF

The document discusses adversarial search and game theory in artificial intelligence. It covers topics like games, optimal decisions in games, the minimax algorithm, and alpha-beta pruning. Games are defined as search problems with elements like initial state, players, legal actions, transition models, terminal tests, and utility functions. The minimax algorithm is introduced as a way to make optimal decisions in two-player zero-sum games by choosing the move that maximizes the minimum payoff against an optimal opponent. It works by searching the game tree to evaluate positions and choosing the move that leaves the opponent with the least damaging options.

Uploaded by

Preti Arora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views21 pages

Week15 16 PDF

The document discusses adversarial search and game theory in artificial intelligence. It covers topics like games, optimal decisions in games, the minimax algorithm, and alpha-beta pruning. Games are defined as search problems with elements like initial state, players, legal actions, transition models, terminal tests, and utility functions. The minimax algorithm is introduced as a way to make optimal decisions in two-player zero-sum games by choosing the move that maximizes the minimum payoff against an optimal opponent. It works by searching the game tree to evaluate positions and choosing the move that leaves the opponent with the least damaging options.

Uploaded by

Preti Arora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Ar#ficial

 Intelligence  
Dr.  Qaiser  Abbas  
Department  of  Computer  Science  &  IT,    
University  of  Sargodha,  Sargodha,  40100,  Pakistan  
[email protected]  
 

Saturday  16  May  20   1  


ADVERSARIAL  SEARCH  
•  In  which  we  examine  the  problems  that  arise  when  we  try  to  plan  
ahead  in  a  world  where  other  agents  are  planning  against  us.    

•  In  this  lecture  we  will  cover  compe##ve  environments,  in  which  


the  agents’  goals  are  in  conflict,  giving  rise  to  adversarial  search  
problems—oOen  known  as  games.    

•  We  will  cover  the  followings:    


–  GAMES    
–  OPTIMAL  DECISIONS  IN  GAMES    
–  MiniMax  Algorithm  
–  ALPHA–BETA  PRUNING    

Saturday  16  May  20   2  


Games  
•  A  game  can  be  defined  as  a  search  problem  with  the  
following  elements:  

–   S0:  Ini#al  state  which  specifies  how  the  game  is  


set  up  at  the  start.  

–  PLAYER(s):  Defines  which  player  has  the  move  in  a  


state  s.  

–  ACTIONS(s):  Returns  set  of  legal  moves  in  a  state  


s.  
Saturday  16  May  20   3  
Games  
–  RESULT(s,a):  The  transi#on  model  defines  the  
result  of  a  move  from  state  s  with  ac^on  a.  

–  TERMINAL-­‐TEST(s):  A  terminal  test  at  a  state  s,  


which  is  true  when  the  game  is  over  and  false  
otherwise.    

–  U  T  I  L  I  T  Y  (s,  p):  A  u#lity  func#on  also  called  an  


objec^ve  func^on  or  payoff  func^on,  defines  the  
final  numeric  value  for  a  game  that  ends  in  
terminal  state  s  for  a  player  p.    
Saturday  16  May  20   4  
Games  
•  The  ini^al  state,  ACTIONS  func^on,  and  RESULT  func^on  define  the  game  
tree—a  tree  where  the  nodes  are  game  states  and  the  edges  are  moves.  
Figure  shows  part  of  the  game  tree  for  Tic-­‐Tac-­‐Toe.    

Saturday  16  May  20   5  


Simple  Approach  in  Tic-­‐Tac-­‐Toe  
•  In  simple  algorithm,  calculate  all  the  possible  moves  from  the  
current  posi^on.  For  a  game  of  Noughts  and  Crosses  the  
result  might  look  like:    

•  Expand  each  of  these  new  possible  moves  for  the  other  
player.  
•  Con^nue  this  expansion  un^l  a  winning  posi^on  for  the  player  
is  found.    
Saturday  16  May  20   6  
Simple  Approach  in  Tic-­‐Tac-­‐Toe  

 
–  This  algorithm  will  work  and  locate  a  series  of  winning  
moves  at  the  cost  of  enormous  calcula^on  e.g.  one  board  
at  first,  9  at  the  next  level,  9∗8  next  and  so  on.  In  total:    
 

–  This  is  not  so  big  that  we  cannot  calculate  it,  but  it  is  
alarming  since  Noughts  and  Crosses  is  such  a  simple  game.    
Saturday  16  May  20   7  
OPTIMAL  DECISIONS  IN  GAMES  
•  An  op^mal  strategy  leads  to  outcomes  at  least  as  good  as  any  
other  strategy  when  one  is  playing  an  infallible  opponent.    
•  Two  Player  Games:  
–  Consider  a  Zero-­‐Sum  game  in  which  gain  of  one  player  is  
balanced  exactly  by  the  loss  of  other  player.  
–  Sta^c  Evalua^on  Func^on  f(n)  =  Complete  R/C/D  open  
posi^ons  for  X  –  Complete  R/C/D  open  posi^ons  for  O  

Saturday  16  May  20   8  


OPTIMAL  DECISIONS  IN  GAMES  
–  Higher  the  result  of  f(n),  the  closer  the  move  towards  a  win.  Three  
moves  result  in  3  but  only  one  move  results  a  win  for  X  in  Figure.  

–  This  f(n)  is  useful  but  another  heuris^cs  is  necessary  to  pick  the  move  
with  highest  f(n)  while  protec^ng  against  a  loss  in  the  next  move.    

–  For  this  purpose,  a  Minimax  algorithm  given  next,  in  which  the  
algorithm's  opponent  will  be  trying  to  minimize  whatever  value  the  
algorithm  is  trying  to  maximize  (hence,  ”Minimax").    

–  Thus,  the  computer  should  make  the  move  which  leaves  its  opponent  
capable  of  doing  the  least  damage.  

Saturday  16  May  20   9  


Minimax  algorithm    
•  Minimax  uses  one  of  the  two  basic  strategies:  

–  En^re  game  tree  is  searched  to  the  leaf  nodes  


–  Tree  is  searched  to  a  predefined  depth  and  then  
evaluated.  

•  Can  pursue  the  tree  by  making  guesses  as  to  how  
the  opponent  will  play.    

•  Cost  func#on  can  be  used  to  evaluate  how  the  


opponent  is  likely  to  play.    

Saturday  16  May  20   10  


Minimax  algorithm    
•  AOer  evalua^ng  some  number  of  moves  ahead  
we  examine  the  total  value  of  the  cost  to  each  
player.    

•  The  goal  is  to  find  a  move  which  will  maximize  


the  value  of  our  move  and  will  minimize  the  
value  of  the  opponents  moves.    

•  The  algorithm  used  is  the  Minimax  search  


procedure  presented  next.    

Saturday  16  May  20   11  


The  Minimax  algorithm    

Saturday  16  May  20   12  


Par#al  Example  Tree  For  Minimax  
Algorithm  

Saturday  16  May  20   13  


ALPHA–BETA  PRUNING    
•  Minimax  search  is  exponen^al  like  DFS  and  
couldn’t  be  eliminated  but  can  be  effec^vely  cut  
in  half.    

•  Idea  of  Pruning  to  eliminate  large  parts  of  the  


tree  can  be  used  and  the  par^cular  technique  we  
examine  is  called  Alpha–Beta  Pruning.    

•  When  applied  to  a  standard  Minimax  tree,  it  


returns  the  same  move  as  Minimax  would,  but  
prunes  away  branches  that  cannot  possibly  
influence  the  final  decision.    
Saturday  16  May  20   14  
ALPHA–BETA  PRUNING    
•  Consider,  the  two-­‐ply  game  tree  from  Figure  
given  next.    
•  Let’s  go  through  the  calcula^on  of  the  op^mal  
decision  once  more,  this  ^me  paying  careful  
aqen^on  to  what  we  know  at  each  point  in  
the  process.    

Saturday  16  May  20   15  


ALPHA–BETA  PRUNING    

Saturday  16  May  20   16  


ALPHA–BETA  PRUNING    
•  Idea  of  pruning  aOer  applying  it  on  the  previous  figure  is  described  
below  .  No  need  to  evaluate  two  successors  of  node  C.  

•  Suppose  they  have  values  x  and  y.  Then  the  value  of  the  root  is:    
–  MINIMAX(root)    =  Max(Min(3,12,8),Min(2,x,y),Min(14,5,2))    
     =  Max(3,Min(2,x,y),2)    
     =  Max(3,z,2)  where  z  =  Min(2,x,y)  ≤  2    
     =  3.    

•  Alpha–beta  pruning  can  be  applied  to  trees  of  any  depth,  and  it  is  
oOen  possible  to  prune  en^re  subtrees  rather  than  just  leaves.    
–  α  =  the  value  of  the  best  (i.e.,  highest-­‐value)  choice  we  have  found  so  
far  at  any  choice  point  along  the  path  for  MAX.    
–  β  =  the  value  of  the  best  (i.e.,  lowest-­‐value)  choice  we  have  found  so  
far  at  any  choice  point  along  the  path  for  MIN.    

•  The  detailed  steps  are  explained  in  Figure  next.    


Saturday  16  May  20   17  
ALPHA–BETA  PRUNING    

Saturday  16  May  20   18  


ALPHA–BETA  PRUNING    
•  Alpha–beta  search  updates  the  values  of  α  and  β  
as  it  goes  along  and  prunes  the  remaining  
branches  at  a  node  (i.e.,  terminates  the  recursive  
call)  as  soon  as  the  value  of  the  current  node  is  
known  to  be  worse  than  the  current  α  or  β  value  
for  MAX  or  MIN,  respec^vely.    

•  The  complete  algorithm  is  given  next.  It  will  be  


good  to  trace  its  behavior  when  applied  to  the  
tree  in  Figure.    
Saturday  16  May  20   19  
ALPHA–BETA  PRUNING    

Saturday  16  May  20   20  


Lab  Project  #7  
•  Implement  the  Tic-­‐Tac-­‐Toe  game  using  any  
adversarial  searching  algorithm  
–  Visit  the  following  link:  
hqps://www.geeksforgeeks.org/minimax-­‐algorithm-­‐
in-­‐game-­‐theory-­‐set-­‐3-­‐^c-­‐tac-­‐toe-­‐ai-­‐finding-­‐op^mal-­‐
move/  
–  Perform  the  following  opera^ons  over  it.    
–  Download  it.  
–  Configure  and  execute  it.  
–  Submit  the  final  report.  

Saturday  16  May  20   21  

You might also like