Artificial IntelligenceUnit 410 min read
Informed Search & Game Playing: Heuristics, A, Minimax, Alpha-Beta
Unit 4 of Artificial Intelligence explores how AI agents make smarter decisions by using domain knowledge (heuristics) to guide search, and how adversarial games like chess or Poker are solved using minimax with alpha-beta pruning. Covers A search, game trees, evaluation functions, and real-world applications in logist
Key Concepts and Techniques
1. Informed Search: Heuristic Search Algorithms
Informed search algorithms use heuristics (rules of thumb) to guide the search toward the goal state more efficiently than uninformed search (BFS/DFS). The key idea is to estimate the cost to reach the goal from any given state.
Heuristic Function (h(n))
A heuristic function estimates the cost from a node n to the goal. It must satisfy:
- Admissibility: Never overestimates the true cost (h(n) ≤ actual cost).
- Consistency (Monotonicity): For any node
nand successorn', h(n) ≤ c(n, n') + h(n').
A Search Algorithm*
A* combines the benefits of Dijkstra’s algorithm (optimal path) and Greedy Best-First Search (fast but not always optimal). It uses:
- f(n) = g(n) + h(n)
g(n): Cost from start to noden(known).h(n): Heuristic estimate fromnto goal (unknown but admissible).
How A Works:*
- Start at the initial node, add it to the open list (priority queue).
- While the open list is not empty:
- Expand the node
nwith the lowestf(n). - If
nis the goal, return the path. - Else, generate successors, calculate
ffor each, and add to open list. - Move
nto the closed list (explored nodes).
- Expand the node
- If open list is empty, no solution exists.
Worked Example: Delivery Route Optimization (Like Pathao/Khalti)
Suppose a delivery agent must go from Kathmandu to Pokhara via Bhaktapur and Dhulikhel, with the following heuristic distances (in km):
- h(Kathmandu) = 200 (direct distance to Pokhara).
- h(Bhaktapur) = 150.
- h(Dhulikhel) = 120.
Graph:
graph TD
A["Kathmandu"] -->|"10"| B["Bhaktapur"]
A -->|"15"| C["Dhulikhel"]
B -->|"20"| D["Pokhara"]
C -->|"25"| DStep-by-Step A Search:*
| Node | g(n) | h(n) | f(n) = g(n) + h(n) | Path Taken |
|---|---|---|---|---|
| Kathmandu | 0 | 200 | 200 | Start |
| Bhaktapur | 10 | 150 | 160 | Kathmandu → Bhaktapur |
| Dhulikhel | 15 | 120 | 135 | Kathmandu → Dhulikhel |
| Pokhara | 30 | 0 | 30 | Bhaktapur → Pokhara |
Optimal Path: Kathmandu → Dhulikhel → Pokhara (total cost = 40 km).
Why? A* picks the path with the lowest f(n) at each step, ensuring optimality.
2. Game Playing: Minimax and Alpha-Beta Pruning
Games involve adversarial search, where two players (MAX and MIN) take turns. The goal is to maximize/minimize the outcome.
Minimax Algorithm
- MAX player tries to maximize the score.
- MIN player tries to minimize the score.
- The algorithm recursively evaluates all possible moves to the terminal state (end of the game) and backpropagates the best value.
Game Tree Example (Tic-Tac-Toe):
Worked Example: Tic-Tac-Toe (Simplified) Assume the following payoffs:
- X wins: +10
- Draw: 0
- O wins: -10
Minimax Evaluation:
Leaf Nodes (Terminal States):
- X wins at (2,1): +10
- Draw at (2,2): 0
- O wins at (1,3): -10
Backpropagation:
- For
O at (1,3), MIN chooses the worst option for MAX → -10. - For
O at (2,1), MAX chooses the best between +10 (X wins) and 0 (draw) → +10. - For
O at (2,2), MIN chooses 0 (draw).
- For
Final Decision:
- MAX picks the move leading to the highest value: X at (1,1) (value = +10).
Alpha-Beta Pruning
Minimax explores all possible moves, which is inefficient. Alpha-Beta Pruning eliminates branches that cannot affect the final decision.
- Alpha (α): Best value that MAX can guarantee so far.
- Beta (β): Best value that MIN can guarantee so far.
- If
α ≥ β, prune the remaining branches.
Example with Pruning:
Steps:
- Start with
α = -∞,β = +∞. - Evaluate
X at (1,1):O at (2,1)→ X wins (+10). Updateα = max(-∞, 10) = 10.- Since
α (10) ≥ β (∞)is false, continue. O at (2,2)→ Draw (0). No change toα.
- Now, evaluate
X at (1,2):O at (1,3)→ O wins (-10). Sinceα (10) ≥ β (-10)is true, prune the rest of the subtree underX at (1,2).
Result: Only the left subtree is explored, saving computation.
3. Comparison of Search Algorithms
| Algorithm | Time Complexity | Optimality | Use Case | Heuristic Needed? |
|---|---|---|---|---|
| BFS | O(b^d) | Yes | Shortest path in unweighted graphs | No |
| DFS | O(b^m) | No | Deep but narrow state spaces | No |
| Greedy | O(b^d) | No | Fast but suboptimal | Yes |
| A* | O(b^d) | Yes | Optimal pathfinding (e.g., GPS) | Yes (admissible) |
| Minimax | O(b^d) | Yes | Two-player games (e.g., Chess) | No |
| Alpha-Beta | O(b^(d/2)) | Yes | Efficient game playing | No |
4. Applications in the Real World
1. Pathao/Khalti Delivery Routing
- Idea Used: A Search*
- How? Pathao optimizes delivery routes by:
- Using
g(n)= distance traveled so far. - Using
h(n)= estimated distance to destination (e.g., straight-line distance via Google Maps API). - Avoiding traffic-heavy routes (dynamic
h(n)).
- Using
2. Ncell’s Network Optimization
- Idea Used: A Search*
- How? Ncell uses A* to:
- Route calls through the least congested towers.
- Minimize latency by choosing the shortest path with the best signal strength (
h(n)).
3. Daraz’s Warehouse Inventory Management
- Idea Used: Minimax + Alpha-Beta Pruning
- How? Daraz uses game theory to:
- Predict customer demand (MAX player).
- Optimize stock levels (MIN player: cost of overstocking vs. understocking).
- Prune irrelevant demand scenarios to speed up decisions.
4. Chess Engines (Stockfish, Leela Chess Zero)
- Idea Used: Minimax with Alpha-Beta Pruning
- How? These engines:
- Evaluate board positions using heuristics (e.g., piece values, mobility).
- Prune millions of irrelevant moves to focus on promising ones.
- Use transposition tables to cache previously evaluated positions.
5. Self-Driving Cars (Tesla, Ncell’s Autonomous Vehicles)
- Idea Used: A Search + Game Trees*
- How? Tesla’s Autopilot:
- Uses A* to plan the shortest path around obstacles (
h(n)= distance to goal + safety margin). - Models pedestrian/car interactions as a game tree (pedestrian = MIN player trying to cross; car = MAX player avoiding collision).
- Uses A* to plan the shortest path around obstacles (
5. Limitations and Challenges
| Issue | Explanation |
|---|---|
| Heuristic Design | Poor heuristics lead to suboptimal paths (e.g., ignoring traffic in A*). |
| Combinatorial Explosion | Game trees grow exponentially (e.g., Chess has ~10^120 possible games). |
| Dynamic Environments | A* assumes static h(n), but real-world paths change (e.g., traffic jams). |
| Evaluation Function Quality | In games, a weak evaluation function (e.g., only piece count) loses to humans. |
Solutions:
- Iterative Deepening A* (IDA*): Combines A* with depth-limited search.
- Monte Carlo Tree Search (MCTS): Used in AlphaGo for better heuristic learning.
- Reinforcement Learning: Adjusts
h(n)dynamically (e.g., Tesla’s self-driving updates route heuristics based on real accidents).
Exam Tip
For A Search:*
- Always show the priority queue (open list) and closed list in your worked example.
- Explain why a heuristic is admissible (e.g., "Manhattan distance is admissible for grid-based paths").
- Compare A* with Greedy Best-First Search (Greedy ignores
g(n); A* considers bothg(n)andh(n)).
For Minimax/Alpha-Beta:
- Draw the game tree and mark pruned branches in Alpha-Beta.
- Memorize the order of evaluation: MAX → MIN → MAX (alternating).
- For Alpha-Beta, highlight where
α ≥ βcauses pruning.
Common Pitfalls:
- Forgetting to expand nodes in order of increasing
f(n)in A*. - Misapplying admissibility (e.g., using Euclidean distance as
h(n)in a grid with obstacles). - In games, not evaluating terminal states correctly (e.g., missing a forced win).
- Forgetting to expand nodes in order of increasing
Real-World Links:
- Expect route optimization questions (like Pathao/Khalti).
- Expect game theory questions (like Chess engines or Poker bots).
- Always relate heuristics to real-world constraints (e.g., "traffic slows down
h(n)").
Based on the TU BITM syllabus for Artificial Intelligence (IT228), unit 4.
Discussion
Loading…