SlideShare uma empresa Scribd logo
1 de 67
Adversarial Search and
           Game Playing


(Where making good decisions requires respecting your opponent)




                 Dr. Ali Abdallah
         (dr_ali_abdallah@hotmail.com)
 Games like Chess or Go are compact
  settings which involve uncertainty and
  interaction
 For centuries humans have used them to
  exert their intelligence
 Recently, there has been great success in
  building game programs that challenge
  human supremacy
Uncertainty
 uncertainty is caused by the actions of another agent
  (MIN), which competes with our agent (MAX)
Uncertainty
 Here, uncertainty is caused by the actions of another
  agent (MIN), which competes with our agent (MAX)
 MIN wants MAX to fail (and vice versa)
 No plan exists that guarantees MAX’s success
  regardless of which actions MIN executes (the same
  is true for MIN)
 At each turn, the choice of which action to perform
  must be made within a specified time limit
 The state space is enormous: only a tiny fraction of
  this space can be explored within the time limit
Specific Setting
     Two-player, turn-taking, deterministic, fully
    observable, time-constrained game

   State space
   Initial state
   Successor function: it tells which actions can be
    executed in each state and gives the successor
    state for each action
   MAX’s and MIN’s actions alternate, with MAX
    playing first in the initial state
   Terminal test: it tells if a state is terminal and,
    if yes, if it’s a win or a loss for MAX, or a draw
   All states are fully observable
Game Tree
                               MAX nodes

MAX’s play →

                                           MIN nodes
MIN’s play →




                  Here, symmetries have been used
                  to reduce the branching factor
Terminal state
(win for MAX) →
Game Tree

MAX’s play →



MIN’s play →



                  In general, the branching
                  factor and the depth of
                  terminal states are large
                  Chess:
                  • Number of states: ~1040
Terminal state
                  • Branching factor: ~35
(win for MAX) →   • Number of total moves
                    in a game: ~100
Choosing an Action: Basic Idea
• Using the current state as the initial
    state, build the game tree uniformly to
    the maximal depth h (called horizon)
    feasible within the time limit
•   Evaluate the states of the leaf nodes
•   Back up the results from the leaves to
    the root and pick the best action
    assuming the worst from MIN
→ Minimax algorithm
Evaluation Function
 Function e: state s → number e(s)
 e(s) is a heuristics that estimates how
  favorable s is for MAX
 e(s) > 0 means that s is favorable to MAX
  (the larger the better)
 e(s) < 0 means that s is favorable to MIN
 e(s) = 0 means that s is neutral
Example: Tic-tac-Toe
   e(s) = number of rows, columns,
   and diagonals open for MAX
          − number of rows, columns,
          and diagonals open for MIN




    8−8 = 0       6−4 = 2       3−3 = 0
Construction of an
Evaluation Function
 Usually a weighted sum of “features”:
                       n
                e(s)=∑ wif(s)
                          i
                       i=1

 Features may include
     Number of pieces of each type
     Number of possible moves
     Number of squares controlled
Backing up Values
Tic-Tac-Toe tree                             1
  at horizon = 2                                        Best move


               -1                                                            1

                                                   -2

 6-5=1 5-5=0 6-5=1 5-5=1 4-5=-1                                      5-4=1 6-4=2




                                  5-6=-1 5-5=0 5-6=-1 6-6=0 4-6=-2
Continuation
                     1                               1


                                 0
 2   1   3   1   2   1


                                             1
             1   0   2   0   1   1


                                                             0
                         2   2   3   1   2       2



                                                     1   1   0
Why using backed-up values?

 At each non-leaf node N, the backed-up
  value is the value of the best state that
  MAX can reach at depth h if MIN plays
  well (by the same criterion as MAX
  applies to itself)
 If e is to be trusted in the first place,
  then the backed-up value is a better
  estimate of how favorable STATE(N) is
  than e(STATE(N))
