@@ -633,20 +633,17 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const {
633
633
// Is there a discovered check?
634
634
if ( unlikely (ci.dcCandidates )
635
635
&& (ci.dcCandidates & from)
636
- && !aligned (from, to, king_square (~sideToMove) ))
636
+ && !aligned (from, to, ci. ksq ))
637
637
return true ;
638
638
639
639
// Can we skip the ugly special cases?
640
640
if (type_of (m) == NORMAL)
641
641
return false ;
642
642
643
- Color us = sideToMove;
644
- Square ksq = king_square (~us);
645
-
646
643
switch (type_of (m))
647
644
{
648
645
case PROMOTION:
649
- return attacks_bb (Piece (promotion_type (m)), to, pieces () ^ from) & ksq;
646
+ return attacks_bb (Piece (promotion_type (m)), to, pieces () ^ from) & ci. ksq ;
650
647
651
648
// En passant capture with check? We have already handled the case
652
649
// of direct checks and ordinary discovered check, so the only case we
@@ -657,18 +654,18 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const {
657
654
Square capsq = file_of (to) | rank_of (from);
658
655
Bitboard b = (pieces () ^ from ^ capsq) | to;
659
656
660
- return (attacks_bb< ROOK>(ksq, b) & pieces (us , QUEEN, ROOK))
661
- | (attacks_bb<BISHOP>(ksq, b) & pieces (us , QUEEN, BISHOP));
657
+ return (attacks_bb< ROOK>(ci. ksq , b) & pieces (sideToMove , QUEEN, ROOK))
658
+ | (attacks_bb<BISHOP>(ci. ksq , b) & pieces (sideToMove , QUEEN, BISHOP));
662
659
}
663
660
case CASTLING:
664
661
{
665
662
Square kfrom = from;
666
663
Square rfrom = to; // Castling is encoded as 'King captures the rook'
667
- Square kto = relative_square (us , rfrom > kfrom ? SQ_G1 : SQ_C1);
668
- Square rto = relative_square (us , rfrom > kfrom ? SQ_F1 : SQ_D1);
664
+ Square kto = relative_square (sideToMove , rfrom > kfrom ? SQ_G1 : SQ_C1);
665
+ Square rto = relative_square (sideToMove , rfrom > kfrom ? SQ_F1 : SQ_D1);
669
666
670
- return (PseudoAttacks[ROOK][rto] & ksq)
671
- && (attacks_bb<ROOK>(rto, (pieces () ^ kfrom ^ rfrom) | rto | kto) & ksq);
667
+ return (PseudoAttacks[ROOK][rto] & ci. ksq )
668
+ && (attacks_bb<ROOK>(rto, (pieces () ^ kfrom ^ rfrom) | rto | kto) & ci. ksq );
672
669
}
673
670
default :
674
671
assert (false );
0 commit comments