Fix is_legal accepting non-canonical castling encodings#1096
Open
grepfuldead wants to merge 1 commit into
Open
Fix is_legal accepting non-canonical castling encodings#1096grepfuldead wants to merge 1 commit into
grepfuldead wants to merge 1 commit into
Conversation
is_legal derives the castling kind from to.file() == File::G alone and
never checks that to is the actual landing square, so with castling
rights and a clear path it accepts (king_from, arbitrary to, Castling)
for 63 bogus encodings per position. Playing one hits the unreachable
in get_castling_rook. Search is unaffected (UCI and the TT path only
see canonical encodings), but islegalperft feeds every accepted
encoding to make_move and currently panics on any position with
castling rights:
position fen r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1
islegalperft 1 -> panicked: entered unreachable code
Require to == kind.landing_square(), making is_legal an exact mirror
of generate_all_moves and restoring the diagnostic (kiwipete
islegalperft 1 now completes: 48). Matches the convention in Stockfish,
where special-move validity is generated-set membership.
No functional change.
Bench: 2526370
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
is_legal derives the castling kind from to.file() == File::G alone and never checks that to is the actual landing square, so with castling rights and a clear path it accepts (king_from, arbitrary to, Castling) for 63 bogus encodings per position. Playing one hits the unreachable in get_castling_rook. Search is unaffected (UCI and the TT path only see canonical encodings), but islegalperft feeds every accepted encoding to make_move and currently panics on any position with castling rights:
Require to == kind.landing_square(), making is_legal an exact mirror of generate_all_moves and restoring the diagnostic (kiwipete islegalperft 1 now completes: 48). Matches the convention in Stockfish, where special-move validity is generated-set membership.
No functional change.
Bench: 2526370