1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-02 01:29:36 +00:00

Triviality in move_gives_check()

It seems even a bit faster, although handling of the special
cases is not the hot path.

No functional change.
This commit is contained in:
Marco Costalba 2012-11-17 12:57:58 +01:00
parent 942989939a
commit 8367cf15da

View file

@ -688,15 +688,16 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
Color us = sideToMove; Color us = sideToMove;
Square ksq = king_square(~us); Square ksq = king_square(~us);
// Promotion with check ? switch (type_of(m))
if (type_of(m) == PROMOTION) {
case PROMOTION:
return attacks_from(Piece(promotion_type(m)), to, pieces() ^ from) & ksq; return attacks_from(Piece(promotion_type(m)), to, pieces() ^ from) & ksq;
// En passant capture with check ? We have already handled the case // En passant capture with check ? We have already handled the case
// of direct checks and ordinary discovered check, the only case we // of direct checks and ordinary discovered check, the only case we
// need to handle is the unusual case of a discovered check through // need to handle is the unusual case of a discovered check through
// the captured pawn. // the captured pawn.
if (type_of(m) == ENPASSANT) case ENPASSANT:
{ {
Square capsq = file_of(to) | rank_of(from); Square capsq = file_of(to) | rank_of(from);
Bitboard b = (pieces() ^ from ^ capsq) | to; Bitboard b = (pieces() ^ from ^ capsq) | to;
@ -704,9 +705,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
return (attacks_bb< ROOK>(ksq, b) & pieces(us, QUEEN, ROOK)) return (attacks_bb< ROOK>(ksq, b) & pieces(us, QUEEN, ROOK))
| (attacks_bb<BISHOP>(ksq, b) & pieces(us, QUEEN, BISHOP)); | (attacks_bb<BISHOP>(ksq, b) & pieces(us, QUEEN, BISHOP));
} }
case CASTLE:
// Castling with check ?
if (type_of(m) == CASTLE)
{ {
Square kfrom = from; Square kfrom = from;
Square rfrom = to; // 'King captures the rook' notation Square rfrom = to; // 'King captures the rook' notation
@ -716,8 +715,10 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
return attacks_bb<ROOK>(rto, b) & ksq; return attacks_bb<ROOK>(rto, b) & ksq;
} }
default:
return false; assert(false);
return false;
}
} }