1. Home
  2. Explore
  3. Computer Science
  4. CS 188 Lecture 6

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

CS 188 Lecture 6

Transcript

[NO AUDIO]

[SIDE CONVERSATION]

PROFESSOR: Hi, everyone. Welcome to the sixth lecture of CS 188. Couple of announcements for today-- your homework 2 was due yesterday. So this is an after-the-fact announcement, but it's good if you missed it that you know that next time not to miss it. Also, your homework going forward always has three components. There is an electronic part, a written part, and a self-assessment of the previous written homework, so just a reminder of that. For the written and for the self-assessment,

use the template we provide such that it matches exactly up with what we have and fill in the blanks as you solve the problem. There is a mini contest-- a little more about that in a second. Homework 3 games will go out soon, probably tonight, otherwise tomorrow. It will be due next Monday. We'll again have three components. And project 2 games will go out probably tomorrow and will be due next week Friday at 4:00 PM.

The contest that's part of project 1, this is optional but we think very exciting. So I want to highlight a little bit what's going on there. So this only counts for extra credit and for glory, not for regular points. What do you get to do in this contest? In project 1, the mazes were relatively small, and there was only one Pac-Man trying to eat the food. In the mini contest, you get to control multiple agents who together are supposed to clear out the board.

And in addition to controlling multiple agents on large boards, you also get to be time-constrained. So we all know that if you get infinite time, you can even run uniform cost search on these problems and ultimately return a solution. But that's not useful in practice. In mini contest 1, you get penalized for time used. The more time you use, the more you get penalized. If you can make fast decisions, you lose less points. And then if you eat dots, you win points.

So this is an example of a board there. If you submit-- so a couple things to note-- this will be closing on Sunday. So there's about a week left. You get 0.5 points of extra credit on project 1 per staff bot beaten. There is two staff bots coincidentally named staff bot 3 and staff bot 2. And there is 0.5 points for submitting any bot. So just go in there, get yourself a bot, and submit. You get 0.5 points already. And then we'll also rank students based on performance of their bots.

And there is a little bit of extra credit related to that. And there's a leaderboard. Here is the current leader board. Staff bot's not on top anymore. Jason [? Lu ?] here-- here? Congratulations, you're currently first. That's awesome. [APPLAUSE] [INAUDIBLE] here? [INAUDIBLE]? Anybody just want to claim it? Don't do that. [LAUGHS] White guy claiming [INAUDIBLE].. [LAUGHTER] You can choose the name of your team freely. It doesn't have to be your own name.

You can do it in teams of two, just like for the project itself. And when you submit, your agent will appear on the leaderboard. Right now, this is the first 20. But actually, there is six of those pages for about 120 total agents in competition now. Some agents have one student behind them. Some agents have two students working together behind them. So I encourage you to check it out. It's set up such that once you've completed project 1, getting a starter agent going should

take extremely little time. Then, of course, to do something more interesting requires some extra thought about what it takes to get two agents or multiple agents to work together and how to work under time constraints. Any questions about logistics? Yes. STUDENT: So you find the string for the how long it takes to find a path or how long it takes Pac-Man to move on the path? PROFESSOR: OK. So you get penalized for amount of time you use before you decide what your next action is.

So the interface is the environment waits for the next action to be given. And the agent is computing, computing, computing, finally gives the next action. Then the environment says, how much time did you take? Based on that, points get subtracted and then executes the action. And thanks to the action, you might get new points. And this process repeats. If you have a shorter path, you might collect more points than if you used the longer path. But if you take a very long time thinking to get a short path, you might still do worse than somebody who has an agent who chooses a longer path but can find it quickly.

STUDENT: [INAUDIBLE] [LAUGHTER] PROFESSOR: Any other questions about logistics? OK, let's start with the technical content of this lecture, adversarial search. This is about game playing in many ways. So let's take a look at game playing state of the art. Checkers-- one of the first games for which there were good AI players. In the '50s, there was a computer player-- decent. In '94, there was the first computer champion. This computer champion took over from Marion Tinsley, who had for 40 years straight been the number one in the world in playing checkers.

