Available Captures for Rook
More downvotes. Problem statement is confusing.
We can solve this problem by first finding the position of the rook on the board, and then checking each of the four cardinal directions for pawns (‘p’) that can be captured. The directions are north (up), south (down), east (right), and west (left).
Here is a Python solution using this approach:
|
|
This code first loops over the entire board to find the rook. Once the rook is found, it checks each of the four cardinal directions until it encounters a bishop (‘B’), the edge of the board, or a pawn (‘p’). If it encounters a pawn, it increments the captures
counter and breaks out of the current direction. The number of captures is then returned.