0% found this document useful (0 votes)
55 views39 pages

Introduction To Artificial Intelligence: Amna Iftikhar Spring ' 2021 1

The document provides an introduction and overview of the minimax algorithm and alpha-beta pruning techniques for game playing. It discusses game theory concepts, examples of games that computers now play like checkers, chess and Go. It then explains the minimax algorithm and how it works through examples. It also discusses limitations of minimax and techniques like alpha-beta pruning to improve search efficiency.

Uploaded by

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

Introduction To Artificial Intelligence: Amna Iftikhar Spring ' 2021 1

The document provides an introduction and overview of the minimax algorithm and alpha-beta pruning techniques for game playing. It discusses game theory concepts, examples of games that computers now play like checkers, chess and Go. It then explains the minimax algorithm and how it works through examples. It also discusses limitations of minimax and techniques like alpha-beta pruning to improve search efficiency.

Uploaded by

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

Introduction to Artificial

Intelligence

Lecture 06
Amna Iftikhar Spring ' 2021 1
Today’s Agenda
• Minimax algorithm
• Alpha Beta pruning

Amna Iftikhar Spring ' 2021 2


Game theory

• Competitive environments, in which the agents’ goals are


in conflict, giving rise to adversarial search problems—
often known as games.

Amna Iftikhar Spring ' 2021 3


Game Playing State-of-the-Art
• Checkers: 1950: First computer player. 1994: First computer champion: Chinook
ended 40-year-reign of human champion Marion Tinsley using complete 8-piece
endgame. 2007: Checkers solved!

• Chess: 1997: Deep Blue defeats human champion Gary Kasparov in a six-game
match. Deep Blue examined 200M positions per second, used very sophisticated
evaluation and undisclosed methods for extending some lines of search up to 40
ply. Current programs are even better, if less historic.

• Go: 2017: AlphaGo beats world's number one Go player Ke Jie. In go, b > 300!
Classic programs use pattern knowledge bases, but big recent advances use Monte
Carlo (randomized) expansion methods.
– AlphaGo Zero achieved a 100-0 victory against the champion-defeating AlphaGo, while its
successor, the self-taught AlphaZero, is currently perceived as the world's top player in Go as
well as possibly in chess.

Amna Iftikhar Spring ' 2021 4


The Number of possible legal board positions
for GO!

• That number—which is greater than the number of atoms in the universe—was


only determined in early 2016. Because there are so many directions any given
game can move in, Go is a notoriously difficult game for computers to play. It has
often been called the “Holy Grail” of artificial intelligence.

Amna Iftikhar Spring ' 2021 5


Types of Games
• Many different kinds of games!

• Axes:
– Deterministic or stochastic?
– One, two, or more players?
– Zero sum?
– Perfect information (can you see the state)?

• Want algorithms for calculating a strategy (policy)


which recommends a move from each state
Amna Iftikhar Spring ' 2021 6
Zero-Sum Games

• Zero-Sum Games • General Games


– Agents have opposite utilities (values on – Agents have independent utilities
outcomes) (values on outcomes)
– Lets us think of a single value that one – Cooperation, indifference,
maximizes and the other minimizes competition, and more are all possible
– Adversarial, pure competition

Amna Iftikhar Spring ' 2021 7


Adversarial Search

Amna Iftikhar Spring ' 2021 8


Game Tree
• Many two-player games can be efficiently represented using
trees, called game trees.
• A game tree is an instance of a tree in which the root node
represents the state before any moves have been made, the
nodes in the tree represent possible states of the game (or
positions), and arcs in the tree represent moves.
• It is usual to represent the two players’ moves on alternate
levels of the game tree, so that all edges leading from the root
node to the first level represent possible moves for the first
player, and edges from the first level to the second represent
moves for the second player, and so on.

Amna Iftikhar Spring ' 2021 9


Ply and Move
• In discussing game trees, we use the concept of ply, which
refers to the depth of the tree.
• When a computer evaluates a game tree to ply 5, it is
examining the tree to a depth of 5. The 4th ply in a game tree
is the level at depth 4 below the root node.
• Because the games we are talking about involve two players,
sequential plies in the tree will alternately represent the two
players. Hence, a game tree with a ply of 8 will represent a
total of eight choices in the game, which corresponds to four
moves for each player.
• It is usual to use the word ply to represent a single level of
choice in the game tree, but for the word move to represent
two such choices—one for each player (Source: wikipedia)

Amna Iftikhar Spring ' 2021 10


Tic-Tac-Toe Game Tree

Amna Iftikhar Spring ' 2021 11


Minimax Algorithm for Tic-Tac-Toe

Amna Iftikhar Spring ' 2021 12


Minimax Algorithm
• The minimax algorithm is a useful method for simple two-
player games. It is a method for selecting the best move
given an alternating game where each player opposes the
other working toward a mutually exclusive goal.

• In a two-person game, you must assume that your opponent


has the same knowledge that you do and applies it as well as
you do. So at each stage of the game you must assume your
opponent makes the best available move. This is the basis of
the minimax procedure.

Amna Iftikhar Spring ' 2021 13


Minimax Algorithm (Cont’d)
• It is assumed that a suitable static evaluation function is
available, which is able to give an overall score to a given
position.

• In applying Minimax, the static evaluator will only be used on


leaf nodes, and the values of the leaf nodes will be filtered up
through the tree, to pick out the best path that the computer
can achieve.

Amna Iftikhar Spring ' 2021 14


Minimax Algorithm (Cont’d)
• The principle behind Minimax is that a path through the tree
is chosen by assuming that at its turn (a max node), the
computer will choose the move that will give the highest
eventual static evaluation, and that at the human opponent’s
turn (a min node), he or she will choose the move that will
give the lowest static evaluation.

• In other words, we assume that each player makes the next


