This version fixes the logic of `gives_check`, which was identified to
be the cause of illegal moves.

closes https://github.com/official-stockfish/Stockfish/pull/5914

No functional change

Co-authored-by: Robert Nürnberg <robert.nurnberg@gmx.de>
Co-authored-by: gab8192 <gabrilomba57@gmail.com>
This commit is contained in:
Shawn Xu
2025-03-21 11:02:19 +01:00
committed by Disservin
co-authored by Robert Nürnberg gab8192
parent f3bfce3531
commit 99d32e395e
+3 -3
View File
@@ -560,7 +560,7 @@ bool Position::legal(Move m) const {
// A non-king move is legal if and only if it is not pinned or it // A non-king move is legal if and only if it is not pinned or it
// is moving along the ray towards or away from the king. // is moving along the ray towards or away from the king.
return !(blockers_for_king(us) & from) || aligned(from, to, square<KING>(us)); return !(blockers_for_king(us) & from) || line_bb(from, to) & pieces(us, KING);
} }
@@ -648,7 +648,7 @@ bool Position::gives_check(Move m) const {
// Is there a discovered check? // Is there a discovered check?
if (blockers_for_king(~sideToMove) & from) if (blockers_for_king(~sideToMove) & from)
return !aligned(from, to, square<KING>(~sideToMove)) || m.type_of() == CASTLING; return !(line_bb(from, to) & pieces(~sideToMove, KING)) || m.type_of() == CASTLING;
switch (m.type_of()) switch (m.type_of())
{ {
@@ -656,7 +656,7 @@ bool Position::gives_check(Move m) const {
return false; return false;
case PROMOTION : case PROMOTION :
return attacks_bb(m.promotion_type(), to, pieces() ^ from) & square<KING>(~sideToMove); return attacks_bb(m.promotion_type(), to, pieces() ^ from) & pieces(~sideToMove, KING);
// En passant capture with check? We have already handled the case of direct // En passant capture with check? We have already handled the case of direct
// checks and ordinary discovered check, so the only case we need to handle // checks and ordinary discovered check, so the only case we need to handle