-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAvailableCapturesForRook.cpp
69 lines (59 loc) · 1.36 KB
/
AvailableCapturesForRook.cpp
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class Solution {
public:
int numRookCaptures(vector<vector<char>>& board) {
int X, Y;
for(int i=0; i<8; i++){
for(int j=0; j<8; j++){
if(board[i][j] == 'R'){
X = i;
Y = j;
}
}
}
int i = X+1, j = Y, Sol = 0;
while(i<8){
if(board[i][j] == 'B'){
break;
}
if(board[i][j] == 'p'){
Sol++;
break;
}
i++;
}
i=X-1;
while(i>=0){
if(board[i][j] == 'B'){
break;
}
if(board[i][j] == 'p'){
Sol++;
break;
}
i--;
}
i = X, j = Y+1;
while(j<8){
if(board[i][j] == 'B'){
break;
}
if(board[i][j] == 'p'){
Sol++;
break;
}
j++;
}
j=Y-1;
while(j>=0){
if(board[i][j] == 'B'){
break;
}
if(board[i][j] == 'p'){
Sol++;
break;
}
j--;
}
return Sol;
}
};