diff --git a/src/backend/Board.java b/src/backend/Board.java index 37fd29a..12dac32 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -393,5 +393,42 @@ public class Board { // 6. If the king is in check and no move avoids it → checkmate return kingInCheck && !hasEscape; } + + private void enPassant(Board board, List moves) { + int x = this.x; + int y = this.y; + + if (isWhite() == true && this.y == 3) { + if(isEnPassant(board, new Piece(x - 1, y))) + moves.add(new Move(this, new Piece(x - 1, y - 1), + board.getPieceAt(new Piece(x - 1, y)))); + if(canCaptureEnPassant(board, new Piece(x + 1, y))) + moves.add(new Move(this, new Piece(x + 1, y - 1), + board.getPieceAt(new Piece(x + 1, y)))); + } + if (isWhite() == false && this.y == 4) { + if(isEnPassant(board, new Piece(x - 1, y))) + moves.add(new Move(this, new Piece(x - 1, y + 1), + board.getPieceAt(new Piece(x - 1, y)))); + if(canCaptureEnPassant(board, new Piece(x + 1, y))) + moves.add(new Move(this, new Piece(x + 1, y + 1), + board.getPieceAt(new Piece(x + 1, y)))); + } + } + + /** + * Checks if the pawn can capture another pawn by en passant + * @param pt location of the other pawn + * @return true if can be captured + */ + private boolean isEnPassant(Board board, Point pt) { + Piece temp = board.getPieceAt(pt); + if(temp != null) + if (temp instanceof Pawn && temp.getColor() != this.color) + if (((Pawn)temp).enPassantOk) + return true; + return false; + } + } diff --git a/src/backend/Piece.java b/src/backend/Piece.java index bc84ba0..da4dab6 100644 --- a/src/backend/Piece.java +++ b/src/backend/Piece.java @@ -1,4 +1,4 @@ -package backend; + package backend; public class Piece { private int x; diff --git a/src/backend/SpecialMoves.java b/src/backend/SpecialMoves.java index 5e0b587..71719ef 100644 --- a/src/backend/SpecialMoves.java +++ b/src/backend/SpecialMoves.java @@ -1,6 +1,12 @@ /*package backend; public class SpecialMoves { +<<<<<<< HEAD + + private Piece piece; + private Board board; + + private Piece piece; private Board board; private int x = piece.getX(); @@ -21,12 +27,17 @@ public class SpecialMoves { int[][] offsets = {{1, 2}, {-1, 2}}; }*/ +<<<<<<< HEAD + public boolean checkCoordinates(int x, int y, PieceType type, boolean isWhite) { + if (type == PieceType.Pawn && isWhite == true && y == 3) { +======= /* public boolean checkCoordinates(int x, int y, PieceType type, boolean isWhite) { if (type == PieceType.Pawn || isWhite == true || y == 3) { +>>>>>>> branch 'master' of https://gitarero.ecam.fr/louise.berteloot/OOP_2A5_Project.git int[][] offsets = {{1, 0}, {-1, 0}}; } - if (type == PieceType.Pawn || isWhite == false || y == 4) { + if (type == PieceType.Pawn && isWhite == false && y == 4) { int[][] offsets = {{1, 0}, {-1, 0}}; } @@ -36,13 +47,17 @@ public class SpecialMoves { public boolean isEnpassant() { boolean isWhite = piece.isWhite(); +<<<<<<< HEAD + if (boolean isWhite == true && PieceType getType() == PieceType.Pawn) { //no idea honestly +======= if (isWhite == true || PieceType getType() == PieceType.Pawn) { //no idea honestly +>>>>>>> branch 'master' of https://gitarero.ecam.fr/louise.berteloot/OOP_2A5_Project.git if () } - if (boolean isWhite == false|| //PieceType type == Pawn) { + if (boolean isWhite == false && //PieceType type == Pawn) { if () } - } + } }*/