You are on page 1of 30

Lecture 16

Game Theory
Artificial Intelligence
COSC-3112

Ms. Humaira Anwer


humaira.anwer@kfueit.edu.pk

Lecture 16- Game Theory 1


Today’s Agenda
• Game Theory
• Adversarial Search
• Games Vs. Search Problems
• MiniMax Algorithm
• Alpha Beta Pruning

Lecture 16- Game Theory 2


Game Theory
• Choosing from a set of rational choices in a multi-
agent situation.

• Dealing with deciding on a given set of options.

• Multi-agent situation- choices affect the choices of


the opponent in the game, and their decision
affects our choices

Lecture 16- Game Theory 3


Game Theory & AI
• In AI, problems can be of two types:
• One - is when a single person is trying to do a job.
• The other problem is where many people are doing the
job like a game.
• Here the choice of one player affects the other.

• Hence the game theory is used in AI whenever


there is more than one person involved in solving
a logical problem.

Lecture 16- Game Theory 4


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.”

Lecture 16- Game Theory 5


Let’s Play
• You -> X
• Computer Opponent-> O

x O x
x x O
O x O
Lecture 16- Game Theory 6
Game Theory

• Game-playing programs developed by AI researchers


since the beginning of the modern AI era
• Programs playing chess, checkers, etc (1950s)
• Specifics:
• Sequences of player’s decisions we control
• Decisions of other player(s) we do not control
• Contingency problem: many possible opponent’s
moves must be “covered” by the solution
• Opponent’s behavior introduces uncertainty
• Rational opponent – maximizes its own utility (payoff)
function

Lecture 16- Game Theory 7


Games vs. Search Problems
• Search-no adversary
• Goal->Solution
• Evaluation Function->f(n)
• Games-adversary
• Unpredictability
• Time limits
• Evaluation Function
• Examples: Chess, Checkers, ludo, Tic-Tac-Toe, Tennis etc.

Lecture 16- Game Theory 8


Game Search Problem
• Problem formulation
• Initial state
• Player (s)
• Actions (s)
• Goal (terminal test)
• Utility (payoff) function: measures the outcome of the
game and its desirability
• Search objective:
• Find the sequence of player’s decisions (moves)
maximizing its utility (payoff)
• Consider the opponent’s moves and their utility

Lecture 16- Game Theory 9


Game tree (2-player,
deterministic, turns)

Lecture 16- Game Theory 10


Minimax Algorithm
• How to deal with the contingency problem?
• Assuming the opponent is always rational and always
optimizes its behavior (opposite to us), we consider the
best opponent’s response
• Then the minimax algorithm determines the best move

Lecture 16- Game Theory 11


Minimax
• Minimax algorithm in Game Theory is one of the oldest algorithms in AI and is
used generally for two players.
• Perfect play for deterministic games
• Idea: choose move to position with highest minimax value
= best achievable payoff against best play

Lecture 16- Game Theory 12


MiniMax
• Working (Rules)
• We assign one player as Max who chooses the maximum from the
given set of choices

• The other player as Min who chooses the minimum from the same
collection.

• A Tree data structure is used. We designate each level of this tree-


structure to both the players Max and Min, alternatively.

• At each level, the decision is made by the player.

• The last level has all the potential outcomes of the game.

• The goal is to reach the top of the tree from the bottom
level, without breaking any of the defined rules and
eventually solve the problem.

Lecture 16- Game Theory 13


MiniMax: Let's begin the game!
-7
0 Max

-10 -7
1 Min

10 -10 5 -7
2 Max

10 5 -10 5 -∞ -7
3 Min
+
5 - -
10 ∞ 10
7 5 -7 -5

4 Max
Lecture 16- Game Theory 14
Minimax: Practice Problem.

Lecture 16- Game Theory 15


Complexity of the minimax
algorithm

Lecture 16- Game Theory 16


Alpha Beta Pruning
• Simple MiniMax Algorithm traverses through each
leaf node to predict the winner.

• Some branches will never be played by rational


players since they include sub-optimal decisions for
either player

• To avoid this long route, we use the Alpha-Beta


Pruning Algorithm.

Lecture 16- Game Theory 17


Alpha Beta Pruning
• We take a game tree same as in Minimax Algorithm
with levels designated to Max and Min.

• Then we take two values Alpha(α) and Beta(β).