Minimax Algorithm
1. Expand the game tree uniformly from the current
     state (where it is MAX’s turn to play) to depth h
2.   Compute the evaluation function at every leaf of
     the tree
3.   Back-up the values from the leaves to the root of
     the tree as follows:
      A MAX node gets the maximum of the evaluation of its
       successors
      A MIN node gets the minimum of the evaluation of its
       successors
4. Select the move toward a MIN node that has the
     largest backed-up value
Game Playing (for MAX)

Repeat until a terminal state is reached
2. Select move using Minimax
3. Execute move
4. Observe MIN’s move
Note that at each cycle the large game tree built to
horizon h is used to select only one move
All is repeated again at the next cycle (a sub-tree of
depth h-2 can be re-used)
Can we do better?

Yes ! Much better !
                     ≥ 3




     3        ≤ -1


                           ← Pruning
                                This part of the tree can’t
         -1
                                have any effect on the value
                                that will be backed up to the
                                root
Example
Example


                The beta value of a MIN
                node is an upper bound on
          β=2   the final backed-up value.
                It can never increase




  2
Example


                    The beta value of a MIN
                    node is an upper bound on
          β=1       the final backed-up value.
                    It can never increase




  2             1
Example
                        α=1


                    The alpha value of a MAX
                    node is a lower bound on
          β=1       the final backed-up value.
                    It can never decrease




  2             1
Example
                    α=1




          β=1                  β = -1




  2             1         -1
Example
                                        α=1




                      β=1                          β = -1

Search can be discontinued below
any MIN node whose beta value is
less than or equal to the alpha value
of one of its MAX ancestors
      2                      1                -1
Alpha-Beta Pruning

 Explore the game tree to depth h in
  depth-first manner
 Back up alpha and beta values whenever
  possible
 Prune branches that can’t lead to
  changing the final decision
Alpha-Beta Algorithm

 Update the alpha/beta value of the parent of
    a node N when the search below N has been
    completed or discontinued
   Discontinue the search below a MAX node N
    if its alpha value is ≥ the beta value of a MIN
    ancestor of N
   Discontinue the search below a MIN node N if
    its beta value is ≤ the alpha value of a MAX
    ancestor of N
Example




    0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example




   0




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example




         0



   0




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example




         0



   0     -3




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example




         0



   0     -3




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example




               0



         0



   0     -3




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example




               0



         0         3



   0     -3   3




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example




               0



         0         3



   0     -3   3




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example

                           0


                       0


               0



         0         3



   0     -3   3




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example

                           0


                       0


               0



         0         3



   0     -3   3                5




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example

                           0


                       0


               0



         0         3               2



   0     -3   3                2




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example

                           0


                       0


               0



         0         3               2



   0     -3   3                2




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example

                           0


                       0           2


               0           2



         0         3                   2



   0     -3   3                2




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example

                           0


                       0           2


               0           2



         0         3                   2



   0     -3   3                2




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example
                                           0


                           0


                       0           2


               0           2



         0         3                   2



   0     -3   3                2




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example
                                           0


                           0


                       0           2


               0           2



         0         3                   2



   0     -3   3                2               5




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example
                                           0


                           0


                       0           2


               0           2



         0         3                   2           1



   0     -3   3                2               1




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example




    0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5
Example
                                           0


                           0


                       0           2           1


               0           2                   1



         0         3                   2           1



   0     -3   3                2               1   -3   -5




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example
                                           0


                           0


                       0           2           1


               0           2                   1



         0         3                   2           1



   0     -3   3                2               1   -3   -5




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example
                                           0


                           0


                       0           2           1


               0           2                   1        -5



         0         3                   2           1    -5



   0     -3   3                2               1   -3   -5




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example
                                           0


                           0


                       0           2           1


               0           2                   1        -5



         0         3                   2           1    -5



   0     -3   3                2               1   -3   -5




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example
                                           1


                           0                        1


                       0           2           1


               0           2                   1        -5



         0         3                   2           1    -5



   0     -3   3                2               1   -3   -5




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example
                                           1


                           0                        1


                       0           2           1             2


               0           2                   1        -5       2



         0         3                   2           1    -5           2



   0     -3   3                2               1   -3   -5           2




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
Example
                                           1


                           0                        1


                       0           2           1             2


               0           2                   1        -5       2



         0         3                   2           1    -5           2



   0     -3   3                2               1   -3   -5           2




       0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
How much do we gain?

Consider these two cases:
                      α=3                      α=3




3        β=-1               3       β=4




    -1          (4)                       -1
                                4
How much do we gain?
   Assume a game tree of uniform branching factor b
   Minimax examines O(bh) nodes, so does alpha-beta in
    the worst-case
   The gain for alpha-beta is maximum when:
     • The MIN children of a MAX node are ordered in decreasing
       backed up values
     • The MAX children of a MIN node are ordered in increasing
       backed up values
 Then alpha-beta examines O(bh/2) nodes [Knuth and Moore, 1975]
 But this requires an oracle (if we knew how to order nodes
    perfectly, we would not need to search the game tree)
 If nodes are ordered at random, then the average
    number of nodes examined by alpha-beta is ~O(b3h/4)
Heuristic Ordering of Nodes

 Order the nodes below the root according to
 the values backed-up at the previous iteration

 Order MAX (resp. MIN) nodes in decreasing
 (increasing) values of the evaluation function e
 computed at these nodes
Other Improvements

 Adaptive horizon + iterative deepening
 Extended search: Retain k>1 best paths,
    instead of just one, and extend the tree at
    greater depth below their leaf nodes to (help
    dealing with the “horizon effect”)
   Singular extension: If a move is obviously
    better than the others in a node at horizon h,
    then expand this node along this move
   Use transposition tables to deal with
    repeated states
   Null-move search
State-of-the-Art
Checkers: Tinsley vs. Chinook
                                Name:        Marion Tinsley
                                Profession: Teach mathematics
                                Hobby:       Checkers
                                Record:      Over 42 years
                                loses only 3 games     of
                                checkers
                                World champion for over 40
                                years




Mr. Tinsley suffered his 4th and 5th losses against Chinook
Chinook




 First computer to become official world champion of Checkers!
Chess: Kasparov vs. Deep Blue
Kasparov                                          Deep Blue

5’10”                    Height                        6’ 5”
176 lbs                 Weight                    2,400 lbs
34 years                  Age                       4 years
50 billion neurons     Computers        32 RISC processors
                                   + 256 VLSI chess engines
2 pos/sec                 Speed        200,000,000 pos/sec
Extensive               Knowledge                  Primitive
Electrical/chemical   Power Source                Electrical
Enormous                   Ego                         None

 1997: Deep Blue wins by 3 wins, 1 loss, and 2 draws
Chess: Kasparov vs. Deep Junior


                                          Deep Junior

                           8 CPU, 8 GB RAM, Win 2000
                                    2,000,000 pos/sec
                                     Available at $100




     August 2, 2003: Match ends in a 3/3 tie!
Othello: Murakami vs. Logistello




                       Takeshi Murakami
                       World Othello Champion


  1997: The Logistello software crushed Murakami
  by 6 games to 0
Go: Goemate vs. ??
          Name: Chen Zhixing
          Profession: Retired
          Computer skills:
             self-taught programmer
          Author of Goemate (arguably the
             best Go program available today)

          Gave Goemate a 9 stone
          handicap and still easily
          beat the program,
          thereby winning $15,000
Go: Goemate vs. ??
             Name: Chen Zhixing
             Profession: Retired
             Computer skills:
                self-taught programmer
   Go has too high a branching factor
             Author of Goemate (arguably the
   for existing search techniques
                strongest Go programs)
   Current and future software must
   rely on huge databasesaand pattern-
             Gave Goemate 9 stone
             handicap and still easily
   recognition techniques
             beat the program,
             thereby winning $15,000
Secrets
 Many game programs are based on alpha-beta +
  iterative deepening + extended/singular search +
  transposition tables + huge databases + ...

 For instance, Chinook searched all checkers
  configurations with 8 pieces or less and created an
  endgame database of 444 billion board
  configurations

 The methods are general, but their implementation
  is dramatically improved by many specifically
  tuned-up enhancements (e.g., the evaluation
  functions) like an F1 racing car
Perspective on Games: Con and Pro

Chess is the Drosophila of           Saying Deep Blue doesn’t
artificial intelligence. However,     really think about chess
computer chess has developed          is like saying an airplane
much as genetics might have if      doesn't really fly because
the geneticists had concentrated     it doesn't flap its wings.
their efforts starting in 1910 on
                                                Drew McDermott
breeding racing Drosophila. We
would have some science, but
mainly we would have very fast
fruit flies.
               John McCarthy
Other Types of Games
 Multi-player games, with alliances or not
 Games with randomness in successor
  function (e.g., rolling a dice)
   Expectminimax algorithm
 Games with partially observable states
  (e.g., card games)
   Search of belief state spaces

See R&N p. 175-180

Mais conteúdo relacionado

Semelhante a 05 adversarial

Juegos minimax AlfaBeta
Juegos minimax AlfaBetaJuegos minimax AlfaBeta
Juegos minimax AlfaBetanelsonbc20
 
The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184Mahmoud Samir Fayed
 
AI subject - Game Theory and cps ppt pptx
AI subject  - Game Theory and cps ppt pptxAI subject  - Game Theory and cps ppt pptx
AI subject - Game Theory and cps ppt pptxnizmishaik1
 
The Ring programming language version 1.9 book - Part 69 of 210
The Ring programming language version 1.9 book - Part 69 of 210The Ring programming language version 1.9 book - Part 69 of 210
The Ring programming language version 1.9 book - Part 69 of 210Mahmoud Samir Fayed
 
Game and Search
Game and SearchGame and Search
Game and SearchAdri Jovin
 
cs-171-07-Games and Adversarila Search.ppt
cs-171-07-Games and Adversarila Search.pptcs-171-07-Games and Adversarila Search.ppt
cs-171-07-Games and Adversarila Search.pptSamiksha880257
 
Calculo Thomas (Solutions).pdf
Calculo Thomas  (Solutions).pdfCalculo Thomas  (Solutions).pdf
Calculo Thomas (Solutions).pdfadriano65054
 
The Ring programming language version 1.7 book - Part 64 of 196
The Ring programming language version 1.7 book - Part 64 of 196The Ring programming language version 1.7 book - Part 64 of 196
The Ring programming language version 1.7 book - Part 64 of 196Mahmoud Samir Fayed
 
Minmax and alpha beta pruning.pptx
Minmax and alpha beta pruning.pptxMinmax and alpha beta pruning.pptx
Minmax and alpha beta pruning.pptxPriyadharshiniG41
 
Global and local alignment (bioinformatics)
Global and local alignment (bioinformatics)Global and local alignment (bioinformatics)
Global and local alignment (bioinformatics)Pritom Chaki
 
ch_5 Game playing Min max and Alpha Beta pruning.ppt
ch_5 Game playing Min max and Alpha Beta pruning.pptch_5 Game playing Min max and Alpha Beta pruning.ppt
ch_5 Game playing Min max and Alpha Beta pruning.pptSanGeet25
 
Graphical Method
Graphical MethodGraphical Method
Graphical MethodSachin MK
 
Algebra 2 Section 2-5
Algebra 2 Section 2-5Algebra 2 Section 2-5
Algebra 2 Section 2-5Jimbo Lamb
 
