 What's up guys my is Michael and welcome to my YouTube channel today. We're gonna do another leak code challenge It's called available Captures for Rook so you're given an 8 by 8 chess board and each of them has empty squares white bishops and black ponds So they are given these characters are for R for um, let's see R dot B and P Okay, so the uppercase characters represent white pieces lowercase characters represent black pieces so the R represents the Rook the B represents the The a bishop that's white and then a the P represents a Pond okay, P represents a black pond the what moves in the rules of chess, so it moves a Horizontally or vertically that's what this means Until it reaches the edge of the board or captures an opposing piece by moving to the line it occupies so Rooks you cannot move in the same Square as other friendly bishops, okay? So the Rooks can only move left to right and up and down and bishops can move diagonal So return a number of ponds that the Rook can capture in one move So I'm gonna give you time to do this question and then I'll come back and I'll explain my solution right here Okay, so based on my solution This is what I did well first of all you need to keep track the number of ponds that we're returning and that's the Number of ponds are capturing So what I did first I had to go through the whole board in order to find the Rook because you need to find the position of The Rook first before you could figure out then the ponds it could capture Around its space for her horizontally and vertically So once I find I had to go through the whole board once I find the Rook I set the position of the Rooks row and column and then I break out of these four or two for loops So that's that would that would stop the for loop once I find a the Rook Once I find the Rook Then I had to go through This is gonna go through This is gonna go through to the left side. Okay, so this is gonna start at the row and it's gonna The index is gonna start at the current row that the Rook is on and it's gonna keep going until it reaches zero And this is basically in traverse left side. So basically the zero represents the row over here Zero one two three four right. So this is gonna go from four down to zero. So this is gonna check all the left sides basically, I'm gonna check if I've reached a Bishop because if I reach a bishop then I have to get out of the Have to get out of the board That means I can't capture it if there's a bishop interfering with my own bishop interfering like in this case If there's a bishop in this in the position that where I'm at Then I can't actually capture a pond even if there is a pond that is at that Location near me if there's a bishop then I have to break out and I can't capture the pond Now I have to check if there's a pond that I'm gonna capture to the left side Remember I'm going to the left Decrementing this way if I see a pond I'm gonna increase in my number of ponds and then I break out The reason why I break out because I can't capture two ponds at the same time based on this based on this Example three as you can see here an example three you cannot capture these two ponds on the left side You only could capture one pond at a time So going through the left side. There's only one pond that they could capture So that's why you have to break out once you see one pond Then I have to go through the right side You have to check horizontally to the right side and check exactly the same way as I checked to the left side Got to check if there's a bishop interfering if there's my own bishop interfering with The whatever I'm checking then I have to get out and break It means I can't capture a pond Now if I did now if it what there's if there was no bishop in that location Then I have to check if there's a pond and I increase number of ponds and then I break Because I only could capture one pond at a time and that would get me One pond on the right side in this case Then I have to check through going upwards and downwards and it's about exactly the same thing Going upwards. I'm going to start at my column and I'm going to keep going until I hit to the sides and that's going to go this way Now I have to check going downwards, which is Basically I have to keep going until I reach zero starting at my column So that's going to go this way and I do the exact same thing for checking of going upwards and downwards got to check if there's a if there's a bishop interfering then you break Otherwise you have to check if there's a pond if there's a pond you got to increase the number ponds and then break And that's basically it Once you have the number of ponds you just return the number of ponds and that's the solution for this. It's pretty basic It's all you have to do. Yeah Let me know what kind of solutions you guys thought of And see if it's more efficient or not break off scribe a check