Add getLegalDestinations() method to ChessEngine
parent
cf0a8173b4
commit
fe8c1a65d9
|
|
@ -1,5 +1,8 @@
|
|||
package de.hs_mannheim.informatik.chess.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.bhlangonijr.chesslib.Board;
|
||||
import com.github.bhlangonijr.chesslib.Square;
|
||||
import com.github.bhlangonijr.chesslib.move.Move;
|
||||
|
|
@ -21,5 +24,16 @@ public class ChessEngine {
|
|||
}
|
||||
}
|
||||
|
||||
public List<String> getLegalDestinations(String from) {
|
||||
List<String> 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"
|
||||
}
|
||||
}
|
||||
return destinations;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue