43 lines
1.8 KiB
Java
43 lines
1.8 KiB
Java
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 don’t 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;
|
||
}
|
||
}
|