0% found this document useful (0 votes)
36 views

Search Applications - Games: This Unit Has Two Main Sections Planning Learning Adaptation and Heuristics

The document discusses planning and search algorithms for game playing. It describes heuristics for the 8-puzzle game that estimate the number of misplaced tiles (h1) or the sum of distances of tiles from their goal positions (h2). The minimax algorithm is introduced for two-player games that assigns scores to game states based on the players' objectives. Alpha-beta pruning is described as a way to prune branches that cannot influence the game outcome to improve search efficiency. Planning is discussed as a way to find a sequence of actions to achieve a goal by representing the problem as an initial state, actions, transition model, and goal test.

Uploaded by

Nourhan Abdi
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Search Applications - Games: This Unit Has Two Main Sections Planning Learning Adaptation and Heuristics

The document discusses planning and search algorithms for game playing. It describes heuristics for the 8-puzzle game that estimate the number of misplaced tiles (h1) or the sum of distances of tiles from their goal positions (h2). The minimax algorithm is introduced for two-player games that assigns scores to game states based on the players' objectives. Alpha-beta pruning is described as a way to prune branches that cannot influence the game outcome to improve search efficiency. Planning is discussed as a way to find a sequence of actions to achieve a goal by representing the problem as an initial state, actions, transition model, and goal test.

Uploaded by

Nourhan Abdi
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 53

1 Search Applications -Games

This unit has two main sections


• Planning

• Learning adaptation and heuristics


2
Game heuristics
 we look at heuristics for the 8-puzzle, in order to shed light
on the nature of heuristics in general.
 The object of the puzzle is to slide the tiles horizontally or
vertically into the empty
space until the configuration matches the goal
configuration.
 The branching factor is about 3
 When the empty tile is in the middle, four moves are
possible.
 when it is in a corner, two
 when it is along an edge, three
3
8-puzzel
4
8-puzzle-heuristic definition
If we want to find the shortest solutions by using A∗, we need a
heuristic function that never overestimates the number of steps to the
goal.
One possible heuristic is:

h1 = the number of misplaced tiles.


For the past figure, all of the eight tiles are out of

position, so the start state would have h1 = 8.


h1 is an admissible heuristic because it is clear that

any tile that is out of place must be moved at least


once.
5
8-puzzle-heuristic definition
h2 = the sum of the distances of the tiles from their goal positions.
Because tiles cannot move along diagonals, the distance we will count is the sum of the horizontal
and vertical distances.
h2 is also admissible because all any move can do is move one tile one step closer to the goal.
Tiles 1 to 8 in the start state give a distance of
h2 = 3 + 1 + 2 + 2 + 2 + 3 + 3 + 2 = 18 .
6
Summary
 Before an agent can start searching for solutions, a
goal must be identified and a well defined problem
must be formulated.
 A problem consists of five parts: the initial state, a
set of actions, a transition model describing the
results of those actions, a goal test function, and a
path cost function.
 The environment of the problem is represented by a
state space. A path through the state space from
the initial state to a goal state is a solution.
 Search algorithms are judged on the basis of
completeness, optimality, time complexity, and space
complexity. Complexity depends on b, the branching
factor in the state space, and d, the depth of the
shallowest solution.
 Uninformed search methods have access only to
the problem definition. The basic algorithms are as
follows:
 Breadth-first search expands the shallowest nodes first, it has exponential
space complexity.
 Uniform-cost search expands the node with lowest path cost, g(n), and is
optimal for general step costs.
 Depth-first search expands the deepest unexpanded node first. it has linear
space complexity. Depth-limited search adds a depth bound.
 Iterative deepening search calls depth-first search with increasing depth limits
until a goal is found.
 Informed search methods may have access to a
heuristic function h(n) that estimates the cost of a
solution from n.
 The generic best-first search algorithm selects a node for expansion according to
an evaluation function.
 Greedy best-first search expands nodes with minimal h(n). It is not optimal but
is often efficient.
 A∗ search expands nodes with minimal f(n) = g(n) + h(n). A∗ is complete and
optimal, provided that h(n) is admissible (for TREE-SEARCH) or consistent (for
GRAPH-SEARCH). The space complexity of A∗ is still prohibitive.
9 Search- Enhancing
Our first step needs to be coming up with some way of evaluating the outcome
of a game.
In Stone, the outcomes are ‘win’ or ‘lose’ which we can give values of +1 and –
1, respectively.
Games like Scrabble give each player a score, which can be used to evaluate
game end positions.
We will call the two players MIN and MAX: MAX’s objective is to finish the
game with as high a score as possible, while MIN’s objective to finish the game
with the smallest score possible.
If we know the scores of all the children of a node in the game tree, we can
predict what MIN’s or MAX’s move would be. This allows us to assign the score
of the chosen child to this node, which can be used to determine the choice
made in the parent node. This is the basis of the minimax algorithm.
10 Search
I’ll show how the algorithm works by looking at the smaller example
search tree for a game of Stone(4, 2)
11 Search

