heuristic search and game playing
heuristic search and game playing
Game Playing
By:
Vijeta Rani
Delhi Technological University
• This approach can be effective but may not work well for
complex problems. Combining it with other techniques can
improve efficiency.
Backtracking
• Backtracking is a problem-solving algorithmic technique that
involves finding a solution incrementally by trying different
options and undoing them if they lead to a dead end.
• Upper and lower bounds: The algorithm uses upper and lower
bounds to reduce the size of the search space and eliminate
subproblems that cannot contain the optimal solution.
Characteristics of Branch and Bound
• Pruning: The algorithm prunes the search tree by eliminating
subproblems that cannot contain the optimal solution or are
not worth exploring further.
Height is defined by
Evaluation Function
Variations of hill climbing algorithm
1. Simple Hill climbing: It examines the neighboring nodes one
by one and selects the first neighboring node which optimizes
the current cost as the next node.
2. Steepest Ascent Hill Climbing: The algorithm evaluates all the
possible moves from the current solution and selects the one
that leads to the best improvement.
3. Simulated annealing: It is a probabilistic variation of Hill
Climbing that allows the algorithm to occasionally accept
worse moves in order to avoid getting stuck in local maxima.
Simple Hill climbing algorithm
1. 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.
2. Loop until a solution is found or until there are no new operators left to be applied to
the current state.
a) Select an operator that has not yet been applied to the current state and apply it to
produce a new state.
b) Evaluate the new state.
i) If it is the goal state, then return it and quit.
ii) If it is not a goal state, but it is better than the current state, then make it the
current state.
iii) If it is not better than the current state , then continue in the loop.
Algorithm for Steepest Ascent Hill climbing
1. 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.
-5 -5 -2
2 8 3 1 2 3
1 4 h = -3 8 4 h = -1
7 6 5 7 6 5
-3 -4
2 3 2 3
1 8 4 1 8 4 h = -2
7 6 5 7 6 5
h = -3 -4
f (n) = -(number of tiles out of place)
Problems with hill climbing
• Local Maxima: peaks that aren’t the local
highest point in the space maximum
• Plateaus: the space has a broad flat plateau
region that gives the search algorithm
no direction (random walk)
• Ridges: flat like a plateau, but with
drop-offs to the sides; steps to the
North, East, South and West may go
down, but a step to the NW may go up.
ridge
Image from: http://classes.yale.edu/fractals/CA/GA/Fitness/Fitness.html
Solutions to the hill climbing problems
To overcome these problems, one or a combination of the following
methods:
4. Loop until a solution is found or until there are no new operators left to be applied in
the current state.
a) Select an operator that has not yet been applied to the current state and apply it to
produce a new state.
Simulated annealing algorithm contd...
b) Evaluate the new state. Compute
ΔE = (value of current) - (value of new state)
i) If the new state is the goal state, then return it and quit.
ii) If it is not a goal state but is better than the current state, then make it the
current state. Also set BEST-SO-FAR to this new state.
iii) If it not better than the current state, then make it the current state with
probability p’ = e-ΔE/T. This step is usually implemented by invoking a random number
generator to produce a number in the range [0,1]. If that number is less than p’, then
the move is accepted. Otherwise do nothing.
c) Revise T as necessary according to the annealing schedule.
5. Return BEST-SO-FAR, as the answer.
Best First Search Algorithm
• The idea of Best First Search is to use an evaluation function to
decide which adjacent is most promising and then explore.
• This algorithm jumps all around in the search space to find out
the minimum evaluation function.
• In hill climbing, only the children are compared for minimum
evaluation function, but in best first search, even the
previously untraversed nodes are also compared.
• It is a branch and bound algorithm.
Best First Search Algorithm
1. Create two lists: OPEN list and CLOSED list
4. (B:6) (F:12), (G:14) (D:9), (E:8), (H:7), (F:12), S, (A:3), (C:5), (B:6)
(G:14)
5. (H:7) (I:5), (J:6) (D:9), (E:8), (F:12), (G:14), S, (A:3), (C:5), (B:6),
(I:5), (J:6) (H:7)
6. (I:5) (K:1), (L:0), (M:2) (D:9), (E:8), (F:12), (G:14), S, (A:3), (C:5), (B:6),
(J:6), (K:1), (L:0), (M:2) (H:7), (I:5)
7. (L:0) Search stops as L is the (D:9), (E:8), (F:12), (G:14), S, (A:3), (C:5), (B:6),
goal (J:6), (K:1), (M:2) (H:7), (I:5), (L:0)
Difference between steepest ascent hill
climbing and Best first search
• In Hill climbing one move is selected and all the others are rejected,
never to be reconsidered. Whereas in Best first search, one move is
selected but the others are kept around so that they can be
revisited later, if the selected path becomes less promising.
• Further, the best available state is selected in best first search, even
if the state has a value that is lower than the value of the state that
was just explored. In contrast, hill climbing stops if there are no
successor states with better values than the current state.
Analysis of Best first search
• The worst-case time complexity for Best First Search is O(n *
log n) where n is the number of nodes. In the worst case, we
may have to visit all nodes before we reach goal. Note that
priority queue is implemented using Min(or Max) Heap, and
insert and remove operations take O(log n) time.
• The performance of the algorithm depends on how well the
cost or evaluation function is designed.
A* Search
• In best first search, the heuristic function used was evaluation function,
in which the distance from the goal node was estimated.
• Apart from evaluation function, a function named as the cost function
can be used. This function indicate the amount of resources (energy,
space, time etc) are spent on reaching a node from the start node.
• While the evaluation function value deals with the future, the cost
function value deals with the past.
• The sum of the evaluation function and the cost function values is called
as the fitness number.
A* Search
A* is a Branch and Bound Search with an estimate of remaining
distance (best first Search) combined with principle of Dynamic
Programming
f(x) = g(x) + h(x)
Where,
g: measure of the cost of getting from initial node to current node
(sum of the cost of applying each rules that were applied along the
best path)
h: estimate of getting to goal node from current node
A* Search Algorithm
1. Create the OPEN list
Create the CLOSED list
2. Put the starting node on the OPEN list (you can set its g as zero, and
calculate its f = 0 + h.)
1. (S:7)
1. (A:10)
5. (I:8) (E:15), (H:12), (J:10) (B:14), (H:12: Replaced by (A:10), (F:9), (G:9),
new path), (E:15), (J:10) (I:8)
6. (J:10) Stop as J is the Goal. (B:14), (H:12), (E:15), (A:10), (F:9), (G:9),
(I:8), (J:10)
More points about A*
• Is A* algorithm admissible or not? Almost none.
useful heuristics can help to select the best rule to apply first.
If a letter that has only two possible values and another with six
possible values then there is a better chance of guessing right on
the first than on the second.
This procedure can be implemented as a depth –first search.
Game Playing
• Making computers play games.
• The rules of games are limited. Hence extensive amount of
domain specific knowledge are seldom needed.
• There are two major components of a game playing program:-
1. Plausible move generator: It expands or generates only
selected moves as it not possible to examine all the moves.
2. Static Evaluation function generator: Based on heuristics,
this generates the static evaluation function value. Higher
value means more probability of a win.
Game Playing strategies
• Games can be classified as :
1. Single person playing
2. Multi person playing