Ai 2
Ai 2
By Sonal Gupta
OIMT Faculty
HILL-CLIMBING SEARCH/ALGORITHM
• It examines the neighboring nodes one by one and selects the first neighboring node
which optimizes the current cost as the next node.
• Evaluate the initial state. If it is a goal state then stop and return success.
Otherwise, make the initial state as the current state.
• Loop until a solution is found or until there are no new operators left to be
applied in the current state:
• Select an operator that has not yet been applied to the current state and apply it to
produce a new state.
• Evaluate the new state.
• If it is a goal state, then return it and quit
• If it is not a goal state but it is better than the current state, then make it the
current state.
• If it is not better than the current state, then continue in the loop.
SIMPLE HILL CLIMBING
SIMPLE HILL CLIMBING
SIMPLE HILL CLIMBING
SIMPLE HILL CLIMBING
SIMPLE HILL CLIMBING
Ref: https://www.youtube.com/watch?v=2SlO34_VsY4
STEEPEST-ASCENT HILL CLIMBING
• A useful variation on simple hill climbing considers all the moves from the
current state and select, the best one as the next state.
• Notice that this contrasts with the basic method in which the first state that is
better than the current state is selected.
• Evaluate the initial state. If it is also a goal state, then return it and quit.
Otherwise, continue with the initial state as the current state.
• Loop until a solution is found or until a complete iteration produces no change
to current state:
• Let SUCC be a state such that any possible successor of the current state will be
better than SUCC.
STEEPEST-ASCENT HILL CLIMBING
Ref: https://www.youtube.com/watch?v=LQbBGpiw1Pc
SIMULATED ANNEALING HILL CLIMBING
• The AND-OR graph (or tree), is useful for representing the solution of problems that
can be solved by decomposing them into a set of smaller problems, all of which must
then be solved.
• This decomposition, or reduction, generates arcs that we call AND arcs.
• One AND arc may point to any number of successor nodes, all of which must be solved
in order for the arc to point to a solution.
• Just as in an OR graph, several arcs may emerge from a single node, indicating a variety
of ways in which the original problem might be solved.
• This is why the structure is called not simply an AND graph but rather an AND-OR
graph.
• To solve games using AI, we will introduce the concept of a game tree.
• The different states of the game are represented by nodes in the game tree,
very similar to the above planning problems. The idea is just slightly different.
• In the game tree, the nodes are arranged in levels that correspond to each
player’s turns in the game so that the “root” node of the tree (usually depicted
at the top of the diagram) is the beginning position in the game.
• In tic-tac-toe, this would be the empty grid with no Xs or Os played yet.
• Under root, on the second level, there are the possible states that can result
from the first player’s moves, be it X or O.
• We call these nodes the “children” of the root node.
Source: https://course.elementsofai.com/2/3
TWO-PLAYER GAMES
• Two-player games are games in which two players compete against each other.
• These are also known as zero-sum games.
• The goal then in playing a two-player game is choosing a move that maximizes
the score of the player and/or minimizes the score of the competing player.
• A zero-sum game is one in which the gain of one player is balanced exactly by
the loss of the other player.
• Consider the two-player game Tic-Tac-Toe. Players alternate moves, and as
each move is made, the possible moves are constrained.
TWO-PLAYER GAMES
TWO-PLAYER GAMES
• At each node in the tree (a possible move) a value defining the goodness of
the move toward the player winning the game can be provided.
• So at a given node, the child nodes (possible moves from this state in the
game) each have an attribute defining the relative goodness of the move.
• A static evaluation function (that measure the goodness of a move) is used to
determine the value of a given move from a given game state.
• The evaluation function identifies the relative value of a successor move from
the list of possible moves as a measure of the move quality toward winning the
game.
• Game Tree – Tree representation of a game
TWO-PLAYER GAMES
• The static evaluation function is defined as x’s possibility to win – o’s possibility
to win. Max – x, Min – o
THE MINIMAX ALGORITHM
• Upon reaching a leaf node, the value of the node is calculated using an
evaluation (or utility) function.
• For our move, we’ll use the maximum value as our determiner for the best
move to make.
• For our opponent, the minimum value is used.
• At each layer of the tree, the child nodes area is scanned and depending on
whose move is to come, the maximum value is kept (in the case of our move),
or the minimum value is kept (in the case of the opponent’s move).
• Since these values are propagated up in an alternating fashion, we maximize the
minimum, or minimize the maximum.
• In other words, we assume that each player makes the move next that benefits
them the most.
THE MINIMAX ALGORITHM
• 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.
• Example:
• Consider a game which has 4 final states and paths to reach
final state are from root to 4 leaves of a perfect binary tree as
shown below.
• Assume you are the maximizing player and you get the first
chance to move, i.e., you are at the root and your opponent at
next level.
• Which move you would make as a maximizing player
considering that your opponent also plays optimally?
THE MINIMAX ALGORITHM
• The second module is the evaluation function, which computes a relative utility
for a given board configuration (how good a given board is compared to
others for a given board configuration).
• The final module is the search algorithm which must efficiently iterate through
the available board configurations, given a move, and decide which path to take
through the tree to select the next move to make.
• In the 1990s IBM’s Deep Blue successfully defeated Gary Kasparov, who at the
time was the world Chess champion.