we can see that a game of Stone(4, 2) always results in a loss for


the first player (assuming optimal play for both players).
12 Search

Apply the minimax algorithm to the game tree for Stone(5, 2) player
wins?
13 Search

MAX, by taking one stone initially.


14 Optimal decisions in multiplayer
games
• we need to replace the single value for each node with a
vector of values.
• For example, in a three-player game with players A, B, and
C, a vector <vA, vB, vC> is associated with each node.
• For terminal states, this vector gives the utility of the state
from each player’s viewpoint.

15
16 Search

Minimax is based on:


 Perfect information: each player knows
everything there is to know about the state of
the game
 Determinism: difference between deterministic

like stone and non deterministic like


backgammon. (rolling dice)
17 Search

The horizon problem: it is the inability to see the


consequences of moves.
18
Alpha beta pruning principle
• The problem with minimax search is that the number of
game states it has to examine is exponential in the
depth of the tree.
• The trick is that it is possible to compute the correct
minimax decision without looking at every node in the
game tree
• Prune away branches that
cannot possibly influence the final decision.
19
Alpha beta pruning principle
20 Search
Efficiency gains: α-β pruning
Alpha: value of best move for us seen so far in current search
path.
beta: best move for opponent (worst move for us) seen so far
in current search path.

If alpha >= beta, prune


Initial alpha: −∞
Initial beta: ∞

Some branches will never be played by rational players since


they include sub-optimal decisions (for either player).
21 Search
22 Search
23 Search
24 Search
25 Search
26 Search
27 Search
28 Search
29 Search
30 Search
31 Search
32 Search
33 Search
34 Search
35 Search
36 Search
37 Search
38 Search
39
Planning

devising a plan of action to achieve one’s goals


40 Symbolic AI in the world

Planning
 Planning might appear to be just another form of problem
solving.
 In Symbolic AI, problem solving consists of setting a system to
an initial state, defining a goal state and then defining all of the
possible actions our system can take.
 The system will search through the space of possible states
looking for a solution.
41 Symbolic AI in the world

Planning
 To take a simple example, consider solving the problem of
buying apples from a shop.
 The initial state is being at home with no apples, the goal
state is being back at home with some apples.
 Between the two lies a state space that may be something like
the one shown in following figure
42 Symbolic AI in the world
43 Symbolic AI in the world
Planning
This is an oversimplified picture of the problem:
 In reality, each level of the tree must have thousands, if not

millions, of branches and the tree itself might have hundreds of


levels.
 Exhaustive search of such a space is clearly infeasible, so

heuristic techniques have to be brought in to speed up searches


 A good heuristic would tell the system that shopping is a good way

of acquiring new items (including apples).


44 Symbolic AI in the world

Planning
 The search could then be directed along the shopping

branch.
 A further heuristic might then guide the search towards

shops that sell fruit.


 But a more serious difficulty is that it forces the system to

start either at the initial state or at the goal state and work
towards the other: the search program must examine each
of the initial actions before moving on to the next.
45 Symbolic AI in the world
Planning
 By comparison, planning relies on making direct connections
between states and actions.
 Computers describe plans which are composed of states, goals and
actions using a system of formal logic. ‘Have some apples’ is an
English language description of a goal;
 The logical expression Have(apples) is its equivalent.
 Actions are described in the same manner
46 Symbolic AI in the world

Planning
 Humans use their knowledge base to solve problems.

 Figure out a computer program attempting to solve


this simple problem: buying apples.

 With all the possible input and the encountered


constraints, this will not be an easy job!!
47 Symbolic AI in the world

Planning
 General actions: Buy(x), which results: having x
48 Symbolic AI in the world

Sub-Planning
 The planning process allows for the problem to be
broken into independent chunks known as sub-plans
 An example of the success and failure of sub-planning
is illustrated in the following sections: Blocks world.
49
Planning
The spare tire problem

The goal is to have a good spare tire properly mounted


onto the car’s axle, where the initial state has a flat
tire on the axle and a good spare tire in the trunk.
50
Planning
The spare tire problem

There are just four actions:


1. removing the spare from the trunk

2. removing the flat tire from the axle

3. putting the spare on the axle

4. leaving the car unattended overnight.


51
Planning
The spare tire problem

We assume that the car is parked in a particularly bad


neighborhood, so that the effect of leaving it
overnight is that the tires disappear.
Goal:
[Remove(Flat, Axle), Remove(Spare, Trunk),
PutOn(Spare, Axle)]
52
Planning
The spare tire problem

Initial state

Goal state
53
Action set

You might also like