So this was somebody who was just superior to everybody else in the world for 40 years. But then a computer came in and took it from him in '94. Then in 2007, checkers was "solved." What does it mean to be "solved" versus beating the best humans? Beating the best humans is something where it's just the level of play that you're at. Being "solved" will become more clear later in lecture, but it means that you know that you can force a win or force a draw if both sides play optimally.

And we'll find out more about what that means. But for now, let's already put it on the chart-- checkers solved. Chess-- '97, Deep Blue defeated Kasparov, the human champion, in a six-game match. Deep Blue was able to examine 200 positions per second at that time, with computers from 20 years ago. Used a very sophisticated evaluation function, which we'll see more about today, and some undisclosed methods that IBM did not tell anybody. And some searches were 40-ply deep,

which we'll also see more about today, but that's searching very deep in your game tree of possible scenarios of how things could play out. Current programs are even better, but a little less historic because the best human player has been beaten. Chess is not solved in the sense that checkers is solved in that we don't know for sure who is guaranteed to win or whether it's guaranteed to be a draw if both players play optimally. A lot of people suspect it's a draw, but it's not been proven.

Go-- this is what we would say just a few years ago. Human champions are now starting to be challenged by machines. And that's a recent thing as of the 2010s. Before the 2010s, humans wouldn't play against computer Go players, because it was just too boring. It would be an insult to be asked to spend your time that way. Why was it so hard to build good Go players? So on Go, the branching factor is 300 roughly on average throughout the game. And that means there's a lot of possible future scenarios. So classic programs used knowledge bases. But then a lot of advances started to come in through Monte Carlo. Expansion methods, which essentially means something along the lines of, from the current situation, if I let both players play randomly a few times, who wins more often? And you use that to decide whether that's a good position for white or for black to be in. But this changed.

In 2016, AlphaGo defeated the human champion using still Monte Carlo tree search but also learned evaluation functions of a quality nobody had really anticipated were achievable anytime soon. And again, we'll see more about evaluation functions in this lecture. But that's where the big surprise was. A lot of people thought Go was maybe still 10, 20, 30 years away. But the quality of evaluation functions completely changed that. And then Pac-Man-- that's what we all want to know here.

Still have to figure it out. Maybe we'll figure it out by the end of the semester. Open problem for now. OK, so let's take a look at Pac-Man in action. So here is-- where is the game? There it is. Here is a game situation. Now there are ghosts. Let's watch a mastermind Pac-Man in action.

In the terminal window, you see a bunch of competition happening, which we'll understand more about later. For now, the thing to pay attention to is that indeed it is somehow avoiding the ghosts, eating food pellets, and periodically eating one of the power pellets. And when it eats power pellets, it can eat ghosts and get extra score for eating the ghosts at that time.

OK. That's how I mastermind Pac-Man. And that's what we we're going to be after in this lecture, to try to understand what it takes to build something like this but while not having to write lines of code of the type "if a ghost is nearby on that side, move in the other direction. If there's a power pellet in that direction, move in that direction." We want it to reason about the consequences of its actions and the ghosts' actions to infer from that what is the right thing to do. OK, so let's first do a quick step back and talk about types of games. There are many different types of games. You've already probably in your free time played a lot of games-- computer games, board games, and so forth. What are some axes along which we can categorize them? Well, one axis is whether they're deterministic or stochastic. So an example of deterministic would be checkers, or chess, or Go. Example of stochastic would be backgammon, where there is a roll of dice that determines which

moves are available to you. Then the number of players-- one, two, or more players. Solitaire would be a canonical game to play alone. Two players-- checkers, chess, Go, backgammon. More players-- poker. A lot of board games have more than two players. Then another axis along which you could categorize games is whether they are zero-sum or not. We'll see a little more on that very soon. But the general notion here is, are you all playing against each other or is there some notion that you're not

