]> git.sesse.net Git - stockfish/commitdiff
Remove Condition from Generate_Move Loop
authorbmc4 <bmc4@cin.ufpe.br>
Sun, 10 Jan 2021 06:30:40 +0000 (03:30 -0300)
committerJoost VandeVondele <Joost.VandeVondele@gmail.com>
Mon, 11 Jan 2021 17:41:47 +0000 (18:41 +0100)
it seems it's faster to handle blockers_for_king(~Us) outside loops

Passed STC:
LLR: 2.96 (-2.94,2.94) {-0.25,1.25}
Total: 22184 W: 2063 L: 1919 D: 18202
Ptnml(0-2): 63, 1485, 7855, 1623, 66
https://tests.stockfishchess.org/tests/view/5ffbee2f6019e097de3ef18d

closes https://github.com/official-stockfish/Stockfish/pull/3299

No functional change

AUTHORS
src/movegen.cpp

diff --git a/AUTHORS b/AUTHORS
index b31a36e9d625f5d61ca620b4c333c0de98cfa3d2..d170364e0167a25016a1a469ad617ae8d0e6235b 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -33,6 +33,7 @@ Bill Henry (VoyagerOne)
 Bojun Guo (noobpwnftw, Nooby)
 braich
 Brian Sheppard (SapphireBrand, briansheppard-toast)
 Bojun Guo (noobpwnftw, Nooby)
 braich
 Brian Sheppard (SapphireBrand, briansheppard-toast)
+Bruno de Melo Costa (BM123499)
 Bryan Cross (crossbr)
 candirufish
 Chess13234
 Bryan Cross (crossbr)
 candirufish
 Chess13234
index e017d8fe2c596c4fd2cee565fce2bfec972c9f54..855a203ec9dbdc3e729b5fd4a7954648c36f4755 100644 (file)
@@ -175,25 +175,19 @@ namespace {
   }
 
 
   }
 
 
-  template<Color Us, PieceType Pt, bool Checks>
-  ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Bitboard target) {
+  template<PieceType Pt, bool Checks>
+  ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Bitboard piecesToMove, Bitboard target) {
 
     static_assert(Pt != KING && Pt != PAWN, "Unsupported piece type in generate_moves()");
 
 
     static_assert(Pt != KING && Pt != PAWN, "Unsupported piece type in generate_moves()");
 
-    Bitboard bb = pos.pieces(Us, Pt);
+    Bitboard bb = piecesToMove & pos.pieces(Pt);
 
     while (bb) {
         Square from = pop_lsb(&bb);
 
 
     while (bb) {
         Square from = pop_lsb(&bb);
 
-        if (Checks)
-        {
-            if (    (Pt == BISHOP || Pt == ROOK || Pt == QUEEN)
-                && !(attacks_bb<Pt>(from) & target & pos.check_squares(Pt)))
-                continue;
-
-            if (pos.blockers_for_king(~Us) & from)
-                continue;
-        }
+        if (Checks && (Pt == BISHOP || Pt == ROOK || Pt == QUEEN)
+            && !(attacks_bb<Pt>(from) & target & pos.check_squares(Pt)))
+            continue;
 
         Bitboard b = attacks_bb<Pt>(from, pos.pieces()) & target;
 
 
         Bitboard b = attacks_bb<Pt>(from, pos.pieces()) & target;
 
@@ -211,7 +205,10 @@ namespace {
   template<Color Us, GenType Type>
   ExtMove* generate_all(const Position& pos, ExtMove* moveList) {
     constexpr bool Checks = Type == QUIET_CHECKS; // Reduce template instantations
   template<Color Us, GenType Type>
   ExtMove* generate_all(const Position& pos, ExtMove* moveList) {
     constexpr bool Checks = Type == QUIET_CHECKS; // Reduce template instantations
-    Bitboard target;
+    Bitboard target, piecesToMove = pos.pieces(Us);
+
+    if(Type == QUIET_CHECKS)
+        piecesToMove &= ~pos.blockers_for_king(~Us);
 
     switch (Type)
     {
 
     switch (Type)
     {
@@ -236,10 +233,10 @@ namespace {
     }
 
     moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
     }
 
     moveList = generate_pawn_moves<Us, Type>(pos, moveList, target);
-    moveList = generate_moves<Us, KNIGHT, Checks>(pos, moveList, target);
-    moveList = generate_moves<Us, BISHOP, Checks>(pos, moveList, target);
-    moveList = generate_moves<Us,   ROOK, Checks>(pos, moveList, target);
-    moveList = generate_moves<Us,  QUEEN, Checks>(pos, moveList, target);
+    moveList = generate_moves<KNIGHT, Checks>(pos, moveList, piecesToMove, target);
+    moveList = generate_moves<BISHOP, Checks>(pos, moveList, piecesToMove, target);
+    moveList = generate_moves<  ROOK, Checks>(pos, moveList, piecesToMove, target);
+    moveList = generate_moves< QUEEN, Checks>(pos, moveList, piecesToMove, target);
 
     if (Type != QUIET_CHECKS && Type != EVASIONS)
     {
 
     if (Type != QUIET_CHECKS && Type != EVASIONS)
     {