Adversarial Search
Adversarial Search
• The initial state, which includes the board position and an indication of
whose move it is.
• A set of operators, which define the legal moves that a player can make.
• A terminal test, which determines when the game is over. States where the
game has ended are called terminal states.
• A utility function (also called a payoff function), which gives a numeric
value for the outcome of a game. In chess, the outcome is a win, loss, or
draw, which we can represent by the values +1, —1, or 0
Perfect Decisions in two person Games
• The general case of a game with two players, whom we will call MAX and
M1N,
• MAX moves first, and then they take turns moving until the game is over.
• At the end of the game, points are awarded to the winning player.
Perfect Decisions in two person Games
• MAX would have to search for a sequence of moves that leads to a terminal
state that is a winner then go ahead and make the first move in the sequence.
• Unfortunately, MIN has something to say about it.
• MAX therefore must find a strategy that will lead to a winning terminal
state regardless of what MIN does, where the strategy includes the correct
move for MAX for each possible move by MIN.
Tic-Tac-Toe Game tree (2-player, deterministic,
turns)
• From the initial state, has a choice of nine possible moves.
• Play alternates between MAX placing x's and MIN placing o's
until we reach leaf nodes corresponding to terminal states: states
where one player has three in a row or all the squares are filled.
• The number on each leaf node indicates the utility value of the
terminal state from the point of view of MAX; high values are
assumed to be good for MAX and bad for MIN.
• It is MAX'S job to use the search tree to determine the best
move.
Generate Game Tree
Searching with an opponent
Searching with an opponent
• Heuristic approximation: defining an evaluation function which indicates how close a
state is from a winning (or losing) move
• This function includes domain information.
• It does not represent a cost or a distance in steps.
• Conventionally:
• A winning move is represented by the value“+∞”.
• A losing move is represented by the value “-∞”.
• The algorithm searches with limited depth.
X O O X X O
X O O X X O O
Another Evaluation Function for Tic Tac Toe
X O O X X
O
e(n) = 6 - 4 = 2 e(n) = 4 - 3 = 1
Example Utility Functions for Chess
• Chess: Assume Max is “White”
• Assume each piece has the following values
• pawn = 1; knight = 3; bishop = 3;
• rook = 5; queen = 9;
• let w = sum of the value of white pieces
• let b = sum of the value of black pieces
• e(n) =
• w-b
• w+b
Note that this value ranges between 1 and -1
Example Utility Functions for Chess
• The previous evaluation function naively gave the same weight to a piece
regardless of its position on the board...
-
α= ∞
β=∞
-
α= ∞
β=∞
Alpha-beta pruning
• The leaves below B have the values 3, 12 and 8.
Condition
• The value of B is exactly 3.
α≥β
• It can be inferred that the value at the root is at least 3, because MAX has a choice worth 3.
α= ∞- α represents max
β=∞
β represents min
B
α= ∞-
β=∞
Alpha-beta pruning
• C, which is a MIN node, has a value of at most 2.
Condition
• But B is worth 3, so MAX would never choose C.
α≥β
• Therefore, there is no point in looking at the other successors of C.
α= ∞-
β=∞
B C α= ∞-
β=∞
Alpha-beta pruning
• D, which is a MIN node, is worth at most 14.
Condition
• This is still higher than MAX’s best alternative (i.e., 3), so D’s other successors are explored.
α≥β
α= ∞ -
β=∞
B C D
α= ∞ -
β=∞
Alpha-beta pruning
• The second successor of D is worth 5, so the exploration continues.
Condition
α= ∞ - α≥β
β=∞
B C D -
α= ∞
β=∞
Alpha-beta pruning
• The third successor is worth 2, so now D is worth exactly 2.
Condition
• MAX’s decision at the root is to move to B, giving a value of 3
-
α= ∞ α≥β
β=∞
-
α= ∞
B C D β=∞
Effectiveness of Alpha-Beta Search
• Worst-Case
• branches are ordered so that no pruning takes place. In this case alpha-beta gives no
improvement over exhaustive search
• Best-Case
• each player’s best move is the left-most child (i.e., evaluated first)
• in practice, performance is closer to best rather than worst-case
Alpha-Beta Pruning
• Pruning does not affect final results
• Entire subtrees can be pruned.
• Good move ordering improves effectiveness of pruning
Example
-which nodes can be pruned?
3 4 1 2 7 8 5 6
Answer to Example
Max
-which nodes can be pruned?
Answer: NONE! Because the most favorable
nodes for both are explored last (i.e., in the
diagram, are on the right-hand side).
Min
Max
5 6
3 4 1 2 7 8
Second Example
-which nodes can be pruned?
6 5 8 7 2 1 3 4
Second Example
Max -which nodes can be pruned?
Answer: LOTS! Because the most favorable
nodes for both are explored first (i.e., in the
diagram, are on the left-hand side).
Min
Max
3 4
6 5 8 7 2 1