Lecture 14 Speeding up the Search
Speeding up the Search
Pruning the Search
Concept: In minimax search, not all parts of the game tree need to be explored. Some branches won't change the final decision, so we can ignore (prune) them to save time.
Why Prune?:
The goal is to find the optimal move without exhaustively searching every possibility.
Pruning reduces the number of nodes evaluated, making the search faster.
Hypothetical Tree Example:
Imagine a game tree where the AI (MAX) has explored two options:
Option A scores high.
Option B also scores well.
Option C: The values at unexplored nodes attached to node C can't change the outcome because node C's options are worse than what MAX already has from options A and B.
In Essence:
If the minimax value at a node (like C) is guaranteed to be worse than the best option already found, there's no need to explore further down that path.
Example: If MAX already has a move with a score of 2 (from node B), and node C can never be better than 2, prune node C’s subtree.
General Case: Pruning at a MIN Node
Scenario: You're exploring the game tree in a depth-first manner, from left to right.
Logic: If the utility (score) of a node will never be better (i.e., higher) than the utility of node or , you can stop searching through the subtree at .
MIN's Perspective: MIN wants to minimize the score. If a branch guarantees a score no worse than what MIN already has, further exploration is unnecessary.
General Case: Pruning at a MAX Node
Scenario: Depth-first exploration of the game tree, going from left to right.
Logic: If the utility of a node is guaranteed to be better than or equal to the utility of nodes or , you can prune the subtree at .
MAX's Perspective: MAX aims to maximize the score. If a branch can only lead to scores that are as good as or worse than what MAX already has, it can be ignored.
Alpha-Beta Pruning
Core Idea: Keep track of the best possible values (bounds) as you traverse the tree.
Alpha:
Represents the utility (score) of the best possible choice for MAX along the current path from the root.
It's the minimum score that MAX is guaranteed to achieve.
Beta:
Represents the utility of the best possible choice for MIN along the current path from the root.
It's the maximum score that MIN is guaranteed to achieve.
Exploration: Depth-first, left to right.
Passing Values: The alpha and beta values are passed down the tree during the search.
Alpha-Beta Search Algorithm
Two Functions: The algorithm is defined using two functions,
MAX-VALUEandMIN-VALUE.ALPHA-BETA-SEARCH(game, state):Purpose: Returns the best action for the current game state.
How it Works:
Determines whose turn it is (
game.TO-MOVE(state)).Calls
MAX-VALUEto find the best move and its value.Initializes alpha to negative infinity . (MAX wants to maximize, so start with the worst possible score.)
Initializes beta to positive infinity . (MIN wants to minimize, so start with the best possible score.)
Returns the chosen 'move'.
MAX-VALUE(game, state, a, ß):Purpose: Returns the (utility, move) pair for the MAX player.
How it Works:
If the state is a terminal state (game over), return the utility of the state for the player and a null move.
Initialize to negative infinity .
Iterate through each possible action in
game.ACTIONS(state).Call
MIN-VALUEto get the utility (score) and the opponent's counter move .If is greater than , update and 'move' with and , respectively (found a better move).
Update alpha: . (Update the best score MAX can guarantee.)
Pruning: If is greater than or equal to beta , return and 'move'. (No need to explore further; MIN will avoid this branch.)
Return and 'move'.
MIN-VALUE(game, state, a, ß):Purpose: Returns the (utility, move) pair for the MIN player.
How it Works:
If the state is a terminal state, return the utility of the state for the player and a null move.
Initialize to positive infinity .
Iterate through each action in
game.ACTIONS(state).Call
MAX-VALUEto get the utility and the opponent's counter move .If is less than , update and 'move' with and , respectively (found a better move for MIN).
Update beta: . (Update the best score MIN can guarantee.)
Pruning: If is less than or equal to alpha , return and move. (No need to explore further; MAX will avoid this branch.)
Return and 'move'.
Move Ordering
Default: Depth-first search explores the tree from left to right.
Importance of Order: The order in which moves are considered significantly affects pruning efficiency.
Observation: The amount of pruning depends on the order.
Optimal Ordering: Alpha-beta pruning with the best possible move ordering can explore a tree roughly twice as deep as minimax search in the same amount of time.
Limitation: Runtime remains exponential in the depth of the tree.
Heuristic Evaluation Functions
Challenge: Finding an optimal strategy for complex games is often impossible due to the vast search space.
Solution: Use an estimate of the value of a node instead of fully expanding its subtree.
Effect: Treat the node as if it were a terminal node and stop the search.
Heuristic Evaluation Function: Provides the utility estimate.
Example (Chess): A heuristic function could be based on the material value of each piece (e.g., queen = 9, rook = 5, etc.).
Application: Apply this estimate with a cutoff test to stop recursion in the search.
Machine Learning: Can be used to learn good heuristic functions if expert knowledge is lacking.
Cutting off the Search
Simple Cutoff: Limit the tree's depth to a certain value.
Problem: May miss important moves that occur further down the tree.
Horizon Effect: Outcomes beyond the depth limit might significantly change the heuristic score (e.g., an unavoidable checkmate).
Look-Ahead Techniques: Needed to mitigate the horizon effect.
Forward Pruning and Lookup Tables
Forward Pruning: Prune moves that appear weak or suboptimal early on.
Beam Search: Only consider the k “best” moves, based on the evaluation function.
Probabilistic Alpha-Beta: Prune nodes if they are likely to fall outside the alpha-beta window.
Adaptive Depth Limiting: Limit the depth of alpha-beta search more aggressively for nodes that seem poor compared to others.
Lookup Tables:
Store known good moves for certain positions (e.g., opening moves in chess).
Can be combined with game tree search for improved performance.