OOP_2A5_Project/src/backend/SpecialMoves.java

147 lines
4.4 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*package backend;
import java.util.ArrayList;
public class SpecialMoves {
private Piece piece;
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 y = piece.getY();
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) {
this.piece = piece;
this.board = board;
} //???
public boolean checkCoordinates(int x, int y, PieceType type, boolean isWhite) {
if (type == PieceType.Pawn || isWhite == true || y == 6) {
int[][] offsets = {{1, -2}, {-1, -2}};
}
if (type == PieceType.Pawn || isWhite == false || y == 1) {
int[][] offsets = {{1, 2}, {-1, 2}};
}*/
/* 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) {
int[][] offsets = {{1, 0}, {-1, 0}};
}
}
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 ()
}
}
}
package backend;
public class SpecialMoves {
private Piece piece;
private Board board;
public SpecialMoves(Piece piece, Board board) {
this.piece = piece;
this.board = board;
}
// Call this when trying to move a pawn to check for en passant
public boolean isEnpassant(int fromX, int fromY, int toX, int toY) {
if (piece.getType() != PieceType.Pawn) return false;
boolean isWhite = piece.isWhite();
// En passant capture happens diagonally
int dx = toX - fromX;
int dy = toY - fromY;
if (Math.abs(dx) != 1 || (isWhite && dy != -1) || (!isWhite && dy != 1)) {
return false;
}
// Check the adjacent piece
Piece sidePawn = board.getPieceAt(toX, fromY);
if (sidePawn == null || sidePawn.getType() != PieceType.Pawn || sidePawn.isWhite() == isWhite) {
*/