]> git.sesse.net Git - stockfish/commitdiff
Use if instead of goto
authorProkop Randáček <prokop@randacek.dev>
Wed, 12 May 2021 18:15:21 +0000 (20:15 +0200)
committerJoost VandeVondele <Joost.VandeVondele@gmail.com>
Wed, 19 May 2021 17:38:44 +0000 (19:38 +0200)
This PR inverts the if and removes goto in the generate_all function.

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

No functional change

AUTHORS
src/movegen.cpp

diff --git a/AUTHORS b/AUTHORS
index 9042495fdc0ea839e53b9a5e5eeda2db00329a5c..7165363f08e5705a915c595cddcafbd01af26d64 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -175,6 +175,7 @@ Stefan Geschwentner (locutus2)
 Stefano Cardanobile (Stefano80)
 Steinar Gunderson (sesse)
 Stéphane Nicolet (snicolet)
+Prokop Randáček (ProkopRandacek)
 Thanar2
 thaspel
 theo77186
index be16845095d43e04f317f33541f0b6a56761957a..bb81aeac07897655e155437b65506439b333f61a 100644 (file)
@@ -192,21 +192,20 @@ namespace {
     const Square ksq = pos.square<KING>(Us);
     Bitboard target;
 
-    if (Type == EVASIONS && more_than_one(pos.checkers()))
-        goto kingMoves; // Double check, only a king move can save the day
-
-    target = Type == EVASIONS     ?  between_bb(ksq, lsb(pos.checkers()))
-           : Type == NON_EVASIONS ? ~pos.pieces( Us)
-           : Type == CAPTURES     ?  pos.pieces(~Us)
-                                  : ~pos.pieces(   ); // QUIETS || QUIET_CHECKS
-
-    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);
-
-kingMoves:
+    // Skip generating non-king moves when in double check
+    if (Type != EVASIONS || !more_than_one(pos.checkers()))
+    {
+        target = Type == EVASIONS     ?  between_bb(ksq, lsb(pos.checkers()))
+               : Type == NON_EVASIONS ? ~pos.pieces( Us)
+               : Type == CAPTURES     ?  pos.pieces(~Us)
+                                      : ~pos.pieces(   ); // QUIETS || QUIET_CHECKS
+
+        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);
+    }
     if (!Checks || pos.blockers_for_king(~Us) & ksq)
     {
         Bitboard b = attacks_bb<KING>(ksq) & (Type == EVASIONS ? ~pos.pieces(Us) : target);