-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBishop.java
32 lines (28 loc) · 972 Bytes
/
Bishop.java
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
package Chess;
public class Bishop extends Piece{
public Bishop(int color, Square location) {
super(color,location);
}
@Override
public boolean canMove(String to) {
boolean validMove = false;
Square targetLocation = location.getBoard().getSquareAt(to);
Square [] between = location.getBoard().getSquaresBetween(location,targetLocation);
if(this.location.isAtSameDiagonal(targetLocation)){
// for loop checks squares between target and initial location are empty
for (Square square : between){
validMove = square.isEmpty();
}
if(!validMove){
if(targetLocation.getPiece() != null && targetLocation.getPiece().isEnemy(this))
validMove = true;
}
return validMove;
}
return false;
}
@Override
public String toString() {
return color == 0 ? "B":"b";
}
}