]> git.sesse.net Git - stockfish/blobdiff - src/movegen.cpp
Streamline generation of MV_NON_EVASION
[stockfish] / src / movegen.cpp
index 1082ad016aab60bbe60c7a782113b38920e7efb5..eb235b1df679320e4c49effd8669ce219dfd30bf 100644 (file)
@@ -101,8 +101,6 @@ namespace {
   FORCE_INLINE MoveStack* generate_piece_moves(const Position& p, MoveStack* m, Color us, Bitboard t) {
 
     assert(Pt == PAWN);
-    assert(Type == MV_CAPTURE || Type == MV_NON_CAPTURE || Type == MV_EVASION);
-
     return (us == WHITE ? generate_pawn_moves<WHITE, Type>(p, m, t, SQ_NONE)
                         : generate_pawn_moves<BLACK, Type>(p, m, t, SQ_NONE));
   }
@@ -151,27 +149,22 @@ namespace {
 template<MoveType Type>
 MoveStack* generate(const Position& pos, MoveStack* mlist) {
 
+  assert(Type == MV_CAPTURE || Type == MV_NON_CAPTURE || Type == MV_NON_EVASION);
   assert(!pos.in_check());
 
   Color us = pos.side_to_move();
   Bitboard target;
 
-  if (Type == MV_CAPTURE || Type == MV_NON_EVASION)
+  if (Type == MV_CAPTURE)
       target = pos.pieces(flip(us));
+
   else if (Type == MV_NON_CAPTURE)
       target = pos.empty_squares();
-  else
-      assert(false);
 
-  if (Type == MV_NON_EVASION)
-  {
-      mlist = generate_piece_moves<PAWN, MV_CAPTURE>(pos, mlist, us, target);
-      mlist = generate_piece_moves<PAWN, MV_NON_CAPTURE>(pos, mlist, us, pos.empty_squares());
-      target |= pos.empty_squares();
-  }
-  else
-      mlist = generate_piece_moves<PAWN, Type>(pos, mlist, us, target);
+  else if (Type == MV_NON_EVASION)
+      target = pos.pieces(flip(us)) | pos.empty_squares();
 
+  mlist = generate_piece_moves<PAWN, Type>(pos, mlist, us, target);
   mlist = generate_piece_moves<KNIGHT>(pos, mlist, us, target);
   mlist = generate_piece_moves<BISHOP>(pos, mlist, us, target);
   mlist = generate_piece_moves<ROOK>(pos, mlist, us, target);
@@ -339,7 +332,7 @@ namespace {
            Delta == DELTA_NW ? p << 7 : Delta == DELTA_SW ? p >> 9 : p;
   }
 
-  template<MoveType Type, Square Delta>
+  template<Square Delta>
   inline MoveStack* generate_pawn_captures(MoveStack* mlist, Bitboard pawns, Bitboard target) {
 
     const Bitboard TFileABB = (Delta == DELTA_NE || Delta == DELTA_SE ? FileABB : FileHBB);
@@ -371,10 +364,10 @@ namespace {
     {
         to = pop_1st_bit(&b);
 
-        if (Type == MV_CAPTURE || Type == MV_EVASION)
+        if (Type == MV_CAPTURE || Type == MV_EVASION || Type == MV_NON_EVASION)
             (*mlist++).move = make_promotion(to - Delta, to, QUEEN);
 
-        if (Type == MV_NON_CAPTURE || Type == MV_EVASION)
+        if (Type == MV_NON_CAPTURE || Type == MV_EVASION || Type == MV_NON_EVASION)
         {
             (*mlist++).move = make_promotion(to - Delta, to, ROOK);
             (*mlist++).move = make_promotion(to - Delta, to, BISHOP);
@@ -435,10 +428,10 @@ namespace {
     }
 
     // Standard captures
-    if (Type == MV_CAPTURE || Type == MV_EVASION)
+    if (Type == MV_CAPTURE || Type == MV_EVASION || Type == MV_NON_EVASION)
     {
-        mlist = generate_pawn_captures<Type, RIGHT_UP>(mlist, pawns, enemyPieces);
-        mlist = generate_pawn_captures<Type, LEFT_UP>(mlist, pawns, enemyPieces);
+        mlist = generate_pawn_captures<RIGHT_UP>(mlist, pawns, enemyPieces);
+        mlist = generate_pawn_captures<LEFT_UP>(mlist, pawns, enemyPieces);
     }
 
     // Single and double pawn pushes
@@ -470,7 +463,8 @@ namespace {
     }
 
     // En passant captures
-    if ((Type == MV_CAPTURE || Type == MV_EVASION) && pos.ep_square() != SQ_NONE)
+    if (  (Type == MV_CAPTURE || Type == MV_EVASION || Type == MV_NON_EVASION)
+        && pos.ep_square() != SQ_NONE)
     {
         assert(Us != WHITE || rank_of(pos.ep_square()) == RANK_6);
         assert(Us != BLACK || rank_of(pos.ep_square()) == RANK_3);