CS 188 Lecture 6


CS 188 Lecture 6

Anna
Welcome back to another deep dive into AI. Today we're tackling adversarial search — the algorithms that let an agent make decisions when there's an opponent actively working against it.

Michael
Right. And before we get into the algorithms, we should mention that the lecture kicked off with some logistics — homework 2 was due, homework 3 is coming out, and there's a mini contest for Project 1 where you can control multiple Pac-Man agents under time pressure. It's optional but worth extra credit.

Anna
Exactly. But the real meat is adversarial search. Let's start with the state of the art in game playing. Checkers was solved in 2007 — meaning we know the outcome if both players play optimally. Chess hasn't been solved, but Deep Blue beat Kasparov in '97 by searching about 200 million positions per second.

Michael
And Go was considered incredibly hard because of its branching factor — about 300 on average. But AlphaGo surprised everyone by beating the human champion in 2016 using Monte Carlo tree search and learned evaluation functions.

Anna
So the key idea is that these games can be formalized into a common interface: states, players, actions, a transition function, a terminal test, and utilities — scores assigned to outcomes. For zero-sum games, one player's gain is the other's loss, so we only need a single utility value.

Michael
That makes it easier. In a zero-sum game, the maximizing player wants the highest utility, and the minimizing player wants the lowest. We can model this with a game tree where each node is a state, and branches are moves.

Anna
Let's start with single-agent trees. Say Pac-Man can move west or east, and each move costs 1 point, eating a pellet gives 10. The terminal utilities are computed by the score. The best value from a state is just the max of its children — that's straightforward.

Michael
Now add a ghost. Pac-Man maximizes, ghost minimizes. So if Pac-Man has a choice between two states, the ghost will choose the move that gives the lower outcome. That's the minimax algorithm: at max nodes you take the maximum of children, at min nodes you take the minimum.

Anna
And we work bottom-up. For example, if a min node has children with values 3, 12, and 8, the min picks 3. If another min node has 2, 4, 6, it picks 2. Then the max above chooses between 3 and 2, so it picks the child leading to 3.

Michael
That's the optimal play assuming both players are perfect. But what if the opponent might make mistakes? In that case, you might take a riskier move with a higher upside. That's a different modeling approach — we'll see that in the next lecture on stochastic games.

Anna
Minimax is great, but its time complexity is O(b^m), where b is the branching factor and m is the depth. For chess, that's 35^100 — impossible. So we need pruning.

Michael
Enter alpha-beta pruning. The idea is that you can skip exploring subtrees that cannot influence the final decision. The key is keeping track of alpha — the best value the maximizer can guarantee so far — and beta — the best value the minimizer can guarantee so far.

Anna
Let's walk through an example. Suppose we're at a max node with a child min node. We find that min can achieve at most 2 from that child. If the max already has a guaranteed 3 from another branch, then any further exploration under that min node is irrelevant because max will never choose it. We prune.

Michael
The effectiveness depends on the order in which we explore children. If we look at promising moves first, we get more pruning. With perfect ordering, the time complexity drops to O(b^(m/2)) — the square root, which doubles the depth we can search with the same compute.

Anna
Let's test it on a small tree. Consider a max node with two min children. The first min has leaves 10 and 8 — the min picks 8. That gives max an alpha of 8. Now the second min's first leaf is 4. That means this min node's value is ≤4. Since 4 < 8, we can prune the rest of that subtree.

Michael
And that's exactly what happens in the examples from lecture. You get to skip entire branches. But even with alpha-beta, we often can't reach the terminal states — the game tree is just too deep.

Anna
So we use depth-limited search: we stop the search at a certain depth and apply an evaluation function to approximate the utility of that state. For chess, that might be a weighted sum of material, mobility, and so on.

Michael
The evaluation function is critical. If it's not informative enough, you get weird behavior — like Pac-Man thrashing back and forth because it only looks two steps ahead and can't distinguish between equally good-looking positions.

Anna
You can improve by adding features, like distance to the nearest pellet, or closeness to ghosts. But there's a trade-off: a more complex evaluation function takes more time to compute, leaving less time for search. It's a balancing act.

Michael
And there's a beautiful synergy between evaluation functions and alpha-beta. A good evaluation function can serve as a bound, letting you prune earlier. Also, you can use the evaluation to order your successor nodes — explore the most promising ones first, which increases pruning.

Anna
So to summarize: minimax gives us optimal play in deterministic zero-sum games, alpha-beta pruning makes it feasible by cutting away irrelevant subtrees, and depth-limited search with strong evaluation functions lets us handle real-world games like chess and Pac-Man.

Michael
And next time, we'll add uncertainty — stochastic games where dice rolls or random ghost movements force us to think about expected values. That's where expectimax comes in. But for now, we've got the foundation.

Ask anything
We've read this whole study set, so questions about it get the best answers.