-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathAvailable Captures for Rook.py
49 lines (49 loc) · 1.79 KB
/
Available Captures for Rook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Solution:
def numRookCaptures(self, board: List[List[str]]) -> int:
# Checking for possible case to the right of Rook
def right_position(n,i):
List = i[0:n][::-1] # taking list to the right of rook
pIndex,bIndex = -1,-1
if 'p' in List: # Checking if 'p' in list
pIndex = List.index('p')
if 'B' in List: # Checking if 'B' in list
bIndex = List.index('B')
print(bIndex,pIndex,List)
if bIndex == -1 and pIndex >-1: # if list does not have 'B' and have 'p'
return True
if pIndex == -1: # if list does not have 'p'
return False
return bIndex>pIndex
def left_position(n,i):
List = i[n+1:]# taking list to the right of rook
pIndex,bIndex = -1,-1
if 'p' in List:
pIndex = List.index('p')
if 'B' in List:
bIndex = List.index('B')
print(bIndex,pIndex,List)
if bIndex == -1 and pIndex >-1:
return True
if pIndex == -1:
return False
return bIndex>pIndex
Count = 0
# Checking for possibilites in row
for i in board:
if 'R' in i:
print(i)
n = i.index('R')
if left_position(n,i):
Count += 1
if right_position(n,i):
Count += 1
Col = []
# checking for possibilites in col
for i in range(0,len(board)):
Col.append(board[i][n]) # taking the elements from the same col of Rook
n = Col.index('R')
if left_position(n,Col):
Count += 1
if right_position(n,Col):
Count += 1
return Count