Repository navigation
Expand file tree
/
Copy pathRock.java
More file actions
102 lines (86 loc) · 1.71 KB
/
Copy pathRock.java
File metadata and controls
102 lines (86 loc) · 1.71 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
public class Rock extends Chess{
@Override
public void setImage() {
// TODO Auto-generated method stub
}
@Override
public boolean[][] getReachableGrid(Chess[][] chessboard) {
boolean reachable[][] = new boolean[8][8];
int i = 0,j = 0;
for(i=0;i<8;i++)
for(j=0;j<8;j++)
reachable[i][j] = false;
for(i=y;i<8;i++){
if(chessboard[x][i]==null)
reachable[x][i] = true;
else if(chessboard[x][i].camp!=camp){
reachable[x][i] = true;
break;
}
else break;
}
for(i=y;i>=0;y--){
if(chessboard[x][i]==null)
reachable[x][i] = true;
else if(chessboard[x][i].camp!=camp){
reachable[x][i] = true;
break;
}
else break;
}
for(i=x;i<8;i++){
if(chessboard[i][y]==null)
reachable[i][y] = true;
else if(chessboard[i][y].camp!=camp){
reachable[i][y] = true;
break;
}
else break;
}
for(i=x;i>=0;i--){
if(chessboard[i][y]==null)
reachable[i][y] = true;
else if(chessboard[i][y].camp!=camp){
reachable[i][y] = true;
break;
}
else break;
}
reachable[x][y] = false;
return reachable;
}
@Override
public boolean isReachable(Chess[][] chessboard, int lx, int ly) {
boolean res = false;
int i;
if(x==lx||y==ly){
if(x==lx){
for(i=lx;i<8;i++){
if((chessboard[x][i]==null)){
if(i==ly)
res = true;
}else if(chessboard[x][i].camp!=camp){
if(i==ly){
res = true;
break;
}
}else break;
}
}
else{
for(i=ly;i<8;i++){
if((chessboard[i][y]==null)){
if(i==lx)
res = true;
}else if(chessboard[i][y].camp!=camp){
if(i==lx){
res = true;
break;
}
}else break;
}
}
}
return res;
}
}