0% found this document useful (0 votes)
24 views33 pages

FAI - Unit 3 - Search Using Games

Uploaded by

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

FAI - Unit 3 - Search Using Games

Uploaded by

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

Fundamentals of Artificial Intelligence

Unit 3: Search Using Games

by
Dr. Abdul Ahad
Content
2.1 Introduction
2.2 Game Trees
2.3 Minmax Evaluation
2.4 Minmax with Alpha-Beta Pruning
2.5 Variations to Minmax
2.6 Improvements to Minmax
2.7 Games of Chance
2.8 The Expect Minmax Algorithm

Dr. Abdul Ahad, Department of AI 2


3.1 Introduction
Search is a natural part of people’s lives. Search in Artificial
Intelligence is the process of navigating from a starting state to a
goal state by transitioning through intermediate states.
A search problem is defined by the
Initial state (e.g., Guntur)
Operators (e.g., Guntur -> Vijayawada,
Guntur -> Miryalaguda, etc.)
Goal test (e.g., at Hyderabad)
Solution cost (e.g., path cost)

Dr. Abdul Ahad, Department


3 of AI
Example Problem – Towers of Hanoi

States: combinations of poles and disks


Operators: move disk x from pole y to pole z
subject to constraints
• cannot move disk on top of smaller disk
• cannot move disk if other disks on top
Goal test: disks from largest (at bottom) to smallest on goal pole
Path cost: 1 per move
Dr. Abdul Ahad, Department of AI 4
Example Problem – Eight Puzzle

States: tile locations


Initial state: one specific tile configuration
Operators: move blank tile left, right, up, or down
Goal: tiles are numbered from one to eight around the square
Path cost: cost of 1 per move (solution cost same as number
of most or path length)
Dr. Abdul Ahad, Department of AI 5
3.2 Game Trees
➢ Game trees are important in artificial intelligence because one
way to pick the best move in a game is to search the game tree
using any of numerous tree search algorithms, combined with
minimax-like rules to prune the tree.
➢ A game tree is a type of recursive search function that examines
all possible moves of a strategy game, and their results, in an
attempt to ascertain the optimal move. They are very useful
for Artificial Intelligence in scenarios that do not require real-
time decision making and have a relatively low number of
possible choices per play. The most commonly-cited example is
chess, but they are applicable to many situations.
➢ Game trees are generally used in board games to determine the
best possible move.
Dr. Abdul Ahad, Department of AI 6
Example: Tic-Tac-Toe Game Tree:
The following figure is showing part of the game-tree
for tic-tac-toe game. Following are some key points of
the game:
•There are two players MAX and MIN.
•Players have an alternate turn and start with MAX.
•MAX maximizes the result of the game tree
•MIN minimizes the result.

Dr. Abdul Ahad, Department of AI 7


Dr. Abdul Ahad, Department of AI 8
▪ From the initial state, MAX has 9 possible moves as he starts first.
MAX place x and MIN place o, and both player plays alternatively
until we reach a leaf node where one player has three in a row or all
squares are filled.
▪ Both players will compute each node, minimax, the minimax value
which is the best achievable utility against an optimal adversary.
▪ Suppose both the players are well aware of the tic-tac-toe and
playing the best play. Each player is doing his best to prevent
another one from winning. MIN is acting against Max in the game.
▪ So in the game tree, we have a layer of Max, a layer of MIN, and
each layer is called as Ply. Max place x, then MIN puts o to prevent
Max from winning, and this game continues until the terminal
node.
▪ In this either MIN wins, MAX wins, or it's a draw. This game-tree
is the whole search space of possibilities that MIN and MAX are
playing tic-tac-toe and taking turns alternately.
Dr. Abdul Ahad, Department of AI 9
In a given game tree, the optimal strategy can be determined
from the minimax value of each node, which can be written as
MINIMAX(n). MAX prefer to move to a state of maximum
value and MIN prefer to move to a state of minimum value
then:

Dr. Abdul Ahad, Department of AI 10