all playing against each other? And then there is a question of perfect information or not. Do you know everything about the current state of the game when you decide on your action? Or do you not know everything? An example of knowing everything would be chess, checkers, Go. You see the board, and that's all there is to it. An example of not knowing everything would be poker. You don't know the cards of the other players. So that's an imperfect information game where you have to think about possible scenarios-- what cards might they be holding; as a function of what cards they're holding, what might I want to do; and so forth. What we want in this setting-- any one of those settings-- is somehow an approach that allows us to calculate a strategy, a policy that tells us what to do in a current situation and then again in future situations. So this is going to be a little different, the result of this, than what we get in regular planning.

In regular planning, we just generate a sequence of actions that we can just execute. But here, because there's an opponent that we don't control very often, we need to find a strategy which prescribes what to do as a function of the situation we are currently in or going to be in. Well, folks, in deterministic games for now, we'll see stochastic games next lecture. Now, the same thing we've done with search and with CSPs is that we want to find a unified interface for all these real-world problems such that once we have the unified interface, we can then have one implementation of an algorithm that applies to any of the real-world problems that's cast into this interface. So here's one way to formalize the interface for games. There is a set of states and a start state as 0. There is a set of players which often take turns. Definitely in what we consider, they take turns. Then there is a set of actions. This can depend on which player you are,

what actions are available to you. There is a transition function, which is a lot like a successor function in regular search-- state and action to next state. There is a terminal test. Is the game over or not in the current situation? And then there are terminal utilities. This is maybe the newest type of thing. But what we're going to do is every outcome of a game will be scored. Simple games might have just three types of outcomes-- win, draw, or lose. But more complicated games might have a wider range of outcomes. For example, in poker, the amount of money you make might be the utility assigned to an outcome. And then it could be a range of values rather than just win, lose, or draw. Solution to something put into this interface is a policy. And a policy is something that tells you for every possible situation you could be in what action you should be taking.

What's this zero-sum thing that we're going to be focusing on in this lecture? In zero-sum games, agents have opposite utilities. They have to fight over one resource or set of resources that's available. And if one agent gets it, the other one doesn't get it. And so the more the other one gets, the less you get. This allows us to think of utilities as not separate utilities for each agent for each situation. We just need one number. We have the utility for agent 1. And then agent 2 we know has the opposite utility, the negative of the utility of agent 1. So this models situations where it's pure competition. It's one agent against the other. There are other types of games-- and we'll see some of them in the future-- where agents have independent utilities. And sometimes this opens up more opportunities. This opens up opportunities for win-win outcomes where you say, I might not care so much about the orange ones. I don't care about the green ones.

But the other way around, you do care. And so here, blue agent collects all the green ones. Red agent collects all the orange ones. And in the process, they're helping each other, making it easier to collect the ones they're looking for. Many real-world scenarios, in some sense, are of this type. But often, the essence can still be simplified in many situations to zero-sum games. And those are the ones we're studying today. OK, so to solve zero-sum games, we'll use a set of approaches called adversarial search. It's something where you, as an agent, have to think about as a function of what you do what will the other agent do who's working against you, what opportunities will you then see after that, what will they see after that, and keep thinking about what if, if, if, if, and so forth through, ideally, the end of the game. So let's first look at something we're already familiar with, which is a single-agent game tree.

A lot like search, but we'll formalize it as a game tree. And then from there, we'll generalize to multiple agents-- two agents for today. OK, here is Pac-Man trying to collect food-- simple maze. Two actions available-- west or east. Then after that, again two actions available and so forth. All the way on the right, it's done. The other ones, it can still keep going. In these game scenarios, with each terminal state, we associate a utility. So for example, this has a utility of 8-- which is a standard scoring we have in our Pac-Man games-- minus 1 for every time step spent, every action taken, plus 10 for every pellet eaten. So two steps, one pellet eaten, that's 10 minus 2, 8. And maybe the numbers for the other ones end up being something like 2, 0, 2, 6, 4, 6, and so forth. If you're a single-agent, you control where you go in this tree. So things are actually relatively easy. You would say, OK, let me look at the tree. What do I see here? Well, 8 is the highest.

So I should do this and then this. And that solves the game. But let's formalize this a little bit more. So each state in the game has a value associated with it, which is the best achievable outcome from that state. So for example, for this data over here, that's very easy. It's a terminal state. The best achievable outcome? Well, there's only one outcome from that state. It's that you terminate the game, and you get 8. So the value of this state is 8. How about a state like this one?

What would be the value of that state? Well, it's the best you can achieve starting from that state. And it looks like from looking at this tree that you can end up with a 4, with a 6, or with an 8. 8 is the best achievable. And so the value here would also be 8. How about the value of this state over here? Well, it looks like there's opportunities for a 2, a 0, a 2, a 6. 6 is the highest. So the value would be 6. How about this one at the top here?

Well, you can either go to the left or to the right. Either you end up with a value of 6 or with a value of 8. 8 is better. You control that. So 8 would be the value of your state over here. And so the way we did this is that for non-terminal states, we looked at the children and took the max of the values of the children, because we control where we go and that's the value of that non-terminal state.

Let's now generalize this to adversarial games. So here we have Pac-Man and ghosts. They're working against each other. Pac-Man tries to maximize score. The ghost wants to minimize score by eating Pac-Man. So let's see what happens. First, Pac-Man gets to take an action. So we're assuming alternating moves here. Could be going left or right. Then after that, the ghost gets to take an action. Then after that, things keep repeating. And then for each sequence of alternating actions,

at some point the game might end. And then with the end of that game, some utility is associated. If Pac-Man survives and has eaten all the food pellets, it would probably be a high score. If Pac-Man doesn't survive, it'd be a very low score. So let's zone in on a smaller version of this to annotate this with some concepts. Let's assume that the game is over after each player has made a move. This is not how the real game works, but just to get it on a slide. This is a very short game--

one move for Pac-Man, one move for the ghost. And here are the scores we have associated with that. There is a minus 8, a minus 5, a minus 10, a plus 8. You might say, well, I'd love the plus 8. That sounds pretty good to me. And you might say, well, OK, I should try to get here. But that's not how it works in this kind of game, because actually the ghost controls this node. And if you were to end up in this node, ghost would prefer to have the lowest possible outcome.

So ghost would say, I'm going to do this, and it's going to end up with minus 10, such the value of this node over here is minus 10. The plus 8 is just there. It might be tempting you. You might want to try to get it. But you're just not going to get it. The ghost is not going to give it to you. So this value here is minus 10. Similarly, on the other side there's a minus 8, minus 5. Ghost working against you will decide it's going to be minus 8. So the value over here is minus 8. Going one level up-- again, from bottom to top-- now, what's the value of this node over here? Well, it's the maximum of the values of the leaves-- not the leaves, but nodes below it. What's below it? An option to get minus 8 and an option to get minus 10. Minus 8 is better. So the value here is minus 8. Pac-Man will choose this move, after which the ghost will choose this move. And that's how the game will play out if both players are playing optimally.

Formalizing this a little bit, terminal states, we have known values. v of s is whatever we annotated it with when this slide was not written on yet. Then states under opponent's control, we have a minimization happening of the utility. And states under our own control, for the maximizer agent, we have a maximization happening. And again, keep in mind there is a plus 8 here, but we're not going to get that. What we're actually going to get is this outcome over here. OK, let's look at a very simple board game-- Tic-Tac-Toe. Has anyone not played Tic-Tac-Toe before? OK, so everybody knows Tic-Tac-Toe. You need to get three in a row. It starts with an empty board. You can choose any of the nine squares to put your mark in. Then the other player goes. And this process repeats until either one player has three in a row or the board is full and then the game is over with a draw. What is the value of this node over here? Well, you have to think about this.

