Compare commits
2 Commits
f14bb1d522
...
2aabc3b0f1
| Author | SHA1 | Date |
|---|---|---|
|
|
2aabc3b0f1 | |
|
|
22eea2b7e9 |
|
|
@ -15,7 +15,11 @@ public class Board {
|
||||||
private boolean pawnDoubleStep;
|
private boolean pawnDoubleStep;
|
||||||
private int xCoordinatePawn;
|
private int xCoordinatePawn;
|
||||||
private int yCoordinatePawn;
|
private int yCoordinatePawn;
|
||||||
|
//<<<<<<< HEAD
|
||||||
|
private boolean enPassant;
|
||||||
|
//=======
|
||||||
private boolean isGameOver = false;//flag for when a king is checkmate and no moves can be made anymore
|
private boolean isGameOver = false;//flag for when a king is checkmate and no moves can be made anymore
|
||||||
|
//>>>>>>> branch 'master' of https://gitarero.ecam.fr/louise.berteloot/OOP_2A5_Project.git
|
||||||
|
|
||||||
private ArrayList<Board> previousStates;
|
private ArrayList<Board> previousStates;
|
||||||
|
|
||||||
|
|
@ -25,6 +29,7 @@ public class Board {
|
||||||
this.turnNumber = 0;
|
this.turnNumber = 0;
|
||||||
this.isWhiteTurn = true; // White starts first
|
this.isWhiteTurn = true; // White starts first
|
||||||
this.previousStates = new ArrayList<>(); // Initialize the ArrayList
|
this.previousStates = new ArrayList<>(); // Initialize the ArrayList
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
|
|
@ -55,6 +60,14 @@ public class Board {
|
||||||
return this.isWhiteTurn;
|
return this.isWhiteTurn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEnPassant() {
|
||||||
|
return this.enPassant;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnPassant(boolean enPassant) {
|
||||||
|
this.enPassant = enPassant;
|
||||||
|
}
|
||||||
|
|
||||||
public void resetTurn() {
|
public void resetTurn() {
|
||||||
this.turnNumber = 0;
|
this.turnNumber = 0;
|
||||||
this.isWhiteTurn = true;
|
this.isWhiteTurn = true;
|
||||||
|
|
@ -202,11 +215,23 @@ public class Board {
|
||||||
// detects castling (piece is castling only if piecetype is king and distance between king and its move is of 2)
|
// detects castling (piece is castling only if piecetype is king and distance between king and its move is of 2)
|
||||||
boolean isCastling = selectedPiece.getType() == PieceType.King && Math.abs(x - originalX) == 2;
|
boolean isCastling = selectedPiece.getType() == PieceType.King && Math.abs(x - originalX) == 2;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
|
} else {
|
||||||
|
if (enPassant == true && y == Math.abs(yCoordinatePawn-1) && x == xCoordinatePawn) {
|
||||||
|
pieces.remove(getPieceAt(xCoordinatePawn, yCoordinatePawn));
|
||||||
|
enPassant = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Moving piece to: " + x + ", " + y);
|
System.out.println("Moving piece to: " + x + ", " + y);
|
||||||
|
|
@ -230,15 +255,6 @@ public class Board {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,10 @@ import java.util.ArrayList;
|
||||||
public class MoveConditions {
|
public class MoveConditions {
|
||||||
private Piece piece;
|
private Piece piece;
|
||||||
private Board board;
|
private Board board;
|
||||||
|
//private boolean enPassant;
|
||||||
|
|
||||||
public MoveConditions(Piece piece, Board board) {
|
|
||||||
|
public MoveConditions(Piece piece, Board board) {
|
||||||
this.piece = piece;
|
this.piece = piece;
|
||||||
this.board = board;
|
this.board = board;
|
||||||
}
|
}
|
||||||
|
|
@ -58,6 +60,7 @@ public class MoveConditions {
|
||||||
sidePawn.isWhite() != isWhite) {
|
sidePawn.isWhite() != isWhite) {
|
||||||
|
|
||||||
moves.add(new int[]{sideX, y + dir}); // capture en passant square
|
moves.add(new int[]{sideX, y + dir}); // capture en passant square
|
||||||
|
board.setEnPassant(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue