Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 48

Unit V

Game Playing and Expert Systems


GAMES
MULTI-PLAYER GAMES
PROBABILISTIC GAMES
ROBOT GAMES
TIC-TAC-TOE, CHESS
• 2-Player games
• Complete-information games
• Zero-Sum games
Game Tree

• Game playing problems can be modeled in terms of


search trees (Game trees).

Fig: Partial Game Tree for Noughts and Crosses (tic-tac-toe).


A game tree for a simple hypothetical game

• Which Move A must take?


A game tree for a simple hypothetical game

• Which Move A must take?


A game tree for a simple hypothetical game

• Which Move A must take?


A game tree for a simple hypothetical game

• Which Move A must take?


Game Playing Techniques

• Minimax Search

• Alpha-Beta Pruning
• - Implemented on top of Minimax Search
• - Improves efficiency of Minimax Search)
Minimax Search
• Two Players: Max and Min

• The Max (Min) player selects the move that leads to the
successor node with the highest (Lowest) score

• The scores are computed starting from the leaves of the


tree and backing up these scores to their predecessors
in accordance with the MINIMAX strategy

• It explores every node in the tree


Example 1:Game Tree Illustrating Minimax

• A simple game tree. Nodes with the maximizer to move are squares;
nodes with the minimizer to move are circles
• 1 -> Max Wins; -1 -> Min wins
Example 2: Continued

The maximizer wins with a Move to C


Example 2:Game Tree for Minimax
• The max (P1) wins with a Move to B:
• P1 move to C leads to draw

10 : P1 wins ; -10: P2 wins; 0: draw


Minimax Search
function MINIMAX(N)
Begin
• If N is a leaf node, then

return the estimated score of this leaf


Else
Let N1, N2, …., Nm be the successors of N;

If N is a Min node, then

Return min{MINIMAX(N1),….,MINIMAX(Nm)}
• Else
• Return min{MINIMAX(N1),….,MINIMAX(Nm)}
• End
Minimax Search
function MINIMAX(N)
Begin

• If N is a leaf node, then

• return the estimated score h(N) of this leaf


Else
Let N1, N2, …., Nm be the successors of N;

If N is a Min node, then

• Return minimum{MINIMAX(N1),
….,MINIMAX(Nm)}

• Else
Minimax Search
A's Winning strategy
2-Ply Minimax Game
(one move for each player)
2-Ply Minimax Game
(one move for each player)
Pruning
Pruning


Minimax search has to search large number of states

But possible to compute correct minimax decision without
looking at every node in search tree

Eliminating a branch of search tree from consideration
(without looking at it) is called pruning

Alpha-beta pruning

– Prunes away branches that cannot possibly influence
final minimax decision

– Returns same move as general minimax
Pruning (Cut-off)

Parent
of A

A β = 10

10
B α = 14 α >= β

14 C
Pruning (Deep Cut-off)
Ancestor α = 10
of D

10

β <= α D β=5 G

5 E
Pruning Rules
Alpha-Beta Pruning

Can be applied to trees of any depth

Often possible to prune entire subtrees rather than just leaves

Alpha-beta name

– Alpha = value of best (highest-value) choice found so far at any
choice point along path for MAX

In other words, the worst score (lowest) MAX could possibly get

Update alpha only during MAX’s turn/ply

– Beta = value of best (lowest-value) choice found so far at any choice
point along path for MIN

In other words, the worst score (highest) MIN could possibly get

Update beta only during MIN’s turn/ply
Alpha and Beta Cut-offs

• Alpha cut-off
• When pruned subtree has rooted at Max node
• Beta Cut-off
• When pruned subtree has rooted at Min node
Alpha beta pruning. Example 1
Example 2
Example 2 Solution
Example 3

The figure shows a 4-ply game tree with evaluation function values
at the horizon. The nodes in the horizon carry reference numbers
(sequence numbers going left to right) at the bottom. Use these
reference numbers when you want to enter a list of nodes. Answer
the following question (next slide)
Example 3
• Questions:
a) What is the MinMax value of the game?
b) What is the number of alpha-cuts and the number of beta-cuts
induced by the AlphaBeta pruning?
c) How many nodes are pruned (unexplored) by AlphaBeta pruning?
Count only the horizon nodes
d) List the nodes pruned by alpha-cuts. Count only the horizon nodes.
e) List the nodes pruned by beta-cuts. Count only the horizon nodes
Check Your Answers
a) 10
b) 3,2
c) 14
d) 14,16,17,18,19,20,21,22,23,24
e) 7,8,11,12

You might also like