New getLegalDestinations method in ChessEngine

Quicksave
Justin 2025-06-19 20:01:05 +02:00
parent 13cb12717a
commit 9adb0db66b
1 changed files with 7 additions and 3 deletions

View File

@ -30,12 +30,16 @@ public class ChessEngine {
return false;
}
public List<String> getLegalDestinations(String from) {
List<String> destinations = new ArrayList<>();
public List<MoveDTO> getLegalDestinations(String from) {
List<MoveDTO> destinations = new ArrayList<>();
Square fromSq = Square.valueOf(from.toUpperCase());
for (Move move : board.legalMoves()) {
if (move.getFrom().equals(fromSq)) {
destinations.add(move.getTo().toString()); // z.B. "E4"
int fromRow = 8 - fromSq.getRank().ordinal();
int fromCol = fromSq.getFile().ordinal();
int toRow = 8 - move.getTo().getRank().ordinal();
int toCol = move.getTo().getFile().ordinal();
destinations.add(new MoveDTO(fromRow, fromCol, toRow, toCol));
}
}
return destinations;