Skip to content

Commit 262c380

Browse files
Henri Wiechersmcostalba
Henri Wiechers
authored andcommitted
Position::gives_check - use ci.ksq
Also remove a couple of local variables while there. No functional change.
1 parent 6a6fd0b commit 262c380

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/position.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -633,20 +633,17 @@ bool Position::gives_check(Move m, const CheckInfo& ci) const {
633633
// Is there a discovered check?
634634
if ( unlikely(ci.dcCandidates)
635635
&& (ci.dcCandidates & from)
636-
&& !aligned(from, to, king_square(~sideToMove)))
636+
&& !aligned(from, to, ci.ksq))
637637
return true;
638638

639639
// Can we skip the ugly special cases?
640640
if (type_of(m) == NORMAL)
641641
return false;
642642

643-
Color us = sideToMove;
644-
Square ksq = king_square(~us);
645-
646643
switch (type_of(m))
647644
{
648645
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;
650647

651648
// En passant capture with check? We have already handled the case
652649
// 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 {
657654
Square capsq = file_of(to) | rank_of(from);
658655
Bitboard b = (pieces() ^ from ^ capsq) | to;
659656

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));
662659
}
663660
case CASTLING:
664661
{
665662
Square kfrom = from;
666663
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);
669666

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);
672669
}
673670
default:
674671
assert(false);

0 commit comments

Comments
 (0)