Added in board a findmovesandcastlingmoves it has find moves and it adds
the findcastling moves to it. Couldn't put everything into findmoves because it created an inifinte loop when caleed in chessrules... PROBLEMATIC!!! Only need to implemnt the actual castling part now!
This commit is contained in:
parent
3ac5c282a5
commit
bf169743bf
|
|
@ -2,6 +2,7 @@ package backend;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class Board {
|
||||
|
||||
private int colNum;
|
||||
|
|
@ -169,7 +170,7 @@ public class Board {
|
|||
selectedY = y;
|
||||
|
||||
highlight.clear();
|
||||
highlight.addAll(findMoves(p));
|
||||
highlight.addAll(findCastlingMoves(p)); //the NEW UPDATED ONE for CASTLING
|
||||
} else {
|
||||
selectedX = -1;
|
||||
selectedY = -1;
|
||||
|
|
@ -355,6 +356,27 @@ public class Board {
|
|||
return moves;
|
||||
}
|
||||
|
||||
public ArrayList<Position> findCastlingMoves(Piece p) {
|
||||
|
||||
ArrayList<Position> moves = findMoves(p); //all the basic moves
|
||||
|
||||
if (p.getType() == PieceType.King) {
|
||||
ChessRulesCheck rules = new ChessRulesCheck();
|
||||
boolean white = p.isWhite();
|
||||
int rank = white ? 7 : 0, kx = p.getX();
|
||||
|
||||
if (kx == 4 && rules.canItCastle(this, white, true)) {
|
||||
moves.add(new Position(6, rank));
|
||||
}
|
||||
|
||||
if (kx == 4 && rules.canItCastle(this, white, false)) {
|
||||
moves.add(new Position(2, rank));
|
||||
}
|
||||
}
|
||||
|
||||
return moves;
|
||||
}
|
||||
|
||||
private void extend(ArrayList<Position> moves, int x, int y, boolean isWhite, int dx, int dy) {
|
||||
int nx = x + dx;
|
||||
int ny = y + dy;
|
||||
|
|
|
|||
Loading…
Reference in New Issue