 Hi guys, it's MJ, the student act tree and in this video I want to show you how do I figure out with my little poker game that I actually have a pair. So I mean what I've made is a little poker game where you click play and generate some random cards. You can swap the cards out and ooh, almost got a flash there. And what we want to check out is how do we make sure that, how do I know if I got the pair. You know what is the logic behind that. And funny enough this actually took, this was a little bit difficult but I'm going to show you what I did. So first thing I did is I have this thing where we check to see what the cards are. I first check to see if we have a straight flush, a flush or a straight before checking these up because you can't have a flush and you know two of a kind because the cards can't duplicate. I have made videos on that so go check those out if you want to see how I made the straight flush and how I generated the random cards. But in this video I want to talk you through how I can figure out the pairs. And what I've done is I said if I get one pair, it's a one pair. If I get, if pair equals two, it's a two pair. If I get pair equals three, it's three of a kind. If pair equals four, it's full house. And if I get pair six, it's four of a kind. So what do we mean by this pair value? So what I did was I took the bubble sort method, okay, that was like my little inspiration that sorts cards and I used that to check to see if the cards are the same. So now look, I can probably put this into a four, you know, I could have a for loop within a for loop like you have it with the bubble sort, but it's much easier to explain it as four individual for loops. So think of it. Think of having five cards in front of you. What I do is I call this method and it says, okay, we're going to take the first card and we're going to run it through a for loop where we're going to check it against the four remaining cards. If the array, if the two cards match, our pair variable will increase by one. So if there are just two cards in the deck that match, then our pair value is going to increase by one. Let's go through it slowly. So I've got five cards. The first card goes and it checks, hold on, let me actually bring this here. So the first card over here will go and look at these other four. So five's not the same as ace, not the same as ace, not the same as two, not the same as four. So pair would actually stay zero here. But then we come to the second for loop where we now look at the second card and we're just going to be checking it to these three cards. No need for me to check it with the five because that's already been done in the previous one. Here the ace does match with the ace. So we are going to say pair plus one, but ace is not going to be equal to two and it's not going to be equal to four. So then we move on. Then this value here checks with this, doesn't, doesn't, okay, move on, doesn't, doesn't. At the end of the day, pair is equal to one and what we have is a one pair. Now look, unfortunately in poker it is very rare to get, you know, like a two pair or, you know, three of a kind or four of a kind or a full house, you know. So if I had to try and simulate that, that would be forever. But let's see if I can get something. Hold on. Let's see if we can get just something a little bit better for the interest rate. Okay, we can't. Okay, we're not being lucky. But if it was a two pair, so let's pretend these two cards are the same. Then the queen would be like, no, no, no, yes, pair plus one. And then this card would be like, yes, pair plus two, no, no. And then this one would be like, no, no. And then we've got pair is equal to two and let's pretend that those cards are the same. We have a two pair. If what you call it, we have, if our pair goes to the value of three, it means we have three of a kind. If we have four, it means we have a full house. And if we have four of a kind, it means the pair is equal to six. Let's actually see if we can just get, whoa, whoa, whoa, whoa. We got three of a kind. Fantastic. Hold on, let's just see if we can improve it. No, we can't improve it. But you can see, so this card, nothing, nothing, nothing, nothing. This card goes, nothing, yes, pair plus one. Pair plus one, so now pair is equal to two. This comes to this card, nothing, nothing. And then we come here, pair over here, plus one again. So we have pair three in total, three of a kind. And then if it's a full house, it will count four times. And if it's four of a kind, it will count six times. So this is the code to check if you've got one pair, two pairs, three of a kind, full house, four of a kind result. And what I've basically done is I've created something called the bubble match, which has taken its inspiration from the bubble sort method. And it's basically, it's four, four loops. So you basically could have a four loop within a four loop. And then it goes through and it checks each card against the other card. And it says if this card is the same, then ta-da, we can increase it. And you can see this value here is increasing. So we could very well have put this into a four loop. So a four loop within a four loop. Look, this was probably one of the hardest things that I did do from a logical perspective for the app. So how I got through this and maybe what you want to do is yourself is actually take out a set of cards and put five cards on the table and do this actually manually before writing the code just to help get your mind into gear. But there we go. That is the code for Android Studio on how to check if you've got those results in poker. This app is available in the App Store. So I will put a link in the description below and you can go and play around with it and hopefully try your luck. Thanks guys so much for watching and hit subscribe. There are a lot more poker videos, so be sure to check them out. Cheers.