]> git.sesse.net Git - stockfish/commitdiff
Movegen: further simplify generate_move_if_legal
authorMarco Costalba <mcostalba@gmail.com>
Fri, 17 Oct 2008 20:52:36 +0000 (22:52 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 18 Oct 2008 19:35:33 +0000 (21:35 +0200)
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/movegen.cpp

index a2e9c9c96578b850d9c7484be0c57d6d4b64219b..9474bb762f2505589ec14fafdc6a02ceac43efa1 100644 (file)
@@ -712,9 +712,8 @@ Move generate_move_if_legal(const Position &pos, Move m, Bitboard pinned) {
       return MOVE_NONE;
 
   // Proceed according to the type of the moving piece.
-  switch (type_of_piece(pc))
-  {
-  case PAWN:
+  if (type_of_piece(pc) == PAWN)
+  {  
       // If the destination square is on the 8/1th rank, the move must
       // be a promotion.
       if (   (  (square_rank(to) == RANK_8 && us == WHITE)
@@ -768,43 +767,12 @@ Move generate_move_if_legal(const Position &pos, Move m, Bitboard pinned) {
       }
       // The move is pseudo-legal.  Return it if it is legal.
       return (pos.move_is_legal(m) ? m : MOVE_NONE);
-      break;
+  }
 
-  case KNIGHT:
-      return (   pos.knight_attacks_square(from, to)
-              && pos.move_is_legal(m)
-              && !move_promotion(m) ? m : MOVE_NONE);
-      break;
-  
-  case BISHOP:
-      return (   pos.bishop_attacks_square(from, to)
-              && pos.move_is_legal(m)
-              && !move_promotion(m) ? m : MOVE_NONE);
-      break;
-  
-  case ROOK:
-      return (   pos.rook_attacks_square(from, to)
-              && pos.move_is_legal(m)
-              && !move_promotion(m) ? m : MOVE_NONE);
-      break;
-
-  case QUEEN:
-      return (   pos.queen_attacks_square(from, to)
-              && pos.move_is_legal(m)
-              && !move_promotion(m) ? m : MOVE_NONE);
-      break;
-
-  case KING:
-      return (   pos.king_attacks_square(from, to)
-              && pos.move_is_legal(m)
-              && !move_promotion(m) ? m : MOVE_NONE);
-      break;
-
-  default:
-      assert(false);
-    }
-  assert(false);
-  return MOVE_NONE;
+  // Luckly we can handle all the other pieces in one go
+  return (   pos.piece_attacks_square(from, to)
+          && pos.move_is_legal(m)
+          && !move_promotion(m) ? m : MOVE_NONE);
 }
 
 
@@ -1039,7 +1007,7 @@ namespace {
     return n;
   }
 
-  
+
   int generate_knight_moves(const Position &pos, MoveStack *mlist, 
                             Color side, Bitboard target) {
     Square from, to;