You have to think about, well, I mean, there is a plus 1 at the bottom somewhere. There's many plus 1's for various outcomes. There's various 0's and various negative 1's. But what can you get to when you're playing against an opponent who's really playing cleverly against you? Well, one thing we definitely know is that either the value here is going to be negative 1, or 0, or plus 1. It's not going to be anything else, because the values are obtained by just taking maxes and mins of values that are leafing out to leaf nodes. And by taking maxes and mins of negative 1, 0, and plus 1, you never end up with anything else than those three. But which one it is? Well, for that, you have to work through the game tree. You figure out the entire tree. You work through the process that we just did on the previous slide here, taking maxes and mins at each respective node till you're all the way out the top. And it turns out that if you work through this carefully,

you find out that the value is 0, which means that if you're two smart people who are going to play this game, you know ahead of time it's going to be a draw. And that's actually what it means when I referred to at the very beginning of this lecture for a game to be "solved." The game of Tic-Tac-Toe is solved because we know that if both players play optimally, the value of the top node is 0. Same thing is true for checkers. People have worked through it with more efficient algorithms

than just drawing out the whole game tree but have worked through it in efficient ways to conclude that for checkers it's also 0, I believe. But I'm not 100% sure whether it's 0 or 1. So that's what it means to be "solved." OK. So now let's design an algorithm that is more computer executable than us looking at trees. Yes. STUDENT: Back to the last slide for a second. PROFESSOR: OK. STUDENT: A game with the possibility for an arbitrarily long cycle of states, how could you end up solving it?

PROFESSOR: OK, so the question is, what if there is a way to keep playing? So the tree would be infinite in that scenario, right? For example, what if in Tic-Tac-Toe maybe you could erase something and then you could keep going? So a lot of games have setups where you cannot repeat the same move over and over to avoid getting into loops. But if there is a possibility to get into a loop that indeed the tree could keep going, and then you'd somehow have to-- well, you then have to decide what that even means. If both players decide to keep playing forever, is that a draw or-- I mean, it's not very clear what the definition is of what that means if both players just keep playing forever. But you somehow have to come up with a definition of what that means. Let's say you call it a draw. That's what some games might do, are just forbid it to go in the same cycle again. Then all of a sudden, you have something again.

Because now we've gone through a cycle a certain number of times, that's the limit. Now it's a draw. They could begin so the trees are infinite in other ways without having repeats. Maybe you have some kind of infinite board you can play on in principle, and you can keep expanding in many, many directions. Then you might need a little bit extra machinery compared to what we're seeing today in lecture. So we're not going to specifically look at that.

OK, so let's formalize this. We've been looking at deterministic zero-sum games. Examples are Tic-Tac-Toe, chess, checkers. One player maximizes the utility at the leaf nodes. The other one minimizes it. In minimax search, we have a state space search tree. Players alternate turns. And to compute minimax values at each node, we can work from the bottom to the top. For example, for this here, we have minimizer says this is 2. Minimizer says this is 5. And then the maximizer knows that the value at the top is 5. And the game would be played out this way. That's the minimax solution to the game, with both players playing minimax strategy.

This is illustrated on the slides. How do we formalize this? Well, at a max node, what we're doing is we're initializing our estimate of the value of that node as negative infinity. And then we start inspecting all the children, see what the value are of the successor nodes, and if they're higher than what we have so far, we increase and ultimately return the maximum value we've seen among all successors. Min, that's the exact counterpart. Start out plus infinity when you've seen nothing.

