From 8367cf15da0bd8bb2cd7cc51ab4404ef6842be79 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 17 Nov 2012 12:57:58 +0100 Subject: [PATCH] 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. --- src/position.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index b2449a71..a0d5730c 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -688,15 +688,16 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const { Color us = sideToMove; Square ksq = king_square(~us); - // Promotion with check ? - if (type_of(m) == PROMOTION) + switch (type_of(m)) + { + case PROMOTION: return attacks_from(Piece(promotion_type(m)), to, pieces() ^ from) & ksq; // En passant capture with check ? We have already handled the case // of direct checks and ordinary discovered check, the only case we // need to handle is the unusual case of a discovered check through // the captured pawn. - if (type_of(m) == ENPASSANT) + case ENPASSANT: { Square capsq = file_of(to) | rank_of(from); 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)) | (attacks_bb(ksq, b) & pieces(us, QUEEN, BISHOP)); } - - // Castling with check ? - if (type_of(m) == CASTLE) + case CASTLE: { Square kfrom = from; 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(rto, b) & ksq; } - - return false; + default: + assert(false); + return false; + } } -- 2.39.2