-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPawn.java
35 lines (32 loc) · 886 Bytes
/
Pawn.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
33
34
35
import java.util.*;
public class Pawn extends Piece {
public Pawn(Location loc, boolean isWhite, Grid grid) {
super(loc,isWhite,grid);
}
@Override
public ArrayList<Location> reachable() {
ArrayList<Location> locations = new ArrayList<>();
int r = getLocation().getR();
int c = getLocation().getC();
int mult = isWhite() ? 1 : -1;
locations.add(grid.getLocation(c,r + mult));
if((mult * 2 + 9) % 9 == r && grid.getLocation(c,(mult * 3 + 9) % 9).piece()==null) {
locations.add(grid.getLocation(c,(r + mult * 2 + 9) % 9));
}
for(int i = -1; i < 2; i += 2) {
Location loc = grid.getLocation(c + i,r + mult);
if(loc.piece() != null) {
if(loc.piece().isWhite() ^ isWhite()) {
locations.add(loc);
}
}
}
//add en passant
//add promotion
return locations;
}
@Override
public String toString() {
return isWhite() ? "P" : "p";
}
}