Download Game playing

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Choice modelling wikipedia , lookup

Transcript
GAME PLAYING
By
Dr.A.S.Alvi
GAME-PLAYING

There were two reasons that games appeared to be a good
domain in which to explore machine intelligence.
1. They provide a structured task in which it is
very easy to measure success or failure.
2. They did not obviously require large amount of
knowledge. They were thought to be solvable
by straightforward search from the starting
state to winning state.
The first of these reason remain valid &
accounts for continued interest in the area of game
playing by machine.
GAME-PLAYING
Unfortunately, the second is not true for complex
games. For ex the chess.
Thus it is clear that a program that simply does
a straightforward search of the game tree will not be
able to select even its first move during the lifetime
of its opponent.
So some kind of heuristic search procedure is
necessary.
Generate-and-test
1. The generator generates entire proposed
solutions, which the tester then evaluates.
2. The generator generates individual moves in the
search space, each of which is then evaluates by the
tester and most promising one is chosen.
GAME-PLAYING
Thus two improve the effectiveness of a
search based, problem-solving program there are
two things to be done.
1. Improve the generate procedure so that only
good moves (or paths) are generated.
2. Improve the test procedure so that the best
moves (or paths) will be recognized and explored
first.
SEARCH AND GAME PLAYING

Consider a board game
 e.g., chess, checkers, tic-tac-toe
 configuration of the board = unique arrangement of
“pieces”
 each possible configuration = state in search space

Statement of Game as a Search Problem
 States = board configurations
 Operators = legal moves
 Initial State = current configuration
 Terminal State (Goal) = winning configuration
GAME TREES


Represent the problem space for a game by a tree

Nodes represent ‘board positions’ (state)

edges represent legal moves.
Root node is the position in which a decision
must be made.

