Cs 171 07a Games MiniMax
Cs 171 07a Games MiniMax
Cs 171 07a Games MiniMax
Types of Games
battleship
Kriegspiel
Not Considered:
Physical games like tennis, croquet, ice hockey, etc.
(but see robot soccer http://www.robocup.org/)
Typical assumptions
Two agents whose actions alternate
Utility values for each agent are the opposite of the other
This creates the adversarial situation
Fully observable environments
In game theory terms:
Deterministic, turn-taking, zero-sum, perfect information
Generalizes: stochastic, multiple players, non zero-sum, etc.
Compare to, e.g., Prisoners Dilemma (p. 666-668, R&N)
NON-turn-taking, NON-zero-sum, IMperfect information
Games adversary
Solution is strategy
strategy specifies move for every possible opponent reply.
Time limits force an approximate solution
Evaluation function: evaluate goodness of game position
Examples: chess, checkers, Othello, backgammon
Games as Search
MAX moves first and they take turns until the game is over
Winner gets reward, loser gets penalty.
Zero sum means the sum of the reward and the penalty is a constant.
Initial state: Set-up specified by the rules, e.g., initial board set-up of chess.
Player(s): Defines which player has the move in a state.
Actions(s): Returns the set of legal moves in a state.
Result(s,a): Transition model defines the result of a move.
Terminal-Test(s): Is the game finished? True if finished, false otherwise.
Utility function(s,p): Gives numerical value of terminal state s for player p.
E.g., win (+1), lose (-1), and draw (0) in tic-tac-toe.
E.g., win (+1), lose (0), and draw (1/2) in chess.
An optimal procedure:
The Min-Max method
Will find the optimal strategy and best next move for Max:
1. Generate the whole game tree, down to the leaves.
2. Apply utility (payoff) function to each leaf.
3. Back-up values from leaves through branch nodes:
a Max node computes the Max of its child values
a Min node computes the Min of its child values
4. At root: Choose move leading to the child of highest value.
Properties of minimax
Complete?
Yes (if tree is finite).
Optimal?
Yes (against an optimal opponent).
Can it be beaten by an opponent playing sub-optimally?
No. (Why not?)
Time complexity?
O(bm)
Space complexity?
O(bm) (depth-first search, generate all actions at once)
O(m) (backtracking search, generate actions one at a time)
Tic-Tac-Toe
b 5 legal actions per state on average, total of 9 plies in game.
ply = one action by one player, move = two plies.
59 = 1,953,125
9! = 362,880 (Computer goes first)
8! = 40,320 (Computer goes second)
exact solution quite reasonable
Chess
b 35 (approximate average branching factor)
d 100 (depth of game tree for typical game)
bd 35100 10154 nodes!!
exact solution completely infeasible
Typical values :
-infinity (loss) to +infinity (win) or [-1, +1] or [0, +1].
Board evaluation X for player is -X for opponent
Zero-sum game (i.e., scores sum to a constant)
Example:
1. P-QR4 P-QR4; 2. P-KR4 P-KR4
leads to the same position as
1. P-QR4 P-KR4; 2. P-KR4 P-QR4
Summary