move that benefits them the most.

Amna Iftikhar Spring ' 2021 15


Minimax Algorithm for Tic-Tac-Toe

Amna Iftikhar Spring ' 2021 16


Example of Minimax Algorithm

Amna Iftikhar Spring ' 2021 17


Example I

Amna Iftikhar Spring ' 2021 18


Example II

Amna Iftikhar Spring ' 2021 19


Example III

Amna Iftikhar Spring ' 2021 20


Minimax Efficiency
• How efficient is minimax?
– Just like (exhaustive) DFS
– Time: O(bd)
– Space: O(bd)

• Example: For chess, b  35, d  100


– Exact solution is completely infeasible
– But, do we need to explore the whole tree?

Amna Iftikhar Spring ' 2021 21


Minimax Properties
max

min

10 10 9 100

Optimal against a perfect player. Otherwise?

Amna Iftikhar Spring ' 2021 22


Lookahead and Horizon Effect
• Minimax is a very simple algorithm
and is unsuitable for use in many
games, such as chess, where the
game tree is extremely large.
• In such cases, bounded lookahead is
very commonly used and can be
combined with Minimax.
• The idea of bounded lookahead is
that the search tree is only examined
to a particular depth. All nodes at this
depth are considered to be leaf
nodes and are evaluated using a
static evaluation function.

Amna Iftikhar Spring ' 2021 23


Lookahead and Horizon Effect
• When we employ
lookahead strategy, we
suffer from what is called
the horizon effect.

• When we can’t see beyond


the horizon, it becomes
easier to make a move that
looks good now, but leads
to problems later as we
move further into this
subtree.

Amna Iftikhar Spring ' 2021 24


Evaluation Function
• For a computer to use this tree to make decisions
about moves in a game of tic-tac-toe, it needs to use
an evaluation function, which enables it to decide
whether a given position in the game is good or bad.
• If we use exhaustive search, then we only need a
function that can recognize a win, a loss, and a draw.
• Then, the computer can treat “win” states as goal
nodes and carry out search in the normal way.
• But, for limited depth search terminal utilities would
have to be replaced by an evaluation function for
non-terminal positions.
Amna Iftikhar Spring ' 2021 25
Static Evaluation Function for Tic-Tac-Toe
• The static evaluation
function is defined as
the number of
possible win positions
not blocked by the
opponent minus the
number of possible
win positions (row,
column, and diagonal)
for the opponent not
blocked by the current
player:

• f (n) = win_positions-
lose_positions

Amna Iftikhar Spring ' 2021 26


Alpha-Beta Pruning
• Using alpha–beta pruning, it is
possible to remove sections of the
game tree that are not worth
examining, to make searching for a
good move more efficient.
• The principle behind alpha–beta
pruning is that if a move is
determined to be worse than
another move that has already been
examined, then further examining
the possible consequences of that
worse move is pointless.

Amna Iftikhar Spring ' 2021 27


Alpha-Beta Pruning Working
• The algorithm maintains two values, alpha and beta, which represent
the minimum score that the maximizing player is assured of and the
maximum score that the minimizing player is assured of respectively.
• Initially alpha is negative infinity and beta is positive infinity.
• Together alpha and beta provides a window of possible scores. We
will never choose to make moves that score less than alpha and our
opponent will never let us make moves scoring more than beta. The
score we finally achieve must lie between the two.
• As the recursion progresses the "window" becomes smaller. When
beta becomes less than alpha, it means that the current position
cannot be the result of best play by both players and hence need not
be explored further.

Amna Iftikhar Spring ' 2021 28


Alpha-Beta Pruning Working (Cont’d)
• Together alpha and beta provides a window of possible
scores. We will never choose to make moves that score
less than alpha and our opponent will never let us make
moves scoring more than beta. The score we finally
achieve must lie between the two.

• As the recursion progresses the "window" becomes


smaller. When beta becomes less than alpha, it means
that the current position cannot be the result of best play
by both players and hence need not be explored further.

Amna Iftikhar Spring ' 2021 29


Example I (Revisited)

X X

Only 7 nodes (out of 12) explored with alpha-beta pruning.

Amna Iftikhar Spring ' 2021 30


Working of Alpha-Beta for Example I

Amna Iftikhar Spring ' 2021 31


Working of Alpha-Beta for Example I (Cont’d)

Amna Iftikhar Spring ' 2021 32


Minimax Example

3 12 8 2 4 6 14 5 2

Amna Iftikhar Spring ' 2021 33


Pruning

3 12 8 2 14 5 2

Amna Iftikhar Spring ' 2021 34


Alpha-Beta Implementation
α: MAX’s best option on path to root
β: MIN’s best option on path to root

def max-value(state, α, β): def min-value(state , α, β):


initialize v = -∞ initialize v = +∞
for each successor of state: for each successor of state:
v = max(v, value(successor, v = min(v, value(successor,
α, β)) α, β))
if v ≥ β return v if v ≤ α return v
α = max(α, v) β = min(β, v)
return v return v

Amna Iftikhar Spring ' 2021 35


Example II

Amna Iftikhar Spring ' 2021 36


Example III

Amna Iftikhar Spring ' 2021 37


Java Applet

• https
://www.yosenspace.com/posts/computer-scie
nce-game-trees.html

Amna Iftikhar Spring ' 2021 38


Advantages of Alpha-Beta Pruning
• The alpha–beta pruning method provides its best
performance when the game tree is arranged such that the
best choice at each level is the first one (i.e., the left-most
choice) to be examined by the algorithm.
• With such a game tree, a Minimax algorithm using alpha–beta
cut-off will examine a game tree to double the depth that a
Minimax algorithm without alpha–beta pruning would
examine in the same number of steps.

Amna Iftikhar Spring ' 2021 39

You might also like