Professional Documents
Culture Documents
CS 440/ECE 448
Fall 2020 Games 4
Margaret Fleck
Minimax is usually implemented using two mutually recursive functions, min-value and
max-value. The input to min-value should be a min node and min-value returns the
minimax value for that node. The function max-value does the same thing for an input max
node.
max-value (node)
1 of 4 5/10/21, 01:45
CS440 Lectures https://courses.grainger.illinois.edu/cs440/fa2020/lectures/ga...
min-value (node)
The above functions compute the value for the top node in the game tree. That will be
convenient for discussing alpha-beta pruning. However, it's not actually what you'll do if
you are implementing a game player. A game player needs his next move, not the value for
the root node of the tree (aka the current game state). So our game playing code starts with
a modified function at the top level which does this:
Choose-move(n)
Detailed code for choose-move is essentially similar to max-value, except that it returns
argmax rather than max.
Suppose that our search is at some node n. There may be a number of paths leading from
the root downwards to a leaf, via n. The "outcome" of a path is the value that it sends
upwards to the root (which might not be the best value that arrives at the root).
2 of 4 5/10/21, 01:45
CS440 Lectures https://courses.grainger.illinois.edu/cs440/fa2020/lectures/ga...
Suppose that v(n) is the value of our current node n (based on the children we have
examined so far). If there's still a chance that the best path goes through n, we must have
α ≤ v(n) ≤ β
As a node examines more and more of its children
v(n) > β or v(n) < α (No viable path through node n.)
v(n) = β or v(n) = α (No path through node n can improve on what we've
already found.)
Similarly, inside the inner loop for min-value, rv gradually decreases and so does beta. The
3 of 4 5/10/21, 01:45
CS440 Lectures https://courses.grainger.illinois.edu/cs440/fa2020/lectures/ga...
Yes, it's very easy to get parts of this algorithm backwards. We're not going to ask you to
produce this level of detail on an exam. Concentrate on understanding what branches will
be pruned, as shown in the previous lecture. But it's worth seeing the pseudocode briefly so
that you can feel confident that alpha-beta pruning isn't complicated if you ever need to
implement it.
4 of 4 5/10/21, 01:45