forked from sagnew/Chess
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBishop.java
More file actions
59 lines (41 loc) · 957 Bytes
/
Copy pathBishop.java
File metadata and controls
59 lines (41 loc) · 957 Bytes
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
public class Bishop extends Piece{
public String color;
public Bishop(String color){
this.color = color;
}
@Override
public boolean validateMove(Piece[][] board, int currentRow, int currentCol, int newRow, int newCol) {
if(currentRow == newRow || currentCol == newCol){
//Did not move diagonally
return false;
}
if(Math.abs(newRow - currentRow) != Math.abs(newCol - currentCol)){
return false;
}
int rowOffset, colOffset;
if(currentRow < newRow){
rowOffset = 1;
}else{
rowOffset = -1;
}
if(currentCol < newCol){
colOffset = 1;
}else{
colOffset = -1;
}
int y = currentCol + colOffset;
for(int x = currentRow + rowOffset; x != newRow; x += rowOffset){
if(board[x][y] != null){
return false;
}
y += colOffset;
}
return true;
}
public String getColor(){
return this.color;
}
public String toString(){
return color.charAt(0) + "B";
}
}