AI GROUP - 1
Game Playing in AI
What is Game?
What do you mean by Game theory?
What is game playing in AI?
What are the subjects relevance to game theory and game
playing?
Which technique is used to play the games?
What are the Characteristics of game playing?
Define Perfect information games with an example.
Define imperfect information games with an example.
Define game tree.
AI GROUP - 2
Game Playing in AI
What is Game?
Ans: A sort of conflict in which n individuals or groups
(known as players) participate. Games are integral attribute of
human beings.
What do you mean by Game theory?
Ans: Players determine their own strategies in terms of the
strategies and goals of their opponent.
What is game playing in AI?
Ans: Game playing, besides the topic of attraction to the
people, has close relation to "intelligence", and its well-defined
states and rules.
AI GROUP - 3
Game Playing in AI
What are the subjects relevance to game theory and game
playing?
AI GROUP - 4
Game Playing in AI
Which technique is used to play the games?
Ans: Game playing is a search problem
Defined by – Initial state – Successor function – Goal test – Path
cost .
What are the Characteristics of game playing?
Ans:
1.“Unpredictable” opponent: Solution is a strategy specifying a
move for every possible opponent reply
2. Time limits: Unlikely to find goal, must approximate
AI GROUP - 5
Game Playing in AI
Define Perfect information games with an example.
Ans: Perfect information refers to the fact that each player has
the same information that would be available at the end of the
game.
This is, each player knows or can see other player’s moves.
A good example would be chess,
Define imperfect information games with an example.
Ans: Imperfect information appears when decisions have to be
made simultaneously, and players need to balance all possible
outcomes when making a decision.
A good example of imperfect information games is a card
game
AI GROUP - 6
Game Playing in AI
Define game tree.
Ans: A game tree is a tree where nodes of the tree are the game
states and Edges of the tree are the moves by players.
Game tree involves initial state, actions function, and result
Function.
AI GROUP - 7
Mini-Max Algorithm in AI
Mini-max algorithm is a recursive or backtracking algorithm which
is used in decision-making and game theory.
It provides an optimal move for the player assuming that opponent
is also playing optimally.
Mini-Max algorithm uses recursion to search through the game-tree.
Min-Max algorithm is mostly used for game playing in AI.
Such as Chess, Checkers, tic-tac-toe, go, and various tow-players
game.
This Algorithm computes the minimax decision for the current state.
AI GROUP - 8
AI GROUP - 9
Mini-Max Algorithm in AI
Mini-max algorithm is a recursive or backtracking algorithm which
is used in decision-making and game theory.
It provides an optimal move for the player assuming that opponent
is also playing optimally.
Mini-Max algorithm uses recursion to search through the game-tree.
Min-Max algorithm is mostly used for game playing in AI.
Such as Chess, Checkers, tic-tac-toe, go, and various tow-players
game.
This Algorithm computes the minimax decision for the current state.
AI GROUP - 10
Mini-Max Algorithm in AI
• In this algorithm two players play the game, one is called MAX and
other is called MIN.
• Both the players fight it as the opponent player gets the minimum
benefit while they get the maximum benefit.
• Both Players of the game are opponent of each other, where MAX
will select the maximized value and MIN will select the minimized
value.
• The minimax algorithm performs a depth-first search algorithm for
the exploration of the complete game tree.
• The minimax algorithm proceeds all the way down to the terminal
node of the tree, then backtrack the tree as the recursion.
AI GROUP - 11
Mini-Max Algorithm in AI
• Step-1: In the first step, the algorithm generates the entire game-
tree and apply the utility function to get the utility values for the
terminal states.
• In the below tree diagram, let's take A is the initial state of the tree.
Suppose maximize takes first turn which has worst-case initial value
=- infinity, and minimiser will take next turn which has worst-case
initial value = +infinity.
AI GROUP - 12
Mini-Max Algorithm in AI
Step 2: Now, first we find the utilities value for the Maximizer, its
initial value is -∞, so we will compare each value in terminal state
with initial value of Maximizer and determines the higher nodes
values. It will find the maximum among the all.
AI GROUP - 13
Mini-Max Algorithm in AI
Step 3: In the next step, it's a turn for minimizer, so it will compare
all nodes value with +∞, and will find the 3rd layer node values.
AI GROUP - 14
Mini-Max Algorithm in AI
Step 4: Now it's a turn for Maximizer, and it will again choose the
maximum of all nodes value and find the maximum value for the root
node. In this game tree, there are only 4 layers, hence we reach
immediately to the root node, but in real games, there will be more
than 4 layers.
AI GROUP - 15
Mini-Max Algorithm in AI
AI GROUP - 16
One – Ply Search
AI GROUP - 17
253
Two – Ply Search
AI GROUP - 18
254
Backing Up the Values
of a Two – Ply Search
AI GROUP - 19
255
Example Tic-Tac-Toe
AI GROUP - 20
255
Example Tic-Tac-Toe
AI GROUP - 21
255
Properties of Mini-Max algorithm:
Complete- Min-Max algorithm is Complete. It will
definitely find a solution (if exist), in the finite search tree.
Optimal- Min-Max algorithm is optimal if both opponents
are playing optimally.
Time complexity- As it performs DFS for the game-tree,
so the time complexity of Min-Max algorithm is O(bm),
where b is branching factor of the game-tree, and m is
the maximum depth of the tree.
Space Complexity- Space complexity of Mini-max
algorithm is also similar to DFS which is O(bm).
AI GROUP - 22
255
Limitation of the minimax Algorithm:
The main drawback of the minimax algorithm is that it
gets really slow for complex games such as Chess, go,
etc.
This type of games has a huge branching factor, and the
player has lots of choices to decide.
AI GROUP - 23
255
AI GROUP - 24
Alpha-Beta Pruning Algorithm in AI
Alpha-beta pruning is a modified version of the minimax algorithm.
It is an optimization technique for the minimax algorithm.
As we have seen in the minimax search algorithm that the number
of game states it has to examine are exponential in depth of the
tree.
Since we cannot eliminate the exponent, but we can cut it to half.
Hence there is a technique by which without checking each node of
the game tree we can compute the correct minimax decision, and
this technique is called pruning.
This involves two threshold parameter Alpha and beta for future
expansion, so it is called alpha-beta pruning. It is also called
as Alpha-Beta Algorithm.
AI GROUP - 25
Alpha-Beta Pruning Algorithm in AI
Alpha-beta pruning can be applied at any depth of a tree, and
sometimes it not only prune the tree leaves but also entire sub-
tree.
The two-parameter can be defined as:
Alpha: The best (highest-value) choice we have found so far at
any point along the path of Maximizer. The initial value of alpha
is -∞.
Beta: The best (lowest-value) choice we have found so far at any
point along the path of Minimizer. The initial value of beta is +∞.
The Alpha-beta pruning to a standard minimax algorithm returns
the same move as the standard algorithm does, but it removes all
the nodes which are not really affecting the final decision but
making algorithm slow. Hence by pruning these nodes, it makes the
AI GROUP - 26
algorithm fast.
Alpha-Beta Pruning Algorithm in AI
The main condition which required for alpha-beta pruning is:
α>=β
The Max player will only update the value of alpha.
The Min player will only update the value of beta.
While backtracking the tree, the node values will be passed to
upper nodes instead of values of alpha and beta.
We will only pass the alpha, beta values to the child nodes.
AI GROUP - 27
Alpha-Beta Pruning Algorithm in AI
Example: Step 1: At the first step the, Max player will start first
move from node A where α= -∞ and β= +∞, these value of alpha and
beta passed down to node B where again α= -∞ and β= +∞, and Node
B passes the same value to its child D.
AI GROUP - 28
Alpha-Beta Pruning Algorithm in AI
Step 2: At Node D, the value of α will be calculated as its turn for
Max. The value of α is compared with firstly 2 and then 3, and the
max (2, 3) = 3 will be the value of α at node D and node value will
also 3.
AI GROUP - 29
Alpha-Beta Pruning Algorithm in AI
Step 3: Now algorithm backtrack to node B, where the value of β
will change as this is a turn of Min, Now β= +∞, will compare with
the available subsequent nodes value, i.e. min (∞, 3) = 3, hence at
node B now α= -∞, and β= 3.
AI GROUP - 30
Alpha-Beta Pruning Algorithm in AI
Step 4: At node E, Max will take its turn, and the value of alpha
will change. The current value of alpha will be compared with 5, so
max (-∞, 5) = 5, hence at node E α= 5 and β= 3, where α>=β, so the
right successor of E will be pruned, and algorithm will not traverse it,
and the value at node E will be 5
AI GROUP - 31
Alpha-Beta Pruning Algorithm in AI
• Step 5: At next step, algorithm again backtrack the tree, from node
B to node A. At node A, the value of alpha will be changed the
maximum available value is 3 as max (-∞, 3)= 3, and β= +∞, these
two values now passes to right successor of A which is Node C.
• At node C, α=3 and β= +∞, and the same values will be passed on
to node F.
• Step 6: At node F, again the value of α will be compared with left
child which is 0, and max(3,0)= 3, and then compared with right
child which is 1, and max(3,1)= 3 still α remains 3, but the node
value of F will become 1.
AI GROUP - 32
Alpha-Beta Pruning Algorithm in AI
AI GROUP - 33
Alpha-Beta Pruning Algorithm in AI
Step 7: Node F returns the node value 1 to node C, at C α= 3 and
β= +∞, here the value of beta will be changed, it will compare with 1
so min (∞, 1) = 1. Now at C, α=3 and β= 1, and again it satisfies the
condition α>=β, so the next child of C which is G will be pruned, and
the algorithm will not compute the entire sub-tree G.
AI GROUP - 34
Alpha-Beta Pruning Algorithm in AI
Step 8: C now returns the value of 1 to A here the best value for A
is max (3, 1) = 3. Following is the final game tree which is the
showing the nodes which are computed and nodes which has never
computed. Hence the optimal value for the maximizer is 3 for this
example.
AI GROUP - 35
STOCHASTIC GAMES
• A stochastic game was introduced by Lloyd Shapley in the early
1950s. It is a dynamic game with probabilistic transitions played by
one or more players. The game is played in a sequence of stages.
• The game is played in a sequence of stages. At the beginning of each
stage, the game is in a certain state. The players select actions, and
each player receives a payoff that depends on the current state and
the chosen actions. The game then moves to a new random state
whose distribution depends on the previous state and the actions
chosen by the players. The procedure is repeated at the new state,
and the play continues for a finite or infinite number of stages. The
total payoff to a player is often taken to be the discounted sum of the
stage payoffs or the limit inferior of the averages of the stage
payoffs.
AI GROUP - 36