bhlangonijr / chesslib

chess library for legal move generation, FEN/PGN parsing and more
Apache License 2.0
223 stars 78 forks source link

Critical Issue with isLegalMove() #112

Closed Jochengehtab closed 11 months ago

Jochengehtab commented 1 year ago

Why does board.isMoveLegal(new Move(Square.D2, Square.D5), true); does return true in the starting position ??????????????????????????????????????????

bhlangonijr commented 11 months ago

This is not an issue. Board#isMoveLegal() essentially verifies whether the move leaves the board in a valid state (It's arguable if the function naming is misleading though). This is useful when you want to use this function to validate the board state when editing the board - UI drag & drop feature - and want to make sure the final board state is in a valid state (i.e. king doesn't remain in check while moving other pieces). If you want to make sure user's input is a legal move you should match it against Board#legalMoves().