2. Introduction
• The minimax algorithm is a way of finding an optimal move in a two
player game. In the search tree for a two-player game, there are two kinds
of nodes, nodes representing yourmoves and nodes representing your
opponent's moves. Nodes representing your moves are generally drawn as
squares (or possibly upward pointing triangles):
• Below given symbols are also called MAX nodes. The goal at a MAX node
is to maximize the value of the subtree rooted at that node. To do this, a
MAX node chooses the child with the greatest value, and that becomes the
value of the MAX node.
2
3. • Below given are called MIN nodes. The goal at a MIN node is to minimize
the value of the subtree rooted at that node. To do this, a MIN node chooses
the child with the smallest value, and that becomes the value of the MIN
node.
3
5. Example: tic-tac-toe
• e (evaluation function → integer) = number of
available rows, columns, diagonals for MAX -
number of available rows, columns, diagonals
for MIN
• MAX plays with “X” and desires maximizing e.
• MIN plays with “0” and desires minimizing e.
• Symmetries are taken into account.
• A depth limit is used (2, in the example).
5
9. Example
• To demonstrate the minimax algorithm, I'm going to use the following tree.
Note that it's typical for two player games to have different branching
factors at each node. The move I make could make restrictions on what
moves are possible for the other player, or possibly remove restrictions.
Note also that in this example, we're ignoring what the game or the probem
space are in order to focus on the algorithm.
9
10. Example
• So now you've seen the whole search tree. For the rest of the diagrams, I'll
only show the portion of the tree that we've already explored at that
particular time. Thus, when we start the problem, all minimax sees is the
start node:
10
11. Example
• It begins like a depth first search, generating the first child. Then we see
this:
11
12. Example
• So far we've really seen no
evaluation values. The way
minimax works is to go down a
specified number of full moves
(where one "full move" is actually
a move by you and a move by your
opponent), then calculate
evaluation values for states at that
depth. For this example, we're
going to go down one full move,
which is one more level. When we
generate the values for those nodes,
here is what we see:
12
13. Example
• Now we have the values of the
children of the min node, so it
can do its work. It chooses the
minimum of the two child node
values, which is 3. Now we
have this:
13
14. Example
• The max node at the top still
has two other children nodes
that we need to generate and
search. We go on and generate
the second node and generate its
child. Since there is only one
child, the min node must take
it's value, and we have this:
14
15. Example
• Finally, minimax generates the
third child of the top-level max
node, generates its children, and
evaluates them:
15
16. Example
• Now the third min node chooses the
minimum of it's child node values, 1, and
we have this:
16
17. Example
• Finally we have all of the values of
the children of the max node at the
top level, so it chooses the
maximum of them, 15, and we get
the final solution:
17
18. Analysis
• The minimax algorithm performs a complete
depth-first exploration of the game tree.
• In minimax, at each point in the process, only
the nodes along a path of the tree are
considered and kept in memory.
18
19. Analysis
• If the maximum depth of the tree is m, and
there are b legal moves at each point, then
the time complexity is O(bm).
• The space complexity is:
– O(bm) for an algorithm that generates all
successors at once
– O(m) if it generates successors one at a time.
19