-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKing.java
34 lines (28 loc) · 1.01 KB
/
King.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
import java.util.*;
public class King extends Piece {
public King(Color c) {
this.color = c;
// throw new UnsupportedOperationException()
}
// implement appropriate methods
public String toString() {
if (color==null)
throw new UnsupportedOperationException();
String s = this.color.getColorStr()+"k";
return s;
}
public List<String> moves(Board b, String loc) {
int[] locArray = Helper.getLocArray(loc);
List<String> retList = new ArrayList<>();
// valid moves
for(int i=Math.max(0,locArray[0]-1);i<=Math.min(locArray[0]+1,7);i++) {
for (int j = Math.max(0,locArray[1]-1); j <=Math.min(locArray[1] + 1,7); j++) {
if(!color.getColorStr().equals(b.isOccupied(Helper.getLocStr(i,j))) && (i!=locArray[0] || j!=locArray[1])) {
retList.add(Helper.getLocStr(i,j));
}
}
}
return retList;
// throw new UnsupportedOperationException();
}
}