classSolution: defnumRookCaptures(self, board) -> int: i = j = 0 for row in board: if'R'in row: break i += 1 j = row.index('R') count = 0 # right for x inrange(j + 1, 8): if row[x] == 'p': count += 1 break if row[x] == 'B': break # left for x inrange(j, 0, -1): if row[x] == 'p': count += 1 break if row[x] == 'B': break # up for x inrange(i, 0, -1): if board[x][j] == 'p': count += 1 break if board[x][j] == 'B': break # down for x inrange(i+1, 8): if board[x][j] == 'p': count += 1 break if board[x][j] == 'B': break