-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnight.java
More file actions
42 lines (28 loc) · 938 Bytes
/
Copy pathKnight.java
File metadata and controls
42 lines (28 loc) · 938 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
package chess;
public class Knight extends Piece {
// The neigh-whinny class
public Knight (char file, int rank, boolean isBlack) {
super (file, rank, isBlack);
}
@Override
public boolean canMove (char startFile, int startRank, char newFile,
int newRank, Board board) {
// Check for vertical, horizontal, a clear path and that the square is different from its own
if (!isDiffSquare(startFile, startRank, newFile, newRank)) return false;
if (!lMove(startFile, startRank, newFile, newRank)) 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 Knight(this.getFile(), this.getRank(), this.isBlack);
}
@Override
public String getSymbol() {
return ("N");
}
}