3.3 Minmax Evaluation
a) Minimax Search:

➢ Minimax is a kind of backtracking algorithm that 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.

➢ In this algorithm two players play the game, one is called Maximizer
(MAX) and other is called Minimizer(MIN). The maximizer tries to
get the highest score possible while the minimizer tries to do the
opposite and get the lowest score possible.

➢ In a given state if the maximizer has upper hand then, the score of the
board will tend to be some positive value. If the minimizer has the
upper hand in that board state then it will tend to be some negative
value. The values of the board are calculated by some heuristics which
are unique for every type of game.
Dr. Abdul Ahad, Department of AI 11
Example: Following are the main steps involved in solving the two-player
game tree:
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
maximizer takes first turn which has worst-case initial value = -infinity, and
minimizer will take next turn which has worst-case initial value = +infinity.

Dr. Abdul Ahad, Department of AI 12


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.

➢ For node D max(-1,- -∞) => max(-1,4)= 4


➢ For Node E max(2, -∞) => max(2, 6)= 6
➢ For Node F max(-3, -∞) => max(-3,-5) = -3
➢ For node G max(0, -∞) = max(0, 7) = 7

Dr. Abdul Ahad, Department of AI 13


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.
•For node B= min(4,6) = 4
•For node C= min (-3, 7) = -3

Dr. Abdul Ahad, Department of AI 14


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.
➢ For node A max(4, -3)= 4

Time complexity: O(bm), where b is branching factor of the game-tree, and


m is the maximum depth of the tree.
Space Complexity: O(bm).
Dr. Abdul Ahad, Department of AI 15
b) Alpha-Beta Pruning
Alpha-beta pruning is a modified version of the minimax algorithm. It
is an optimization technique for the minimax algorithm. 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.
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 +∞.
Dr. Abdul Ahad, Department of AI 16
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.
The main condition which required for alpha-beta pruning is:
α>=β

Dr. Abdul Ahad, Department of AI 17


An example of two-player search tree to understand the
working of Alpha-beta pruning:
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.

Dr. Abdul Ahad, Department of AI 18


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.

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.

In the next step, algorithm traverse the next successor of Node B which is
node E, and the values of α= -∞, and β= 3 will also be passed.
Dr. Abdul Ahad, Department of AI 19
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.

Dr. Abdul Ahad, Department of AI 20


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.

Dr. Abdul Ahad, Department of AI 21


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.

Dr. Abdul Ahad, Department of AI 22


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.

Dr. Abdul Ahad, Department of AI 23


3.5 Variations to MinMax

▪ Alpha-Beta Pruning. Alpha-beta pruning is a method for


reducing the search space of the MinMax algorithm by
removing branches of the game tree that do not need to be
investigated. ...
▪ Monte Carlo Tree Search. ...
▪ Negamax. ...
▪ MinMax with Iterative Deepening.

Dr. Abdul Ahad, Department of AI 24


3.6 Improvements to Minmax
Irrelevant Moves: In some zero-sum games, there are moves
that can be skipped in the Minimax process. For example, in
gomoku or othello, playing in squares that are not close to other
pieces on the board would be bad moves, and thus can be
skipped without resulting in a loss of skill.
Limit the Number of Moves Checked: Since the complexity of
minimax relies heavily on the branching factor—the number of
children for any node—limiting the number of moves checked
can significantly speed up your search. A basic way to do this is
to sort all the possible moves from any position based off much
the move improves the position with a depth-1 evaluation
function (compare the evaluation before and after placing the
piece). Then only search deeper on the first n best moves instead
of on all possible moves.
Dr. Abdul Ahad, Department of AI 25
Detect Forced Moves: In most games, there are situations where a
move is forced. Forced moves can be categorized into two categories,
I’ll use chess and gomoku for examples.
1. Forced Defense
• For chess, when a King is in check, the player is forced to defend the
King in some way.
• For gomoku, when a player has a four-in-a-row with an open end, the
other is forced to block it.
2. Win Available
This one is very simple—when a win is available, play it!
• For chess, if you are threatening a King on your turn, capture it!
• For gomoku, if you have a four-in-a-row with an open end on your turn,
play on the end to win the game!
▪ After playing one of these moves in your minimax function, you can simply
cut the game off returning the result of the game. There is no need to search
the game any further (in this branch) since it is already over!
▪ Always detect wins before defenses. If no win exists, and you detected
forced defense moves, then only search through the forced moves—don’t
even bother with other moves.
Dr. Abdul Ahad, Department of AI 26
▪ Game-Specific Algorithms: In many games, minimax is best
when it is not used alone. Strong gomoku programs use threat-
space search in conjunction with minimax. Strong chess
programs use alpha-beta pruning along with other types of
searches. In short—think about your game and try searching in
a way that makes more sense to your game. This is the most
complex improvement in the list I made.

