In order to validate if selected_move is a legal move in standard chess rules you can do something like:
if (board.legalMoves().contains(selected_move)) {
board.doMove(selected_move);
}
if you just want to validate if shuffling around some piece within the chessboard - which is not necessarily a legal move - leaves it in a valid state (i.e.: own king is not attacked after the move):
if (board.isMoveLegal(arbitrary_move, true)) {
// chessboard is in a valid state
}
this is particularly useful when for example you are implementing a GUI with a drag & drop feature for editing a chess position.
In order to validate if
selected_move
is a legal move in standard chess rules you can do something like:if you just want to validate if shuffling around some piece within the chessboard - which is not necessarily a legal move - leaves it in a valid state (i.e.: own king is not attacked after the move):
this is particularly useful when for example you are implementing a GUI with a drag & drop feature for editing a chess position.