Merge branch 'master' of https://gitarero.ecam.fr/louise.berteloot/OOP_2A5_Project.git
This commit is contained in:
commit
6e899924bd
|
|
@ -12,6 +12,9 @@ public class Board {
|
||||||
private int selectedX = -1;
|
private int selectedX = -1;
|
||||||
private int selectedY = -1;
|
private int selectedY = -1;
|
||||||
ArrayList<int[]> highlightedSquares = new ArrayList<>();
|
ArrayList<int[]> highlightedSquares = new ArrayList<>();
|
||||||
|
private boolean pawnDoubleStep;
|
||||||
|
private int xCoordinatePawn;
|
||||||
|
private int yCoordinatePawn;
|
||||||
|
|
||||||
private ArrayList<Board> previousStates;
|
private ArrayList<Board> previousStates;
|
||||||
|
|
||||||
|
|
@ -27,6 +30,18 @@ public class Board {
|
||||||
return colNum;
|
return colNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPawnDoubleStep() {
|
||||||
|
return pawnDoubleStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getXCoordinatePawn() {
|
||||||
|
return xCoordinatePawn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getYCoordinatePawn() {
|
||||||
|
return yCoordinatePawn;
|
||||||
|
}
|
||||||
|
|
||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
return lineNum;
|
return lineNum;
|
||||||
}
|
}
|
||||||
|
|
@ -102,42 +117,6 @@ public class Board {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public void movePiece(int fromX, int fromY, int toX, int toY) {
|
|
||||||
Piece piece = board.getPieceAt(fromX, fromY);
|
|
||||||
if (piece == null) return;
|
|
||||||
|
|
||||||
// --- En Passant ---
|
|
||||||
SpecialMoves special = new SpecialMoves(piece, board);
|
|
||||||
boolean isEnPassant = special.isEnpassant(fromX, fromY, toX, toY);
|
|
||||||
|
|
||||||
// --- Move the piece
|
|
||||||
board.setPieceAt(toX, toY, piece);
|
|
||||||
board.setPieceAt(fromX, fromY, null);
|
|
||||||
piece.setX(toX);
|
|
||||||
piece.setY(toY);
|
|
||||||
|
|
||||||
// --- Reset all pawns' en passant eligibility
|
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
for (int j = 0; j < 8; j++) {
|
|
||||||
Piece p = board.getPieceAt(i, j);
|
|
||||||
if (p != null && p.getType() == PieceType.Pawn) {
|
|
||||||
p.setEnPassantEligible(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- If current pawn moved 2 steps forward, set it eligible for en passant
|
|
||||||
if (piece.getType() == PieceType.Pawn && Math.abs(toY - fromY) == 2) {
|
|
||||||
piece.setEnPassantEligible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- En Passant message
|
|
||||||
if (isEnPassant) {
|
|
||||||
System.out.println("En Passant captured successfully!");
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
public void cleanBoard() {
|
public void cleanBoard() {
|
||||||
pieces.clear();
|
pieces.clear();
|
||||||
}
|
}
|
||||||
|
|
@ -209,6 +188,7 @@ public class Board {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (clickedPiece != null) {
|
if (clickedPiece != null) {
|
||||||
System.out.println("Capturing piece at: " + x + ", " + y);
|
System.out.println("Capturing piece at: " + x + ", " + y);
|
||||||
pieces.remove(clickedPiece);
|
pieces.remove(clickedPiece);
|
||||||
|
|
@ -218,6 +198,15 @@ public class Board {
|
||||||
selectedPiece.setX(x);
|
selectedPiece.setX(x);
|
||||||
selectedPiece.setY(y);
|
selectedPiece.setY(y);
|
||||||
|
|
||||||
|
if (selectedPiece.getType() == PieceType.Pawn && Math.abs(y - selectedY) == 2) {
|
||||||
|
pawnDoubleStep = true; //boolean to check if pawn has been moved 2 at start
|
||||||
|
xCoordinatePawn = x; //get its coordinates
|
||||||
|
yCoordinatePawn = y;
|
||||||
|
System.out.println("Pawn moved two squares to (" + xCoordinatePawn + ", " + yCoordinatePawn + ")");
|
||||||
|
} else {
|
||||||
|
pawnDoubleStep = false;
|
||||||
|
}
|
||||||
|
|
||||||
turnNumber++;
|
turnNumber++;
|
||||||
isWhiteTurn = !isWhiteTurn;
|
isWhiteTurn = !isWhiteTurn;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,30 @@ public class MoveConditions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return moves;
|
|
||||||
|
// En Passant
|
||||||
|
boolean pawnDoubleStep = board.isPawnDoubleStep();
|
||||||
|
int xCoordinatePawn = board.getXCoordinatePawn();
|
||||||
|
int yCoordinatePawn = board.getYCoordinatePawn();
|
||||||
|
|
||||||
|
if (pawnDoubleStep && y == (isWhite ? 3 : 4)) { // y = 3 for white, y = 4 for black
|
||||||
|
for (int dx : new int[]{-1, 1}) {
|
||||||
|
int sideX = x + dx;
|
||||||
|
if (sideX == xCoordinatePawn && y == yCoordinatePawn) {
|
||||||
|
Piece sidePawn = board.getPieceAt(sideX, y);
|
||||||
|
if (sidePawn != null &&
|
||||||
|
sidePawn.getType() == PieceType.Pawn &&
|
||||||
|
sidePawn.isWhite() != isWhite) {
|
||||||
|
|
||||||
|
moves.add(new int[]{sideX, y + dir}); // capture en passant square
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return moves;
|
||||||
|
}
|
||||||
|
|
||||||
public ArrayList<int[]> getKnightMoves() {
|
public ArrayList<int[]> getKnightMoves() {
|
||||||
ArrayList<int[]> moves = new ArrayList<>();
|
ArrayList<int[]> moves = new ArrayList<>();
|
||||||
int x = piece.getX();
|
int x = piece.getX();
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,74 @@
|
||||||
/*package backend;
|
/*package backend;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class SpecialMoves {
|
public class SpecialMoves {
|
||||||
<<<<<<< HEAD
|
|
||||||
|
|
||||||
private Piece piece;
|
private Piece piece;
|
||||||
private Board board;
|
|
||||||
|
|
||||||
|
|
||||||
private Piece piece;
|
|
||||||
private Board board;
|
private Board board;
|
||||||
|
private boolean isWhite;
|
||||||
|
|
||||||
|
|
||||||
|
public SpecialMoves(Piece piece, Board board) {
|
||||||
|
this.piece = piece;
|
||||||
|
this.board = board;
|
||||||
|
this.isWhite = piece.isWhite();
|
||||||
|
}
|
||||||
|
|
||||||
private int x = piece.getX();
|
private int x = piece.getX();
|
||||||
private int y = piece.getY();
|
private int y = piece.getY();
|
||||||
private PieceType type = PieceType.getType();
|
|
||||||
private boolean isWhite;
|
private boolean pawnDoubleStep = board.isPawnDoubleStep();
|
||||||
|
private int xCoordinatePawn = board.getXCoordinatePawn();
|
||||||
|
private int yCoordinatePawn = board.getYCoordinatePawn();
|
||||||
|
|
||||||
|
for (int n = 2; n < 4; n++) {
|
||||||
|
int i = x + pieceMoves[n][0]
|
||||||
|
|
||||||
|
int j = y + pieceMoves[n][1];
|
||||||
|
Move move = new Move(x, y, i, j);
|
||||||
|
|
||||||
|
// Diagonal capture
|
||||||
|
if (inBoard(i, j) &&
|
||||||
|
board.getPiece(j, i) != null &&
|
||||||
|
board.getPiece(j, i).isWhite() != isWhite &&
|
||||||
|
!checkIf(move, coordinates[0], coordinates[1], isWhite)) {
|
||||||
|
|
||||||
|
moves.add(new int[]{i, j});
|
||||||
|
}
|
||||||
|
|
||||||
|
// En Passant
|
||||||
|
else if (inBoard(i, j) &&
|
||||||
|
board.getPiece(j, i) == null &&
|
||||||
|
pawnDoubleStep &&
|
||||||
|
i == xCoordinatePawn &&
|
||||||
|
y == yCoordinatePawn &&
|
||||||
|
Math.abs(x - xCoordinatePawn) == 1 &&
|
||||||
|
board.getPiece(y, xCoordinatePawn) != null &&
|
||||||
|
board.getPiece(y, xCoordinatePawn).getType() == PieceType.Pawn &&
|
||||||
|
board.getPiece(y, xCoordinatePawn).isWhite() != isWhite &&
|
||||||
|
!checkIf(move, coordinates[0], coordinates[1], isWhite)) {
|
||||||
|
|
||||||
|
moves.add(new int[]{i, j});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return moves;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean inBoard(int x, int y) {
|
||||||
|
return x >= 0 && x < 8 && y >= 0 && y < 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkIf(Move move, int x, int y, boolean isWhite) {
|
||||||
|
// Stub – replace with your actual move-check logic
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* public SpecialMoves(Piece piece, Board board) {
|
/* public SpecialMoves(Piece piece, Board board) {
|
||||||
this.piece = piece;
|
this.piece = piece;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue