-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRook.java
More file actions
62 lines (39 loc) · 1.31 KB
/
Copy pathRook.java
File metadata and controls
62 lines (39 loc) · 1.31 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
package chess;
public class Rook extends Piece {
// Rook class
public boolean rookHasMoved = false;
public Rook (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 (!horizontalMove(startFile, startRank, newFile, newRank) && !verticalMove(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;
}
public void rookOfficiallyMoved() {
rookHasMoved = true;
}
public boolean checkIfMoved() {
return rookHasMoved;
}
@Override
public Piece clone() {
Rook cloned = new Rook(this.getFile(), this.getRank(), this.isBlack);
cloned.rookHasMoved = this.rookHasMoved;
return cloned;
}
@Override
public String getSymbol() {
return ("R");
}
}