New getLegalDestinations method in ChessEngine
parent
13cb12717a
commit
9adb0db66b
|
|
@ -30,12 +30,16 @@ public class ChessEngine {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getLegalDestinations(String from) {
|
public List<MoveDTO> getLegalDestinations(String from) {
|
||||||
List<String> destinations = new ArrayList<>();
|
List<MoveDTO> destinations = new ArrayList<>();
|
||||||
Square fromSq = Square.valueOf(from.toUpperCase());
|
Square fromSq = Square.valueOf(from.toUpperCase());
|
||||||
for (Move move : board.legalMoves()) {
|
for (Move move : board.legalMoves()) {
|
||||||
if (move.getFrom().equals(fromSq)) {
|
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;
|
return destinations;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue