From 6b9a70ace8073f5ff4c50b4dd5ddc041cf9c819f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Prokop=20Rand=C3=A1=C4=8Dek?= Date: Wed, 12 May 2021 20:15:21 +0200 Subject: [PATCH] Use if instead of goto 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 | 1 + src/movegen.cpp | 29 ++++++++++++++--------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/AUTHORS b/AUTHORS index 9042495f..7165363f 100644 --- 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 diff --git a/src/movegen.cpp b/src/movegen.cpp index be168450..bb81aeac 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -192,21 +192,20 @@ namespace { const Square ksq = pos.square(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(pos, moveList, target); - moveList = generate_moves(pos, moveList, target); - moveList = generate_moves(pos, moveList, target); - moveList = generate_moves(pos, moveList, target); - moveList = generate_moves(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(pos, moveList, target); + moveList = generate_moves(pos, moveList, target); + moveList = generate_moves(pos, moveList, target); + moveList = generate_moves(pos, moveList, target); + moveList = generate_moves(pos, moveList, target); + } if (!Checks || pos.blockers_for_king(~Us) & ksq) { Bitboard b = attacks_bb(ksq) & (Type == EVASIONS ? ~pos.pieces(Us) : target); -- 2.39.2