• We assume α = -∞ = Max and β = +∞ = Min.
• Also, we consider a condition α ≥ β.
• Now, we follow DFS (Depth First Search) rule.

Lecture 16- Game Theory 18


Worked Example Max-> α = -∞
Min-> β = ∞

α = -∞
β=∞
Max

α = -∞ α = -∞
Min β=∞ β=∞

α = -∞ α = -∞ α = -∞ α = -∞
Max β=∞ β=∞ β=∞ β=∞

α = -∞
α = -∞ α = -∞ α = -∞ α = -∞ α = -∞ α = -∞ α = -∞
β=∞
β=∞ β=∞ β=∞ β=∞ β=∞ β=∞ β=∞
Min

3 4 1 1 9 13 6
2 7 8 9 10 2 11 12 14

Lecture 16- Game Theory 19


Worked Example Max-> α = -∞
Min-> β = ∞

α = -∞
β=∞
Max

α = -∞
β=∞
Min

α = -∞
β=∞
Max

α >= β α = -∞
β ==3∞
Min

Lecture 16- Game Theory 20


Worked Example Max-> α = -∞
Min-> β = ∞

α = -∞
β=∞
Max

α = -∞
β=∞
Min

α = -∞
β=∞
Max
α = -∞
3
β =3
Min

3 4

Lecture 16- Game Theory 21


Worked Example Max-> α = -∞
Min-> β = ∞

α = -∞
β=∞
Max

α = -∞
β=∞
Min

α >= β α=3
β=∞
Max
α = -∞
3
β =3
Min

3 4

Lecture 16- Game Theory 22


Worked Example Max-> α = -∞
Min-> β = ∞

α = -∞
β=∞
Max

α = -∞
β=∞
Min

α=3
β=∞
Max
α = -∞ α=3
3
β=3 β=∞
Min

3 4 2

Lecture 16- Game Theory 23


Worked Example Max-> α = -∞
Min-> β = ∞

α = -∞
β=∞
Max

α = -∞
β=∞
Min

α=3
3 β=∞
Max

α >= β 
α = -∞ α=3
3 2
β=3 β=2
Min
3 4 2 1

Lecture 16- Game Theory 24


Worked Example Max-> α = -∞
Min-> β = ∞

α=3
-∞
β=∞
Max
α >= β α = -∞
3
β=3
Min

α=3 α = 3-∞
3 β=∞ 3 α >= β 
β=3
Max
α = -∞ α=3 α = -∞ α >= βα = -∞
3 2 3
β=3 β=2 β=3 β=∞
Min
3 4 2 1 7 8 9 10

Lecture 16- Game Theory 25


Worked Example Max-> α = -∞
Min-> β = ∞

α=3
β=∞

Max

α = -∞ α=3
3 β=3 β=∞

Min

α >= β
α=3 α=3
α=3 3 β=3 β=∞
Max 3 β=∞

α = -∞ α=3 α = -∞
α=3
2 β = 2∞ α >= β 
3 β=3 2 β=2 3 β=3
Min

3 4 2 1 7 8 9 10 2 11

Lecture 16- Game Theory 26


Worked Example Max-> α = -∞
Min-> β = ∞

α=3
3 β=∞
Max

α = -∞ α=3 α >= β 
3 β=3 β=∞
3
Min

α >= β
α=3 α=3 α = -∞
α=3 3 β=3
3 β=∞ β=∞
Max 3 β=∞

α = -∞ α=3 α = -∞
α=3
2 β=2
α=3 α >= β α = -∞ α = -∞
3 β=3 2 β=2 3 β=3 1 ∞
β=1 β=∞
β=∞
Min

3 4 2 1 7 8 9 10 2 11 1 12 14 9 13 6

Lecture 16- Game Theory 27


Worked Example

Initially
α=-∞
β=∞

Lecture 16- Game Theory 28


Minimax with alpha-beta pruning:
The algorithm
• Maxv: function called for max nodes
• Might update alpha, the best max can do far
• Minv: function called for min nodes
• Might update beta, the best min can do so far

• Each tests for the appropriate pruning case

Lecture 16- Game Theory 29


Properties of α-β
• Pruning does not affect final result

• Good move ordering improves effectiveness of


pruning

• With "perfect ordering," time complexity = O(bd/2)

Lecture 16- Game Theory 30

You might also like