Sie sind auf Seite 1von 19

Minimax procedure

Create start node as a MAX node with current board


configuration
Expand nodes down to some depth (a.k.a. ply) of
lookahead in the game
Apply the evaluation function at each of the leaf nodes
Back up values for each of the non-leaf nodes until a
value is computed for the root node
At MIN nodes, the backed-up value is the minimum of the
values associated with its children.
At MAX nodes, the backed up value is the maximum of the
values associated with its children.

Pick the operator associated with the child node whose


backed-up value determined the value at the root

Minimax Algorithm
2
1

2
2

7 1

Static evaluator
value

7 1

7 1

This is the move


selected by minimax

MAX
MIN

7 1

Minimax Tree
MAX node

MIN node

f value

value computed
by minimax

Minimax Principle

Assume the worst


say we are two plays (in the tree) away from the
terminal states
high numbers favor the computer
so we want to choose moves which maximize utility
low numbers favor the opponent
so they will choose moves which minimize utility

Minimax Principle
you (the computer) assume that the opponent will
choose the minimizing move next (after your move)
so you now choose the best move under this
assumption
i.e., the maximum (highest-value) option considering
both your move and the opponents optimal move.
we can generalize this argument more than 2 moves

Minimax Search Example

Explore the tree as far as the terminal states


Calculate utilities for the resulting board configurations
The computer will make the move such that when the opponent
makes his best move, the board configuration will be in the best
position for the computer

Propagating Minimax Values up the


Starting from the leaves
Game Tree
Assign a value to the parent node as follows
Children are Opponents moves: Minimum of all
immediate children
Children are Computers moves: Maximum of all
immediate children

Deeper Game Trees

nimax 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) correspo
to the maximum of the minimax values if the children
Note:
- minimax values are gradually propagated upwards as depth-first
search proceeds, i.e., minimax values propagate up the tree in
a left-to-right fashion

Complexity of Minimax
Algorithm

Assume that all terminal states are at depth d


Space complexity
depth-first search, so O(bd)
Time complexity
branching factor b, thus, O(bd)

The O(bd) time complexity is a major problem since the computer typically only has a
finite amount of time to make a move,
e.g., in chess, 2 minute time-limit, but b=35, d=50 !

So

the direct minimax algorithm is impractical in practice


instead what about depth-limited search to depth m?
but utilities are defined only at terminal states
=> need to know the utility of non-terminal states
these are called heuristic/static evaluation functions

Idea of Static Evaluation


Functions

An Evaluation Function:
provide an estimate of how good the current board
configuration is for the computer.
think of it as the expected utility averaged over all
possible game outcomes from that position
it reflects the computers chances of winning from that
node
but it must be easy to calculate, i.e., cannot involve
searching the tree below the depth-limit node
thus, we use various easily calculated heuristics, e.g.,
Chess: Value of all white pieces - Value of all black
pieces
Typically, one figures how good it is for the computer,
and how good it is for the opponent, and subtracts the
opponents score from the computers

Must agree with the utility function when calculated at


terminal nodes

Minimax with Evaluation


For each move by the computer
Functions
1. perform depth-first search with depth-limit m
2. assign evaluation functions at each state at depth m
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

The same as general minimax, except


only goes to depth m
uses evaluation functions (estimates of utility)

How would this algorithm perform at chess?


could look ahead about 4 ply (pairs of moves)
would be consistently beaten even by average chess players!

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>=2
truly awful it is. -- Pat
MAX
We dont need to
Winston
compute the value at
MIN

=2

<=1

MAX
2

this node.
No matter what it is, it
cant affect the value
of the root node.

The Alpha Beta Principle: Marry Search


Tree Generation with Position Evaluations
1
Computer's

-8

Opponents Moves
(min of evaluations)

3 4

2 0

-8
X

X (X indicates not evaluated)

Alpha Beta Procedure

Depth first search of game tree, keeping track of:


Alpha: Highest value seen so far on maximizing level
Beta: Lowest value seen so far on minimizing level

Pruning
When Maximizing,
do not expand any more sibling nodes once a node has
been seen whose evaluation is smaller than Alpha
When Minimizing,
do not expand any sibling nodes once a node has been
seen whose evaluation is greater than Beta

The minimax algorithm is a way of finding an


optimal move in a two player game. Alpha-beta
pruning is a way of finding the optimal minimax
solution while avoiding searching subtrees of
moves which won't be selected. In the search
tree for a two-player game, there are two kinds
of nodes, nodes representing your moves and
Alpha-Beta
Pruning getsyour
its name
from the following
two terms:
nodes
representing
opponent's
moves.

alpha () = the value of the best choice at any node for the MAX
algorithm
beta () = the value of the best choice at any node for the MIN
algorithm

The Alpha-Beta
Procedure
Alpha-beta pruning is a procedure
to reduce the amount of computation
and searching during minimax.
Minimax is a two-pass search, one
pass is used to assign heuristic values
to the nodes at the ply depth and the
second is used to propagate the values
up the tree.

Alpha-beta search proceeds in a depth-first fashion.


An alpha value is an initial or temporary value
associated with a MAX node. Because MAX nodes are
given the maximum value among their children, an
alpha value can never decrease; it can only go up.
A beta value is an initial or temporary value
associated with a MIN node. Because MIN nodes are
given the minimum value among their children, a beta
value can never increase; it can only go down.

For example, suppose a MAX node's alpha


= 6. Then the search needn't consider
any branches emanating from a MIN
descendant that has a beta value that is
less-than-or-equal to 6. So if you know
that a MAX node has an alpha of 6, and
you know that one of its MIN descendants
has a beta that is less than or equal to 6,
you needn't search any further below that
MIN node. This is called alpha pruning.

For example, suppose a MAX node's alpha = 6. Then the


search needn't consider any branches emanating from a MIN
descendant that has a beta value that is less-than-or-equal to
6. So if you know that a MAX node has an alpha of 6, and you
know that one of its MIN descendants has a beta that is less
than or equal to 6, you needn't search any further below that
MIN node. This is called alpha pruning.
The reason is that no matter what happens below that MIN
node, it cannot take on a value that is greater than 6. So its
value cannot be propagated up to its MAX (alpha) parent.
Similarly, if a MIN node's beta value = 6, you needn't search
any further below a descendant MAX that has acquired an
alpha value of 6 or more. This is called beta pruning.
The reason again is that no matter what happens below that
MAX node, it cannot take on a value that is less than 6. So its
value cannot be propagated up to its MIN (beta) parent.
Rules for Alpha-beta Pruning
Alpha Pruning: Search can be stopped below any MIN node
having a beta value less than or equal to the alpha value of
any of its MAX ancestors.
Beta Pruning: Search can be stopped below any MAX node
having a alpha value greater than or equal to the beta value

Das könnte Ihnen auch gefallen