-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pawn.java
49 lines (35 loc) · 1.27 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//imports:
import java.util.*;
public class Pawn extends Piece{
//variables
public boolean isFirstMove=true;
public Pawn(int row, int col, boolean isWhite) {
super(row, col, isWhite);
}
//methods:
public void calculateMoves(Board b){
//change to check the moves better - we dont have a check checker
if (this.row-1>=0 && b.getCell(this.row-1,this.col).getPiece()==null){
if(isFirstMove && this.row-2>=0 && b.getCell(this.row-2,this.col).getPiece()==null){
super.possibleMoves.add(new int[] {this.row-2,this.col});
}
isFirstMove = false;
super.possibleMoves.add(new int[] {this.row-1,this.col});
}
if(row-1>=0 && col+1<8 && b.getCell(row-1, col+1).getPiece()!=null)
super.possibleMoves.add(new int[] {row-1,col+1});
if(row-1>=0 && col-1>=0 && b.getCell(row-1, col-1).getPiece()!=null)
super.possibleMoves.add(new int[] {row-1,col-1});
validateMoves(b);
}
public List<int[]> getMoves(Board b) {
calculateMoves(b);
return this.possibleMoves;
}
@Override
public char toChar() {
return this.isWhite ? 'P':'p';
}
@Override
public void draw() {}
}