 So we've talked about alpha beta pruning. We walked through a few examples, but you know You were computer scientists and this is probably because you need a grade that you're like give me I how do I build this? I need to build this in my language Well, I'm not gonna just build it for you, but I will at least point you in the direction of Swat of what is a swathmore college? I really like this link in the description below But I really like their pseudo code because it helped even me sort of kind of really wrap my brain about this so What we're looking at here is specifically when we're dealing with alpha beta minimaxing, right? We're dealing with a function or method, you know again your language of choice But specifically looking at all of these different actions You know these different sort of categories of what's going on along the way Might help sort of give you some kind of guidance on what we're dealing with here So at least to start one of the things that they're sort of touching on is this notion of having some kind of depth limit Again, if you remember While I was working off of a simple tic-tac-toe board if you're dealing with a situation You know a game or a search that is much deeper connect for connect chess Checkers you're gonna have way too many potential moves And so it is going to be Beneficial to work off of some kind of depth limit my recommendation, you know, I would set Initial depth level To something like maybe Five and build from there if you end up losing, you know increase it if you you know crash because of Stack overflows decrease it But either way the next little portion here is specifically a static eval method that They sort of leave open-ended and I also in my assignment. I'm leaving it open-ended. The notion is How good Is this node Because remember right now what we're saying is We're sort of treating this like it's a terminal state Even though it's not and so we're saying okay. Well what you know Can you give me a heuristic of how well we're doing and so this is where you know Oh, you know, we talked about heuristics with you know a star search the same thing is going on here You need to give me some kind of heuristic that says whether or not this is a good state For example, one of the assignments that I've presented to my students is connect for Well connect for Just to draw that out a little bit. I think that's right Connect for you could think that And I won't change colors. I'll just use X's and O's for for this You know, if I dropped a position one more column If I dropped a position Here and then you know the other player drop their position. I drop one here. They drop one here I drop one here They drop one here. So at least in this sake, right? Is this a good move like is this column good or is this calm better? And you know one heuristic that you could work off of is how many of your nodes are connected together now in this sense Both of those are still gonna be good possible rounds, but you could expand on that, you know How many connect threes do I have how many connect twos do I have and then try and build out some kind of waiting system? So connect threes are better if I have connect threes or vice versa either way This is up to you to build on your own end and explore and play with But then we also have our terminal states. So our terminal states terminal states Here what we're looking at is again, we're going to see if any potential child This is sort of what are all my possible children and then Really this goes down to here If I have no more children. Oh, well, what are we looking at? Well, the first thing we're dealing with here is what if we're at the very beginning and so at this state initial eyes initial eyes best Move Now not really initial eyes more like Reset initial move one of the things I would recommend is you could create some type of class variable for best Move right and as you do your search that changes along the way that might work out that way But again, you notice it's doing that same kind of thing of a static eval Well, that heuristic is also coming into play even though we're at a leaf node and you can actually evaluate the actual value Again, this is just your method of oh well since we're at a leaf Is this a good leaf? Is this a bad leaf? Okay, so then we're dealing with this is where that resetting of our Best move also happens. So again if I'm at the Root node. So again, if I'm looking at that connect for game, right? What I'm essentially saying is Is this node? Equal to root is it this blank slate again just to help out my students dealing with connect for Again, if I have a blank board and I know Just not right in connect for I think I have too many columns this time Right is My node the current node that I'm evaluating equal to a blank Board now specifically I'm actually going to erase this notion of it being blank Because what happens when I'm doing the search at this state? All right. Well again, it's is it equal to what the board currently is the current board is Actually a better notion of what we're looking at here because again, we're starting off at the very beginning So we're just going to go ahead and say What is the first move? Now specifically this is where Swarthmore and my assignment and your assignment may differ Because they're using this word operator. Well, they're they're doing some weird I think it was a Hawaiian checkers. And so operators not really the best sort of notion for this best action of The first child the best move if I was dealing with connect for again that would be our column If I was dealing with chess, it would be again. What piece of my moving if it's checkers It's what piece am I moving etc either way again? If there's no other options, then we'll just go ahead and return null none Whatever but the big thing here is again. We're setting up best move and because of that We now have sort of our notion of oh, well, this is going to at least be my best move If I just took the leftmost path every single time, okay Then now we're starting to get into minning and maxing now You need to track whose turn it is and there are a number of different ways you could do that You may have maybe some class variable of turn Right and that controls if it's max's turn or men is turn and one of the things that you'd need to do is sort of when you Drop down you you maybe flip Turn is now equal to the negation of turn again That's mostly if we're thinking about this from just like a back-and-forth to player game But that's sort of again tracking whose turn it is Either way you can see that what we're doing here is again if we are in a max move So we are in max move Then we have to get all of our potential children. What are all the possible moves that I could make in my board right now? so what are All the possible moves right Now And specifically again the notion what we're looking at is what if I'm planning this is sort of my actual state So actual Board then what happens if I've been planning occasionally? I've made a few moves. I'm here then here. This is my perceived State So we're looking at when we're thinking about children is when we think about right now we're looking at this from Perception if I'm at this perceived state. What are all my possible moves? But then you can see we do some alpha beta mini maxing now one thing I have made as a suggestion sort of when we deal with our depth limit is it may be Helpful to actually just have depth be right here You know just expand on their pseudo code and track depth along the way Then as you come over to make a call instead of this being Let me actually use a I Will Whiten that out instead of this being where are you? There you are Instead of that being the end of my my method call right What if I came in and said oh well now depth is Is going plus one and then you can see oh well I'd be tracking depth as I go down my moves either way again when we hit recursive or we hit those terminal states We're doing returns of static evals. We're returning some kind of int or Double or floating point numbers so Again, that's the only thing that we are returning in the search not in the best move. That's something else So again as we're going through this we get some kind of value and If that value turns out to be better than alpha because again alpha is tracking our max We want to maximize alpha when we're in a max node then we update alpha and notice again What we're looking at here is this notion of what the best move happens to be once again operator is action What is the action that you need to take because we probably want to record you know record that and Finally, you notice one of the things we're doing is the pruning method So if we see that we have run into a situation where alpha turns out to be Larger than beta stop right that's something and we don't need to search anymore We're already done and then we do the same thing For men's turn. So same kind of thing again if you're tracking turn If turn, I don't know equals negative one then Congratulations, you now know you're in a min turn. You're still doing the same perception so moves at Perceived State and you're still doing alpha beta mini maxing you're still doing the you know depth Plus one here so all that's still happening notice again We're still tracking rather than if alpha is a result is greater than alpha We're looking if it's smaller than beta if that is the case we can change it In same thing this may still also be the best move that we can get you know Again, this is more in that sense of we do have to evaluate that because it may be the best We can get out of our situation, but then we're still in that same alpha Greater than or equal to beta approach here and then once again as you can see We would be returning beta in our sort of traversal of our tree So you'd go through and back and forth of these different Situations and so again the big things that I see from sort of students is Where am I tracking these different things? again, I Recommend that best move If you have a class make it a class Variable an update as you need Then same kind of thing when we're dealing with depth use depth as Another parameter Now again depending on your instructor and how your course is designed out you may not be allowed to but again if that's the case What do you know make it a class variable as well, and so you again keep working through this The bigger things I see a lot of times is this notion of perceived states And so one of the things you will need to do is you will need to sort of create a copy of Whatever your current state is so to make a perceived state to Make a Perceived state make a copy of your Current state Again because of that think current state also with the perception because again The actual board may just look like this again just the blank tic-tac-toe board It may work off of that, but if I create a duplication of that I can work off of that I could drop a piece I could you know place a piece again just how you're thinking about your moves and Then that would allow me to make Again because I have a cloned copy of the current state. I have a perceived I can manipulate the perceived and I can do Static e-vowels on the perceived State so hopefully this again works through this the link for the Swarthmore college pseudo code will be in the description I don't control Swarthmore. So hopefully it stays But again, this is my sort of if you want to start tackling alphabeta mini-backing Try to work through these steps and this might help again Build things out for you and plan things out and you may feel froggy and do things like negamax or something else along the way But with that Whatever your assignment is, you know do a do the YouTube thing of leave a comment in the In the comments down below. Tell me what you had to do In your class to do alphabeta pruning that way I can duplicate it and copy it and make it for my students