]> git.sesse.net Git - stockfish/commitdiff
Triviality in move_gives_check()
authorMarco Costalba <mcostalba@gmail.com>
Sat, 17 Nov 2012 11:57:58 +0000 (12:57 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 17 Nov 2012 12:08:04 +0000 (13:08 +0100)
It seems even a bit faster, although handling of the special
cases is not the hot path.

No functional change.

src/position.cpp

index b2449a71956001ffc405aef33aa92da995d56bf7..a0d5730c4e75a427da26930aeed3df681d6e1f49 100644 (file)
@@ -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<BISHOP>(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<ROOK>(rto, b) & ksq;
   }
-
-  return false;
+  default:
+      assert(false);
+      return false;
+  }
 }