University Notes: Adversarial Search and Planning
Adversarial Search (Chapter 4)
Definition: Searching in situations where other agents or entities are outside our control.
Worst-Case Assumption: We model other agents as opponents (adversaries) to ensure the system can handle the worst-case scenario.
Game Trees: An abstract representation of games (like Chess or Tic-Tac-Toe).
Nodes: Represented by Squares (Agent's move) and Circles (Opponent's move).
Root Node: The starting position of the game.
Terminal/Leaf Nodes: The end of the game, evaluated with a result (e.g., for a win, for a loss, for a draw).
The Minimax Algorithm
Concept: Determines the optimal move by assuming the opponent plays perfectly. It alternates between maximizing the agent's reward and minimizing the agent's reward (from the opponent's perspective).
Process:
Create the entire Game Tree from the initial state to the terminal nodes (Brute Force).
Evaluate the terminal states (win/loss/draw).
Inherit values upward through the tree:
If the node is a Maximizer (Square), take the maximum value among its children.
If the node is a Minimizer (Circle), take the minimum value among its children.
Stop when the root node is evaluated. The result identifies the best move for the starting agent.
Non-Binary Outcomes: Minimax also works for games with numerical scores. The logic remains the same (selecting the minimum or maximum integer value).
Computational Limits and State Spaces
Tic-Tac-Toe: possible states. It is a simple game that can be solved completely by Minimax.
Connect Four: (4.5 trillion) states. Solved in 1988; the first player can guarantee a win with perfect play.
Checkers (Draughts): Approximately states. Solved in 2007 after 18 years of computation. Perfect play leads to a draw.
Chess: State space is between and . Brute forcing the entire tree is impossible. Deep Blue (1997) was a major milestone beat Gary Kasparov.
Go: Approximately states. Traditional heuristics used for chess do not work well. DeepMind's AlphaGo used deep learning to conquer this.
Heuristic Minimax
Depth-Limited Search: Because full trees are too large, agents generate trees for a specific number of moves (depth) and then stop.
Evaluation Function: In place of terminal nodes (where the winner is known), a heuristic evaluates the "quality" of the current state.
Chess Heuristics Example: Assigning values to pieces:
Queen:
Rook:
Bishop:
Knight:
Pawn:
A simple heuristic calculation: .
General Game AI & Monte Carlo Tree Search (MCTS)
Agnosticism: MCTS works without pre-existing domain knowledge (no predefined heuristics).
Process: Evaluates states based on the win rate from random playouts (simulations).
Random Playouts: From a child state, the agent plays the game randomly thousands of times and records the percentage of wins. High win rates suggest a strong starting move.
Selection Balance (UCT):
Exploitation: Focusing on moves that are already known to perform well.
Exploration: Trying moves that haven't been tested much to see if they might be better.
UCB1 Formula (Upper Confidence Bound): UCB1 = \bar{X}_j + C \times \root \frac{\text{ln}(N)}{n_j}
: Average reward/result of node .
: Exploration constant (determines how often to try "worse" things).
: Total visits to the parent node.
: Visits to node .
Phases of MCTS:
Selection: Navigate the tree to a leaf node using UCB1.
Expansion: Create a new child node.
Simulation: Run a random playout from the new node until a terminal state.
Backpropagation: Update all nodes in the path with the result of the playout.
Planning and Markov Decision Processes (MDPs) (Chapter 5)
Deterministic vs. Stochastic: Search problems assume deterministic outcomes (Action A always leads to State B). Planning accounts for randomness (stochasticity) where actions have probabilistic outcomes.
Markov Decision Process Components:
States (): A set of all possible situations.
Actions (): Possible moves available in a state.
Costs/Rewards (): The time, money, or penalty associated with an action.
Transition Probabilities (): The probability of ending up in state given state and action .
Policy (): A strategy that maps every state to a specific action. The goal is to find an optimal policy that minimizes the expected average cost.
The Value Iteration Algorithm
Goal: To find the lowest expected average cost to reach a goal state.
Step-by-Step:
Initialize Value (): Set the goal state to and all other states to an arbitrarily large number (e.g., or ).
Update Rule: For each state, find the outcome of every possible action and choose the minimum:
Repeat: Iterate through all states multiple times until the values converge (stop changing).
Examples of MDP and Planning
Commute to Work Scenario:
Options: Car (walking to car: ), Train (walking to station: ), or Bike ( total).
Chance Nodes:
Car: No traffic (20\text{%}, ), Medium (70\text{%}, ), Heavy (10\text{%}, ).
Train: Train there (90\text{%}, ), No train (10\text{%}, wait in room for ).
Result: Through Value Iteration, we find the expected time for the Car is , Train is , and Bike is a guaranteed . The Car is the optimal policy.
Dice Gamble Game:
Stay: Receive and roll a dice. If 1 or 2, game ends. If 3, 4, 5, or 6, repeat round.
Quit: Receive and end immediately.
Expected Value: "Stay" policy results in an average of (which can be modeled as a cost of ), making "Stay" the better long-term policy.