And then whenever you have examined a new successor, you check if it's better for the minimizer than what you've seen before. And if so, you update the value. And you keep looping till you have gone through everything. Of course, if you just use this, this is a recursion where you go from min to max from max to min and keep going. There is no base case here. So this actually wouldn't really work. So in your code, you'll have to install a base case of some type so you'd have dispatch function that computes value of a state. First checks, am I hitting a base case? If I'm hitting a base case that is a terminal state, return the value of that terminal state. If not, then check what kind of node I'm in. Am I in a maximizer node? Then call max. If I am in a minimizer node, call the min value function and execute that. And to the earlier question, if the game keeps going forever, then some of these occasions you will never hit the terminal state, and you'll

have to somehow decide how your algorithm is going to stop early. It might say, after I am a million moves deep in the game, I'm just calling it done on this branch and have some kind of resolution calling it nevertheless a terminal state because it's been going for so long. STUDENT: Question. PROFESSOR: Question-- yes. STUDENT: So if there's an algorithm, are we [INAUDIBLE] to move step-by-step? For example, the one Pac-Man question where we first moved Pac-Man then the ghost movement, is it a different type on all [INAUDIBLE]?? PROFESSOR: Correct. In everything we're looking at here, it's going to be turn-based games, where the moves are alternating between players. There are other types of games where players takes decisions simultaneously.

We're not going to look at those in the current two lectures. OK, now we have an algorithm. This is essentially the counterpart of our tree search or graph search from when we did search in the first-- well, in lecture 2 and 3. And we can now run this. This is a lot like depth-first search. It's just traversing the entire tree. It's not skipping anything. It's not prioritizing anything over anything else. Just going successor, by successor, by successor, and going deeper, deeper, deeper before it's coming back up. So if you had a game tree and the program

was running through it, it would start with the start state. It wouldn't draw out the entire tree like we've been doing and then from the bottom push things up. It would actually start at the top. It would say, OK, what are the successors? Three successors. Let me look at the first one. Let me dispatch that one. It's a min node. OK, let me call min value on that. What does it mean to call min value on this one? It means to call its successors and loop through them. Oh, looks like the first successor is a terminal state, value of 3. That can be passed back up. And now we have v equal 3 here as our estimate. Next one is 12. Since we're minimizing, v stays 3. Next one is 8. v stays 3. At this point, we're done. We've seen all successors. And we can pass this back up. And our estimate at the top here is now 3. But it might still change, because we've only seen one of the successor nodes, not all of them yet. Now the depth-first search goes down next branch.

Oh, it's a minimizer node again. Look at its successors-- terminal state. This now says, oh, the value here is 2. But it might still change as we see other successors. 4 is not going to change that. 6 is not going to change that. So it's 2. We pass this back up. The maximizer says, I had 3 so far. This new option is 2. That's worse. So I'm sticking with 3. Going to the next successor, again minimizer. Here, the value would be 14 right now. Then the minimizer looks at the next successor.

5-- so updates to 5. Then sees 2. Updates to 2. 2 over here. That gets passed back up. Maximizer says, well, 2 is worse than 3. 3 is the best I've seen. I've seen all my successors. 3 it is. And I will take the corresponding action, which is going this way, after which the minimizer would take the corresponding action, which is going this way. And the game would end up over here. So that's the procedural execution of how the minimax search would work. Any questions about this?

OK. Then let's take a look at some properties. Let's say we have this tree over here. And the question we're asking ourselves here is along the lines of we're faced with a real-world situation in some sense, and we've formalized it into a game tree. And what will minimax give us? Well, look at this. What's the value for the top player, max? Top node? STUDENT: 10. PROFESSOR: 10? Saying 10. Why 10? STUDENT: Because if you go in the other direction, the other player is going to do 9. PROFESSOR: So the answer is well,

it looks very tempting here to go for the 100 maybe. But there is a 9 there, and the minimizer would force the 9. So the value here would be 9. On the other side, it's 10. So the value of the game is 10. OK. So we have a value of the game that's 10. So that's when you play against a perfect player, like a mastermind player. You would always assume that they get it really, really, really right. But what if you play against a player like this one? Maybe you are willing to take your chances.

Maybe you don't think playing Tic-Tac-Toe is a waste of your time. You can actually win a few games. Even though the value of the game in principle for Tic-Tac-Toe is 0 against this player, it might be plus 1 for you, because they might make mistakes. And so when you play against a player that might make mistakes, maybe you want to go this way, because maybe they would go there. And if they don't, 9 is not that much worse than 10. But if they do make a mistake, a hundred is so much better than 10. And so, if just periodically they were to make a mistake, it's worth it going that way. So now we're doing some probabilistic calculation, really. It's like, what's the chances that they might make a mistake? And based on that, maybe we go that way, if the chances are high enough and the payoff is high enough for when they make a mistake. That's a different kind of way of looking at modeling the world. It's modeling the opponent not as a optimal mastermind

playing against you but as somebody who might do some things stochastically. We're not going to look at the details of how that works in this lecture. That's for next lecture. But let's look at some of the consequences of the differences of how you look at the world will affect what you do. So here we'll look at-- well, some apologies for the situation we're putting Pac-Man into here. Pretty grim situation-- no dots nearby, just ghosts. What's our scoring system? Plus 10 for eating a dot. Negative 1 for each action you take.

So what do you think Pac-Man should do in this scenario? STUDENT: [INAUDIBLE] PROFESSOR: Some people are pointing to the right. What does that mean? There is a ghost right there. Why would you go to the right, dive-bomb the ghost? Well, it turns out to give you a higher score. If you can manage to be eaten by the ghost in one step, you only lose 1 point due to time. If you get eaten after more steps, you lose more points. So you want to get eaten as quickly as possible in this case. [LAUGHTER]

That's the minimax solution. Let's see what happens. So Pac-Man playing minimax. Boom-- one step, and game is over. But now let's consider this again. And let's think back to the not-so-smart players and look at the ghosts. Maybe they're not that smart. You say, they look a little bleary-eyed. They're not that smart, probably. Maybe I should take my chances. Well, what does it mean to take your chances? The red one is always going to come towards you. It only has one way to go.

But the blue one could go up or down. So maybe half the time it will come towards, half the time it'll go away from you. If it goes away from you, then you're lucky, because the ghosts keep running the direction they're going whenever there's no intersection. And it'll keep going away from you. You'll be able to eat all the dots and win the game. Of course, you're taking the risk that you live longer. If it does come towards you, then you could have just dive-bombed the red ghost. So let's see what happens. Of course, if the ghost is really taking random actions to choose whether to go up or down, we don't know right now what's going to happen. But let's see what happens. Pac-Man took their chances. And indeed, blue ghost moved away. And got lucky and ate everything just in time. Now, if we play the game again, it might be that it doesn't work out the same way. I'm going to try this. OK, let's see what happens this time. Got lucky again.

But in principle, after it runs a few times, half the time it would be lucky, half the time unlucky. But it might be better than always dive-bombing into the red ghost. So the second scenario here is when you're saying, well, I'm playing one of these kind of players. So it's worth taking my chances. And we'll see how to compute optimal strategies for that in next lecture. How much compute do we need to do this minimax computation? Well, we already covered depth-first search and how much compute it needs in the second lecture. What was it? Well, it's order branching factor to the power depth of the game, so b to the m, where m is depth of the game. Space-- b times m. So space complexity is pretty good, but time complexity is pretty bad. For chess, branching factor about 35. Of course, not the same in every moment of the game, but some average-- 35.

Maybe a hundred moves total. Then 35 to the 100, which is completely infeasible to search the entire tree. So that's not how Deep Blue beat Kasparov. It's not by searching the entire tree. Other machinery was needed to get there. And we'll see some of that machinery now. OK, since we only have finite compute, we cannot explore the entire game tree. So what are we going to do? A first method we'll look at is game tree pruning. The question here is, do we really need to look at the entire tree to find a solution? If we look back at previous weeks in solving CSPs, we had backtracking whenever filtering said that there will be no solution down here. It's not worth doing more work because we've already determined that the domain of one of the variables is empty.