Evaluation function f assigns real-number
scores to `board positions.’

Terminal nodes (leaf) represent ways the game
could end, labeled with the desirability of that
ending (e.g. win/lose/draw or a numerical score)
MAX & MIN NODES

When I move, I attempt to MAXimize my performance.

When my opponent moves, he attempts to MINimize my
performance.
TO REPRESENT THIS:

If we move first, label the root MAX; if our opponent does,
label it MIN.

Alternate labels for each successive tree level.

if the root (level 0) is our turn (MAX), all even levels
will represent turns for us (MAX), and all odd ones
turns for our opponent (MIN).
EVALUATION FUNCTIONS

Evaluations how good a ‘board position’ is


Based on static features of that board alone
Zero-sum assumption lets us use one function to
describe goodness for both players.


f(n)>0 if we are winning in position n

f(n)=0 if position n is tied

f(n)<0 if our opponent is winning in position n
Build using expert knowledge (Heuristic),
GAME TREE REPRESENTATION
Our
Move
S
Opponent
Moves
Our
Moves
G
Possible Goal State
lower in Tree (winning situation for computer)
MINIMAX EXAMPLE
3 6
Max
Min
Max
5
6
5 3
1 3
1
3
0 7
6
5
2
The computer can
obtain 6 by choosing
the right hand edge
from the first node.
6
2
CS 484 – Artificial Intelligence
0
7
10
UTILITY FUNCTIONS

Utility Function:
 defined for each terminal state in a game

assigns a numeric value for each terminal state

these numbers represent how “valuable” the state
is for the computer
 positive for winning
 negative for losing
 zero for a draw

Typical values from -infinity (lost) to +infinity
(won) or [-1, +1].
PROPAGATING MINIMAX VALUES UP THE GAME TREE

Starting from the leaves

Assign a value to the parent node as follows
Children are Opponent’s moves: Minimum of all immediate
children
 Children are Computer’s moves: Maximum of all immediate
children

DEEPER GAME TREES

Minimax can be generalized to deeper game trees
(than just 2 levels): “propagate” utility values
upwards in the tree
GENERAL MINIMAX ALGORITHM ON A GAME TREE
For each move by the computer
1.perform depth-first search as far as the
terminal state
2. assign utilities at each terminal state
3. propagate upwards the minimax choices
if the parent is a minimizer (opponent)
propagate up the minimum value
of the children
if the parent is a maximizer (computer)
propagate up the maximum value
of the children
4. choose the move (the child of the current
node) corresponding to the maximum or
the minimax values if the children
GENERAL MINIMAX ALGORITHM ON A GAME TREE
For each move by the computer
1.perform depth-first search as far as the
terminal state
2. assign utilities at each terminal state
3. propagate upwards the minimax choices
if the parent is a minimizer (opponent)
propagate up the minimum value
of the children
if the parent is a maximizer (computer)
propagate up the maximum value
of the children
4. choose the move (the child of the current
node) corresponding to the maximum of
the minimax values if the children
MINIMAX ALGORITHM
function MINIMAX-DECISION(state) returns an action
inputs: state, current state in game
v←MAX-VALUE(state)
return the action in SUCCESSORS(state) with value v
function MAX-VALUE(state) returns a utility value
if TERMINAL-TEST(state) then return UTILITY(state)
v←−∞
for a,s in SUCCESSORS(state) do
v←MAX(v,MIN-VALUE(s))
return v
MINIMAX ALGORITHM
function MIN-VALUE(state) returns a utility value
if TERMINAL-TEST(state) then return
UTILITY(state)
v←∞
for a,s in SUCCESSORS(state) do
v←MIN(v,MAX-VALUE(s))
return v
MINIMAX ALGORITHM
THE ALPHA-BETA PROCEDURE
Example:
max
min
max
min
THE ALPHA-BETA PROCEDURE
Example:
ma
x
min
ma
x
=4
4
min
THE ALPHA-BETA PROCEDURE
Example:
ma
x
min
ma
x
=4
4 5
min
THE ALPHA-BETA PROCEDURE
Example:
ma
x
min
=3
=3
4 5 3
ma
x
min
THE ALPHA-BETA PROCEDURE
Example:
ma
x
min
ma
x
=3
=3
=1
4 5 3 1
min
THE ALPHA-BETA PROCEDURE
Example:
ma
x
min
=3
ma
x
=3
=3
=1
4 5 3 1
=8
8
min
THE ALPHA-BETA PROCEDURE
Example:
ma
x
min
=3
ma
x
=3
=3
=1
4 5 3 1
=6
8 6
min
THE ALPHA-BETA PROCEDURE
Example:
ma
x
min
=3
=3
=3
=6
=1
4 5 3 1
=6
8 6 7
ma
x
min
THE ALPHA-BETA PROCEDURE
=3
Example:
min
=3
=3
=3
=6
=1
4 5 3 1
ma
x
=6
8 6 7
ma
x
min
THE ALPHA-BETA PROCEDURE
=3
Example:
ma
x
min
=3
=3
=3
ma
x
=6
=1
4 5 3 1
=6
8 6 7
=2
2
min
THE ALPHA-BETA PROCEDURE
=3
Example:
ma
x
min
=3
=3
=3
=6
=1
4 5 3 1
=6
8 6 7
=3
=2
2
ma
x
min
THE ALPHA-BETA PROCEDURE
=3
Example:
ma
x
min
=3
=3
=3
=6
=1
4 5 3 1
=6
8 6 7
ma
x
=3
=2
2
=5
5
min
THE ALPHA-BETA PROCEDURE
=3
Example:
ma
x
min
=3
=3
=3
=6
=1
4 5 3 1
=6
8 6 7
ma
x
=3
=2
2
=4
5 4
min
THE ALPHA-BETA PROCEDURE
=3
Example:
ma
x
=3
=3
=3
=4
=6
=1
4 5 3 1
=6
8 6 7
ma
x
=4
=2
2
min
=4
5 4 4
min
THE ALPHA-BETA PROCEDURE
=3
Example:
ma
x
=3
=3
=3
=6
=1
4 5 3 1
min
=4
=6
8 6 7
ma
x
=4
=2
2
=4
=6
5 4 4
6
min
THE ALPHA-BETA PROCEDURE
=3
Example:
ma
x
=3
=3
=3
=6
=1
4 5 3 1
min
=4
=6
8 6 7
ma
x
=4
=2
2
=4
=6
5 4 4
6 7
min
THE ALPHA-BETA PROCEDURE
=4
Example:
ma
x
=3
=3
=3
=6
=1
4 5 3 1
min
=4
=6
=4
=2
8 6 77 2 7 2
=6
=4
4 5
=6
5 4 4
6 7 7
ma
x
min
THE ALPHA-BETA PROCEDURE
=4
Example:
Done!
=3
=3
=3
=1
4 5 3 1
min
=4
=6
=6
8 6 7
=4
=2
2
=6
=4
ma
x
=6
5 4 4
6 7 7
ma
x
min
ALPHA-BETA PRUNING
 Traverse
the search tree in depth-first order
 At each MAX node n, alpha(n) = maximum value
found so far
 At each MIN node n, beta(n) = minimum value
found so far

The alpha values start at -∞ and only increase, while
beta values start at +∞ and only decrease
 Beta
cutoff: Given MAX node n, cut off search
below n (i.e., don’t generate/examine any more of
n’s children) if alpha(n) >= beta(i) for some MIN
node ancestor i of n.
 Alpha cutoff: stop searching below MIN node n if
beta(n) <= alpha(i) for some MAX node ancestor i of
n.
ALPHA-BETA PRUNING
 We
can improve on the performance of the
minimax algorithm through alpha-beta
pruning
 Basic idea: “If you have an idea that is
surely bad, don't take the time to see how
truly awful it is.” -- Pat Winston
MAX
MIN
>=2
=2
• We don’t need to compute
the value at this node.
<=1
MAX
2
7
1
?
• No matter what it is, it
can’t affect the value of
the root node.