From b38e468429d08f26cb0e775fc32da8131cd7ec1f Mon Sep 17 00:00:00 2001 From: pjpuzzler <31143551+pjpuzzler@users.noreply.github.com> Date: Sat, 12 Aug 2023 14:19:01 -0400 Subject: [PATCH] Fixed generate_castling_moves to_mask bug --- chess/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/chess/__init__.py b/chess/__init__.py index 65719fd5c..3c357f578 100644 --- a/chess/__init__.py +++ b/chess/__init__.py @@ -3610,11 +3610,13 @@ def generate_castling_moves(self, from_mask: Bitboard = BB_ALL, to_mask: Bitboar bb_f = BB_FILE_F & backrank bb_g = BB_FILE_G & backrank - for candidate in scan_reversed(self.clean_castling_rights() & backrank & to_mask): + for candidate in scan_reversed(self.clean_castling_rights() & backrank): rook = BB_SQUARES[candidate] a_side = rook < king king_to = bb_c if a_side else bb_g + if not king_to & to_mask: + continue rook_to = bb_d if a_side else bb_f king_path = between(msb(king), msb(king_to))