So it's waste of time to go look further here. We don't have domains of variables here that can go empty. But maybe there's something similar we can do where at some point we can conclude this part of the search tree is just not useful to explore anymore to find a solution that we need to find. So let's do this by example first. Here's our minimax simple example again. And let's say we run depth-first search. As a reminder, what happens-- we keep going left to right through the tree. We're straight through, collect values. So at this point, this is a 3, which has been passed up. This guy thinks it might be 3, but it might still be something else. Here we now have 2. And now stays 2. Stays 2. The 2 gets passed up. This one stays 3, and so forth.

Do we really need to look at all these numbers to solve this problem? Another way to phrase this, is there is something-- like, are there any nodes at the bottom here, leaf nodes, where I could have changed their value to anything else and the outcome would have been the same, the value would have still been 3? Because if that's the case, if I can change the value of leaf node to anything else and the value was still 3 and I could know that while I'm doing

the search that that leaf node, no matter what the value, the top-- the evaluation will remain the same, then we don't need to go look at that leaf node, and we can skip it. So that's what we're after now. OK, let's see how we can achieve this. We start out just the same way. Right now we have no information about the game. So it's going to be very hard to make any claims like, oh, I can skip this because such and such. We don't know anything yet. After we've gone through the left bottom-most node and we know this value is 3, we can propagate this back up. We have maybe 3 here. Now we have a little bit of knowledge about the game. We know that one way of ending the game is by going to this before-last node where the minimizer will choose 3. Could we have skipped any of these or these nodes? No, because if it had been lower than 3, the minimizer would have chosen it. So there's nothing we could have skipped here so far.

Now go to the next one. Is there anything we can do here? Can we just say, let's skip it? No, we can't, because the minimizer is sitting there. And what if the minimizer's options are only a hundred and above? Then definitely we need to know about that. But if they're below 3, we also need to know about that. Essentially, what we'll need to know, if there are going to be options here below or above 3, because that's what we have right now at the top. So let's take a look. The first one is 2. What does that tell us? This tells us that the value of this minimizer node is less than or equal to 2. We don't know if it's 2 or less. We don't know if it's 2 or maybe another other value, but we know it's less than 2. Once we know it's less than 2, we know the maximizer would never prefer this. It would always prefer going that way. So it does not matter what the values are here. Because no matter what they are, the maximizer would never let the game get to that node,

because it would be worse than going to a node where you get a 3 guaranteed. The guaranteed 3 it already has up here is better than anything that could happen down there, no matter what lives over here. So we can just skip over these. Don't need to look at them. And note this would be true even if these were not terminal nodes. Imagine we're a whole big tree living underneath here-- a whole big tree living underneath here. We don't have to explore any of that tree because we know the maximizer would never let the game go that way because minimizer will be able to make it less than or equal to 2, and maximizer could force a 3. And so we could prune massive amounts of computation if there are big subtrees over there. We continue. OK, we have a minimizer node again. At this point, we know nothing yet about this branch. We know the maximizer can force a 3. We don't know if this might be a better or worse option than the 3 it can already force.

Now we see a value of 14. Oh wow. This looks promising. We know the value here is less than or equal to 14. But if it could be 14, that would be great. Can we stop here and just ignore these? No, we can't, because we're not guaranteed to get 14. It could be negative infinity for all we know, and then we don't want to go there. So we need to keep looking. Now it's 5. So we know this one is less than or equal to 5. 5 would be great. It's better than 3. But there are still other parts that we haven't seen. And as long as we haven't seen that, we don't know what the minimizer will force us to get there. So we need to keep looking. What is it? A 2? Now we know that it's actually 2. That's worse. And maximizer will conclude to go this way, and the game will end up over here. What computation did we save? All of the computation that would have happened over here. In a small tree like this, it might not be a lot.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent