-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBishop.java
More file actions
48 lines (38 loc) · 1.29 KB
/
Bishop.java
File metadata and controls
48 lines (38 loc) · 1.29 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
//imports-------
import java.util.*;
public class Bishop extends Piece{
public Bishop(int row,int col,boolean isWhite) {
super(row, col, isWhite);
}
//calculateing the moves using bfs
public void calculateMoves(Board b){
int[][] dir={{-1,-1},{-1,1},{1,-1},{-1,-1}};
//top left, top right, bottom left, bottom right
for(int i=0;i<dir.length;i++){
for(int r=this.row,c=this.col;r>=0 && c>=0 && r<8 && c<8;r+=dir[i][0], c+=dir[i][1]){
//if first time we dont check curr pos,(possible not to add this cond)
//Delete if needed
if(r==this.row && c==this.col){
continue;
}
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 ? 'B' : 'b';
}
@Override
public void draw() {}
}