-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathQueen.java
More file actions
37 lines (24 loc) · 967 Bytes
/
Queen.java
File metadata and controls
37 lines (24 loc) · 967 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
import java.util.LinkedList;
import java.util.List;
public class Queen extends Piece {
public Queen(int color, Square initSq, String img_file) {
super(color, initSq, img_file);
}
@Override
public List<Square> getLegalMoves(Board b) {
LinkedList<Square> legalMoves = new LinkedList<Square>();
Square[][] board = b.getSquareArray();
int x = this.getPosition().getXNum();
int y = this.getPosition().getYNum();
int[] occups = getLinearOccupations(board, x, y);
for (int i = occups[0]; i <= occups[1]; i++) {
if (i != y) legalMoves.add(board[i][x]);
}
for (int i = occups[2]; i <= occups[3]; i++) {
if (i != x) legalMoves.add(board[y][i]);
}
List<Square> bMoves = getDiagonalOccupations(board, x, y);
legalMoves.addAll(bMoves);
return legalMoves;
}
}