9SearchAdversarial (1).pptx
9SearchAdversarial (1).pptx9SearchAdversarial (1).pptx
9SearchAdversarial (1).pptxumairshams6
 
7.3_Nonlinear Programming-LagrangeExamples.pptx
7.3_Nonlinear Programming-LagrangeExamples.pptx7.3_Nonlinear Programming-LagrangeExamples.pptx
7.3_Nonlinear Programming-LagrangeExamples.pptxethannguyen1618
 

Semelhante a 05 adversarial (20)

Juegos minimax AlfaBeta
Juegos minimax AlfaBetaJuegos minimax AlfaBeta
Juegos minimax AlfaBeta
 
Game playing
Game playingGame playing
Game playing
 
The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184The Ring programming language version 1.5.3 book - Part 69 of 184
The Ring programming language version 1.5.3 book - Part 69 of 184
 
AI subject - Game Theory and cps ppt pptx
AI subject  - Game Theory and cps ppt pptxAI subject  - Game Theory and cps ppt pptx
AI subject - Game Theory and cps ppt pptx
 
The Ring programming language version 1.9 book - Part 69 of 210
The Ring programming language version 1.9 book - Part 69 of 210The Ring programming language version 1.9 book - Part 69 of 210
The Ring programming language version 1.9 book - Part 69 of 210
 
Game and Search
Game and SearchGame and Search
Game and Search
 
cs-171-07-Games and Adversarila Search.ppt
cs-171-07-Games and Adversarila Search.pptcs-171-07-Games and Adversarila Search.ppt
cs-171-07-Games and Adversarila Search.ppt
 
Calculo Thomas (Solutions).pdf
Calculo Thomas  (Solutions).pdfCalculo Thomas  (Solutions).pdf
Calculo Thomas (Solutions).pdf
 
The Ring programming language version 1.7 book - Part 64 of 196
The Ring programming language version 1.7 book - Part 64 of 196The Ring programming language version 1.7 book - Part 64 of 196
The Ring programming language version 1.7 book - Part 64 of 196
 
Minmax and alpha beta pruning.pptx
Minmax and alpha beta pruning.pptxMinmax and alpha beta pruning.pptx
Minmax and alpha beta pruning.pptx
 
2 d kadane
2 d kadane2 d kadane
2 d kadane
 
Problemas pares
Problemas paresProblemas pares
Problemas pares
 
Global and local alignment (bioinformatics)
Global and local alignment (bioinformatics)Global and local alignment (bioinformatics)
Global and local alignment (bioinformatics)
 
AI_unit3.pptx
AI_unit3.pptxAI_unit3.pptx
AI_unit3.pptx
 
Capgemini 1
Capgemini 1Capgemini 1
Capgemini 1
 
ch_5 Game playing Min max and Alpha Beta pruning.ppt
ch_5 Game playing Min max and Alpha Beta pruning.pptch_5 Game playing Min max and Alpha Beta pruning.ppt
ch_5 Game playing Min max and Alpha Beta pruning.ppt
 
Graphical Method
Graphical MethodGraphical Method
Graphical Method
 
Algebra 2 Section 2-5
Algebra 2 Section 2-5Algebra 2 Section 2-5
Algebra 2 Section 2-5
 
9SearchAdversarial (1).pptx
9SearchAdversarial (1).pptx9SearchAdversarial (1).pptx
9SearchAdversarial (1).pptx
 
7.3_Nonlinear Programming-LagrangeExamples.pptx
7.3_Nonlinear Programming-LagrangeExamples.pptx7.3_Nonlinear Programming-LagrangeExamples.pptx
7.3_Nonlinear Programming-LagrangeExamples.pptx
 

Último

Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 

Último (20)

Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

05 adversarial

  • 1. Adversarial Search and Game Playing (Where making good decisions requires respecting your opponent) Dr. Ali Abdallah (dr_ali_abdallah@hotmail.com)
  • 2.  Games like Chess or Go are compact settings which involve uncertainty and interaction  For centuries humans have used them to exert their intelligence  Recently, there has been great success in building game programs that challenge human supremacy
  • 3. Uncertainty  uncertainty is caused by the actions of another agent (MIN), which competes with our agent (MAX)
  • 4. Uncertainty  Here, uncertainty is caused by the actions of another agent (MIN), which competes with our agent (MAX)  MIN wants MAX to fail (and vice versa)  No plan exists that guarantees MAX’s success regardless of which actions MIN executes (the same is true for MIN)  At each turn, the choice of which action to perform must be made within a specified time limit  The state space is enormous: only a tiny fraction of this space can be explored within the time limit
  • 5. Specific Setting Two-player, turn-taking, deterministic, fully observable, time-constrained game  State space  Initial state  Successor function: it tells which actions can be executed in each state and gives the successor state for each action  MAX’s and MIN’s actions alternate, with MAX playing first in the initial state  Terminal test: it tells if a state is terminal and, if yes, if it’s a win or a loss for MAX, or a draw  All states are fully observable
  • 6. Game Tree MAX nodes MAX’s play → MIN nodes MIN’s play → Here, symmetries have been used to reduce the branching factor Terminal state (win for MAX) →
  • 7. Game Tree MAX’s play → MIN’s play → In general, the branching factor and the depth of terminal states are large Chess: • Number of states: ~1040 Terminal state • Branching factor: ~35 (win for MAX) → • Number of total moves in a game: ~100
  • 8. Choosing an Action: Basic Idea • Using the current state as the initial state, build the game tree uniformly to the maximal depth h (called horizon) feasible within the time limit • Evaluate the states of the leaf nodes • Back up the results from the leaves to the root and pick the best action assuming the worst from MIN → Minimax algorithm
  • 9. Evaluation Function  Function e: state s → number e(s)  e(s) is a heuristics that estimates how favorable s is for MAX  e(s) > 0 means that s is favorable to MAX (the larger the better)  e(s) < 0 means that s is favorable to MIN  e(s) = 0 means that s is neutral
  • 10. Example: Tic-tac-Toe e(s) = number of rows, columns, and diagonals open for MAX − number of rows, columns, and diagonals open for MIN 8−8 = 0 6−4 = 2 3−3 = 0
  • 11. Construction of an Evaluation Function  Usually a weighted sum of “features”: n e(s)=∑ wif(s) i i=1  Features may include  Number of pieces of each type  Number of possible moves  Number of squares controlled
  • 12. Backing up Values Tic-Tac-Toe tree 1 at horizon = 2 Best move -1 1 -2 6-5=1 5-5=0 6-5=1 5-5=1 4-5=-1 5-4=1 6-4=2 5-6=-1 5-5=0 5-6=-1 6-6=0 4-6=-2
  • 13. Continuation 1 1 0 2 1 3 1 2 1 1 1 0 2 0 1 1 0 2 2 3 1 2 2 1 1 0
  • 14. Why using backed-up values?  At each non-leaf node N, the backed-up value is the value of the best state that MAX can reach at depth h if MIN plays well (by the same criterion as MAX applies to itself)  If e is to be trusted in the first place, then the backed-up value is a better estimate of how favorable STATE(N) is than e(STATE(N))
  • 15. Minimax Algorithm 1. Expand the game tree uniformly from the current state (where it is MAX’s turn to play) to depth h 2. Compute the evaluation function at every leaf of the tree 3. Back-up the values from the leaves to the root of the tree as follows:  A MAX node gets the maximum of the evaluation of its successors  A MIN node gets the minimum of the evaluation of its successors 4. Select the move toward a MIN node that has the largest backed-up value
  • 16. Game Playing (for MAX) Repeat until a terminal state is reached 2. Select move using Minimax 3. Execute move 4. Observe MIN’s move Note that at each cycle the large game tree built to horizon h is used to select only one move All is repeated again at the next cycle (a sub-tree of depth h-2 can be re-used)
  • 17. Can we do better? Yes ! Much better ! ≥ 3 3 ≤ -1 ← Pruning This part of the tree can’t -1 have any effect on the value that will be backed up to the root
  • 19. Example The beta value of a MIN node is an upper bound on β=2 the final backed-up value. It can never increase 2
  • 20. Example The beta value of a MIN node is an upper bound on β=1 the final backed-up value. It can never increase 2 1
  • 21. Example α=1 The alpha value of a MAX node is a lower bound on β=1 the final backed-up value. It can never decrease 2 1
  • 22. Example α=1 β=1 β = -1 2 1 -1
  • 23. Example α=1 β=1 β = -1 Search can be discontinued below any MIN node whose beta value is less than or equal to the alpha value of one of its MAX ancestors 2 1 -1
  • 24. Alpha-Beta Pruning  Explore the game tree to depth h in depth-first manner  Back up alpha and beta values whenever possible  Prune branches that can’t lead to changing the final decision
  • 25. Alpha-Beta Algorithm  Update the alpha/beta value of the parent of a node N when the search below N has been completed or discontinued  Discontinue the search below a MAX node N if its alpha value is ≥ the beta value of a MIN ancestor of N  Discontinue the search below a MIN node N if its beta value is ≤ the alpha value of a MAX ancestor of N
  • 26. Example 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 27. Example 0 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 28. Example 0 0 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 29. Example 0 0 -3 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 30. Example 0 0 -3 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 31. Example 0 0 0 -3 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 32. Example 0 0 3 0 -3 3 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 33. Example 0 0 3 0 -3 3 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 34. Example 0 0 0 0 3 0 -3 3 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 35. Example 0 0 0 0 3 0 -3 3 5 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 36. Example 0 0 0 0 3 2 0 -3 3 2 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 37. Example 0 0 0 0 3 2 0 -3 3 2 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 38. Example 0 0 2 0 2 0 3 2 0 -3 3 2 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 39. Example 0 0 2 0 2 0 3 2 0 -3 3 2 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 40. Example 0 0 0 2 0 2 0 3 2 0 -3 3 2 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 41. Example 0 0 0 2 0 2 0 3 2 0 -3 3 2 5 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 42. Example 0 0 0 2 0 2 0 3 2 1 0 -3 3 2 1 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 43. Example 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5
  • 44.
  • 45.
  • 46. Example 0 0 0 2 1 0 2 1 0 3 2 1 0 -3 3 2 1 -3 -5 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 47. Example 0 0 0 2 1 0 2 1 0 3 2 1 0 -3 3 2 1 -3 -5 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 48. Example 0 0 0 2 1 0 2 1 -5 0 3 2 1 -5 0 -3 3 2 1 -3 -5 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 49. Example 0 0 0 2 1 0 2 1 -5 0 3 2 1 -5 0 -3 3 2 1 -3 -5 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 50. Example 1 0 1 0 2 1 0 2 1 -5 0 3 2 1 -5 0 -3 3 2 1 -3 -5 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 51. Example 1 0 1 0 2 1 2 0 2 1 -5 2 0 3 2 1 -5 2 0 -3 3 2 1 -3 -5 2 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 52. Example 1 0 1 0 2 1 2 0 2 1 -5 2 0 3 2 1 -5 2 0 -3 3 2 1 -3 -5 2 0 5 -3 3 3 -3 0 2 -2 3 5 2 5 -5 0 1 5 1 -3 0 -5 5 -3 3 2
  • 53. How much do we gain? Consider these two cases: α=3 α=3 3 β=-1 3 β=4 -1 (4) -1 4
  • 54. How much do we gain?  Assume a game tree of uniform branching factor b  Minimax examines O(bh) nodes, so does alpha-beta in the worst-case  The gain for alpha-beta is maximum when: • The MIN children of a MAX node are ordered in decreasing backed up values • The MAX children of a MIN node are ordered in increasing backed up values  Then alpha-beta examines O(bh/2) nodes [Knuth and Moore, 1975]  But this requires an oracle (if we knew how to order nodes perfectly, we would not need to search the game tree)  If nodes are ordered at random, then the average number of nodes examined by alpha-beta is ~O(b3h/4)
  • 55. Heuristic Ordering of Nodes  Order the nodes below the root according to the values backed-up at the previous iteration  Order MAX (resp. MIN) nodes in decreasing (increasing) values of the evaluation function e computed at these nodes
  • 56. Other Improvements  Adaptive horizon + iterative deepening  Extended search: Retain k>1 best paths, instead of just one, and extend the tree at greater depth below their leaf nodes to (help dealing with the “horizon effect”)  Singular extension: If a move is obviously better than the others in a node at horizon h, then expand this node along this move  Use transposition tables to deal with repeated states  Null-move search
  • 58. Checkers: Tinsley vs. Chinook Name: Marion Tinsley Profession: Teach mathematics Hobby: Checkers Record: Over 42 years loses only 3 games of checkers World champion for over 40 years Mr. Tinsley suffered his 4th and 5th losses against Chinook
  • 59. Chinook First computer to become official world champion of Checkers!
  • 60. Chess: Kasparov vs. Deep Blue Kasparov Deep Blue 5’10” Height 6’ 5” 176 lbs Weight 2,400 lbs 34 years Age 4 years 50 billion neurons Computers 32 RISC processors + 256 VLSI chess engines 2 pos/sec Speed 200,000,000 pos/sec Extensive Knowledge Primitive Electrical/chemical Power Source Electrical Enormous Ego None 1997: Deep Blue wins by 3 wins, 1 loss, and 2 draws
  • 61. Chess: Kasparov vs. Deep Junior Deep Junior 8 CPU, 8 GB RAM, Win 2000 2,000,000 pos/sec Available at $100 August 2, 2003: Match ends in a 3/3 tie!
  • 62. Othello: Murakami vs. Logistello Takeshi Murakami World Othello Champion 1997: The Logistello software crushed Murakami by 6 games to 0
  • 63. Go: Goemate vs. ?? Name: Chen Zhixing Profession: Retired Computer skills: self-taught programmer Author of Goemate (arguably the best Go program available today) Gave Goemate a 9 stone handicap and still easily beat the program, thereby winning $15,000
  • 64. Go: Goemate vs. ?? Name: Chen Zhixing Profession: Retired Computer skills: self-taught programmer Go has too high a branching factor Author of Goemate (arguably the for existing search techniques strongest Go programs) Current and future software must rely on huge databasesaand pattern- Gave Goemate 9 stone handicap and still easily recognition techniques beat the program, thereby winning $15,000
  • 65. Secrets  Many game programs are based on alpha-beta + iterative deepening + extended/singular search + transposition tables + huge databases + ...  For instance, Chinook searched all checkers configurations with 8 pieces or less and created an endgame database of 444 billion board configurations  The methods are general, but their implementation is dramatically improved by many specifically tuned-up enhancements (e.g., the evaluation functions) like an F1 racing car
  • 66. Perspective on Games: Con and Pro Chess is the Drosophila of Saying Deep Blue doesn’t artificial intelligence. However, really think about chess computer chess has developed is like saying an airplane much as genetics might have if doesn't really fly because the geneticists had concentrated it doesn't flap its wings. their efforts starting in 1910 on Drew McDermott breeding racing Drosophila. We would have some science, but mainly we would have very fast fruit flies. John McCarthy
  • 67. Other Types of Games  Multi-player games, with alliances or not  Games with randomness in successor function (e.g., rolling a dice)  Expectminimax algorithm  Games with partially observable states (e.g., card games)  Search of belief state spaces See R&N p. 175-180