moves and pieces correlation

This commit is contained in:
ricoc 2025-04-18 15:11:40 +02:00
parent 32333cf768
commit 76f061e679
2 changed files with 47 additions and 1 deletions

View File

@ -235,4 +235,10 @@ public class Board {
}
public boolean isEmpty(int x, int newY) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -1,5 +1,7 @@
package backend;
import java.util.ArrayList;
public class Piece {
private int x;
private int y;
@ -28,5 +30,43 @@ public class Piece {
public boolean isWhite() {
return pieceColor;
}
public ArrayList<Move> getPossibleMoves(Board board) {
ArrayList<Move> moves = new ArrayList<>();
switch (type) {
case Pawn:
// Example for a simple forward move (white only)
int direction = isWhite() ? -1 : 1;
int newY = y + direction;
if (board.isEmpty(x, newY)) {
moves.add(new Move(x, y, x, newY, this));
}
// Add capture moves, double-step moves etc. here
break;
case Rook:
// Add horizontal and vertical moves here
break;
case Knight:
// Add L-shaped moves here
break;
case Bishop:
// Add diagonal moves here
break;
case Queen:
// Combine Rook + Bishop moves
break;
case King:
// Add adjacent square moves
break;
}
return moves;
}
}
}