OOP_Groupe_1A3_Project/src/backend/MoveHighlighter.java

43 lines
1.8 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 MoveHighlighter {
public static ArrayList<int[]> getPossibleMoves(Piece piece, Board board){
ArrayList<int[]> validMoves = new ArrayList<int[]>();
MovePiece movement = new MovePiece(piece, board);
PieceType type= piece.getType();
MovementCapabilities specialMoves= new MovementCapabilities();
//looping through each square space
for (int x = 0; x < board.getWidth(); x++) {
for (int y = 0; y < board.getHeight(); y++) {
boolean valid=false;
System.out.println("MoveHighlighter: checking (" + x + "," + y + ") for type " + type);
if(type==PieceType.Pawn) {
valid=movement.movePawnSimulate(x, y)|| specialMoves.enPassant(piece, x, y, board);;
} else if(type==PieceType.Rook) {
valid=movement.moveRookSimulate(x, y);
}else if(type==PieceType.King) {
valid=movement.moveKingSimulate(x, y)|| specialMoves.castling(piece, x, y, new Board(board));
//Because castling moves two pieces (king and rook), and you dont want the highlight simulation to affect your real board.
//Creating a temporary copy (new Board(board)) allows us to test if castling would work without breaking anything.
}else if(type==PieceType.Queen) {
valid=movement.moveQueenSimulate(x, y);
}else if(type==PieceType.Bishop) {
valid=movement.moveBishopSimulate(x, y);
}else if(type==PieceType.Knight) {
valid=movement.moveKnightSimulate(x, y);
}
if(valid) {
System.out.println("✅ Valid move for " + type + " at (" + piece.getX() + "," + piece.getY() + ") → (" + x + "," + y + ")");
System.out.println("Highlighting move to (" + x + "," + y + ") for " + type);
validMoves.add(new int[] {x,y});
}
}
}
return validMoves;
}
}