-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueen.java
More file actions
31 lines (30 loc) · 983 Bytes
/
Queen.java
File metadata and controls
31 lines (30 loc) · 983 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
public class Queen extends Piece{
public Queen(int row,int col,boolean isWhite){
super(row, col, isWhite);
}
//TODO: implement movement.
public void calculateMoves(Board b){
int[][] dir={{-1,-1},{-1,1},{1,-1},{-1,-1},{1,0},{0,1},{-1,0},{0,-1}};
for(int[] d:dir){
for(int r=this.row,c=this.col;r>=0 && c>=0 && r<8 && c<8;r+=d[0],c+=d[1]){
if(b.getCell(r,c).getPiece()==null){
super.possibleMoves.add(new int[] {r,c});
}else{
if(b.getCell(r,c).getPiece().isWhite==this.isWhite){
break;
}else{
super.possibleMoves.add(new int[] {r,c});
break;
}
}
}
}
validateMoves(b);
}
@Override
public char toChar() {
return this.isWhite ? 'Q' : 'q';
}
@Override
public void draw() {}
}