▪ Double-check your Code!: This might not seem like it


should belong in this post, but there are almost always
improvements that can be made to your functions. In minimax,
the evaluation function is constantly being called on, if there is
anything—however slight—that can be made more efficient in
it, it’ll really pay off.

Dr. Abdul Ahad, Department of AI 27


3.7 Games of Chance
There exist some games that include an element of chance 1.
Example: Backgammon is typical game that combine luck and skill.
Dice are rolled at the beginning of a Player's turn to determine the
legal moves.
A game tree in backgammon must include chance nodes in addition to
MAX and MIN nodes. These chance nodes are shown as circles.
The branches leading from each chance node denotes the possible dice
rolls, and each is labelled with the roll and chance that it will occur.
The six doubles (1-1 through b-b) have a 1/36 chance of coming up,
the other is district rolls a 1/15 chance each.

Dr. Abdul Ahad, Department of AI 28


Dr. Abdul Ahad, Department of AI 29
To make correct decisions, pick the move that leads to the best
position.
Only expected value can be calculated which leads to generalize the
minimax value for deterministic games to an expectiminimax value
for games with chance nodes.
Chance nodes are evaluated by taking weighted average values
resulting from all possible dice rolls i.e.,
Successor function for a chance node a simply augments the state of
n with each possible dice roll to produce each successor S.

P(S) - Probability that dice roll occurs.


Dr. Abdul Ahad, Department of AI 30
2.8 Expect Minimax algorithm
The expect minimax algorithm is a variation of the minimax
algorithm, for use in artificial intelligence systems that play two-player
zero-sum games, such as backgammon, in which the outcome depends
on a combination of the player's skill and chance elements such as dice
rolls.
The Expectiminimax algorithm is a variation of the Minimax
algorithm and is used in artificial intelligence systems that play two-
player zero-sum games such as backgammon. In this game, the
outcome is determined by a combination of player skill and chance
factors such as the roll of the dice. . In addition to the "min" and "max"
nodes of a traditional minimax tree, this variant has a "chance" ("move
by Nature") node that captures the expected value of a random event
that occurs.

Dr. Abdul Ahad, Department of AI 31


In game theory terminology, an expectiminimax tree is a game tree for
an expanded form of a game with complete but incomplete
information. In traditional minimax methods, the tree switches from
maximum to minimum levels until the tree depth limit is reached.

In an Expectiminimax tree, the "chance" node is interleaved with the


maximum and minimum nodes. Instead of taking the maximum or
minimum utility value of a child, the Chance node calculates a
weighted average, weighted by the probability that the child will reach
it. Interleaving varies by game. Each "turn" in the game is a "max"
node (representing the AI ​player's turn), a "minimum" node
(representing the potentially optimal opponent's turn), or a "chance"
node (representing a random effect). ).
For example, consider a game where each round is his one die throw
and decisions are made first by his AI player and then by another
intelligent opponent. The order of the nodes in this game switches
between "Chance", "Maximum", and "Minimum“.

Dr. Abdul Ahad, Department of AI 32


Thank You

Dr. Abdul Ahad, Department of AI 33

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy