-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBishop.java
More file actions
45 lines (28 loc) · 928 Bytes
/
Copy pathBishop.java
File metadata and controls
45 lines (28 loc) · 928 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
package chess;
public class Bishop extends Piece{
// Bishop class
public Bishop (char file, int rank, boolean isBlack) {
super (file, rank, isBlack);
}
@Override
public boolean canMove (char startFile, int startRank, char newFile,
int newRank, Board board) {
if (!isDiffSquare(startFile, startRank, newFile, newRank)) return false;
if (!diagonalMove(startFile, startRank, newFile, newRank)) return false;
if (!pathClear(startFile, startRank, newFile, newRank, board)) return false;
Piece newLoc = board.getPiece(newFile, newRank);
if (newLoc == null) {
return true;
}
if (newLoc.isBlack != this.isBlack) return true;
else return false;
}
@Override
public Piece clone() {
return new Bishop(this.getFile(), this.getRank(), this.isBlack);
}
@Override
public String getSymbol() {
return ("B");
}
}