2008-08-31 23:59:13 -06:00
|
|
|
/*
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
2021-01-08 09:04:23 -07:00
|
|
|
Copyright (C) 2004-2021 The Stockfish developers (see AUTHORS file)
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish is free software: you can redistribute it and/or modify
|
2008-08-31 23:59:13 -06:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2008-10-20 13:57:13 -06:00
|
|
|
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish is distributed in the hope that it will be useful,
|
2008-08-31 23:59:13 -06:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2008-10-20 13:57:13 -06:00
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-01-05 02:50:51 -07:00
|
|
|
#include <cassert>
|
2008-08-31 23:59:13 -06:00
|
|
|
|
|
|
|
#include "movegen.h"
|
2011-07-16 15:59:14 -06:00
|
|
|
#include "position.h"
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2021-02-26 02:02:13 -07:00
|
|
|
namespace Stockfish {
|
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
namespace {
|
2008-10-18 09:37:49 -06:00
|
|
|
|
2017-12-04 09:52:31 -07:00
|
|
|
template<GenType Type, Direction D>
|
Simplify promotion move generator
This patch removes Knight promotion checks from Captures. As a consequence,
it also removes this underpromotion from qsearch.
STC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 37776 W: 3113 L: 3023 D: 31640
Ptnml(0-2): 103, 2419, 13755, 2507, 104
https://tests.stockfishchess.org/tests/view/60be6a06457376eb8bcaa775
LTC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 39760 W: 1257 L: 1203 D: 37300
Ptnml(0-2): 11, 1079, 17646, 1133, 11
https://tests.stockfishchess.org/tests/view/60beb972457376eb8bcaa7c5
closes https://github.com/official-stockfish/Stockfish/pull/3536
Bench: 5530620
2021-06-07 12:47:37 -06:00
|
|
|
ExtMove* make_promotions(ExtMove* moveList, Square to) {
|
2012-01-04 06:10:53 -07:00
|
|
|
|
2014-12-24 03:36:04 -07:00
|
|
|
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
|
2016-09-23 11:28:34 -06:00
|
|
|
*moveList++ = make<PROMOTION>(to - D, to, QUEEN);
|
2012-01-04 06:10:53 -07:00
|
|
|
|
2014-12-24 03:36:04 -07:00
|
|
|
if (Type == QUIETS || Type == EVASIONS || Type == NON_EVASIONS)
|
2012-01-04 06:10:53 -07:00
|
|
|
{
|
2016-09-23 11:28:34 -06:00
|
|
|
*moveList++ = make<PROMOTION>(to - D, to, ROOK);
|
|
|
|
*moveList++ = make<PROMOTION>(to - D, to, BISHOP);
|
Simplify promotion move generator
This patch removes Knight promotion checks from Captures. As a consequence,
it also removes this underpromotion from qsearch.
STC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 37776 W: 3113 L: 3023 D: 31640
Ptnml(0-2): 103, 2419, 13755, 2507, 104
https://tests.stockfishchess.org/tests/view/60be6a06457376eb8bcaa775
LTC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 39760 W: 1257 L: 1203 D: 37300
Ptnml(0-2): 11, 1079, 17646, 1133, 11
https://tests.stockfishchess.org/tests/view/60beb972457376eb8bcaa7c5
closes https://github.com/official-stockfish/Stockfish/pull/3536
Bench: 5530620
2021-06-07 12:47:37 -06:00
|
|
|
*moveList++ = make<PROMOTION>(to - D, to, KNIGHT);
|
2012-01-04 06:10:53 -07:00
|
|
|
}
|
2012-01-14 15:01:09 -07:00
|
|
|
|
2015-09-27 02:53:39 -06:00
|
|
|
return moveList;
|
2012-01-04 06:10:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-24 03:08:16 -06:00
|
|
|
template<Color Us, GenType Type>
|
2016-07-03 02:35:44 -06:00
|
|
|
ExtMove* generate_pawn_moves(const Position& pos, ExtMove* moveList, Bitboard target) {
|
2012-01-04 06:10:53 -07:00
|
|
|
|
2020-03-30 14:45:35 -06:00
|
|
|
constexpr Color Them = ~Us;
|
2018-03-18 16:38:58 -06:00
|
|
|
constexpr Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB);
|
|
|
|
constexpr Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB);
|
2019-10-31 10:17:46 -06:00
|
|
|
constexpr Direction Up = pawn_push(Us);
|
2018-03-18 16:38:58 -06:00
|
|
|
constexpr Direction UpRight = (Us == WHITE ? NORTH_EAST : SOUTH_WEST);
|
|
|
|
constexpr Direction UpLeft = (Us == WHITE ? NORTH_WEST : SOUTH_EAST);
|
2012-01-04 06:10:53 -07:00
|
|
|
|
Simplify Declaration on Pawn Move Generation
Removes possible micro-optimization in favor of readability.
STC:
LLR: 2.95 (-2.94,2.94) <-2.50,0.50>
Total: 75432 W: 5824 L: 5777 D: 63831
Ptnml(0-2): 178, 4648, 28036, 4657, 197
https://tests.stockfishchess.org/tests/view/611fa7f84977aa1525c9cb75
LTC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 41200 W: 1156 L: 1106 D: 38938
Ptnml(0-2): 13, 981, 18562, 1031, 13
https://tests.stockfishchess.org/tests/view/611fcc694977aa1525c9cb9b
Closes https://github.com/official-stockfish/Stockfish/pull/3669
No functional change
2021-08-20 22:53:03 -06:00
|
|
|
const Bitboard emptySquares = ~pos.pieces();
|
|
|
|
const Bitboard enemies = Type == EVASIONS ? pos.checkers()
|
|
|
|
: pos.pieces(Them);
|
2012-01-04 06:10:53 -07:00
|
|
|
|
2012-05-01 05:01:38 -06:00
|
|
|
Bitboard pawnsOn7 = pos.pieces(Us, PAWN) & TRank7BB;
|
|
|
|
Bitboard pawnsNotOn7 = pos.pieces(Us, PAWN) & ~TRank7BB;
|
2012-01-04 06:10:53 -07:00
|
|
|
|
2012-01-04 08:40:12 -07:00
|
|
|
// Single and double pawn pushes, no promotions
|
2012-06-24 03:08:16 -06:00
|
|
|
if (Type != CAPTURES)
|
2012-01-04 06:10:53 -07:00
|
|
|
{
|
2016-09-23 11:28:34 -06:00
|
|
|
Bitboard b1 = shift<Up>(pawnsNotOn7) & emptySquares;
|
|
|
|
Bitboard b2 = shift<Up>(b1 & TRank3BB) & emptySquares;
|
2012-01-04 06:10:53 -07:00
|
|
|
|
2012-06-24 03:08:16 -06:00
|
|
|
if (Type == EVASIONS) // Consider only blocking squares
|
2012-01-04 08:40:12 -07:00
|
|
|
{
|
2012-01-05 02:50:51 -07:00
|
|
|
b1 &= target;
|
2012-01-04 08:40:12 -07:00
|
|
|
b2 &= target;
|
|
|
|
}
|
2012-01-04 06:10:53 -07:00
|
|
|
|
2012-06-24 03:08:16 -06:00
|
|
|
if (Type == QUIET_CHECKS)
|
2012-01-04 06:10:53 -07:00
|
|
|
{
|
Simplify pawn moves generator
This patch simplifies QUIET_CHECKS pawn move generator by merging discovery check
move generator with direct check move generator. It also simplifies emptySquares
instantiation. In addition, I added a comment in generate_moves() to clarify Check
branches.
STC:
LLR: 2.95 (-2.94,2.94) <-2.50,0.50>
Total: 112648 W: 9952 L: 9945 D: 92751
Ptnml(0-2): 369, 7682, 40195, 7729, 349
https://tests.stockfishchess.org/tests/view/6088226895e7f1852abd2978
LTC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 74656 W: 2797 L: 2765 D: 69094
Ptnml(0-2): 38, 2328, 32554, 2380, 28
https://tests.stockfishchess.org/tests/view/60884e5095e7f1852abd2994
closes https://github.com/official-stockfish/Stockfish/pull/3447
No functional change
2021-04-27 16:59:46 -06:00
|
|
|
// To make a quiet check, you either make a direct check by pushing a pawn
|
|
|
|
// or push a blocker pawn that is not on the same file as the enemy king.
|
|
|
|
// Discovered check promotion has been already generated amongst the captures.
|
Simplify promotion move generator
This patch removes Knight promotion checks from Captures. As a consequence,
it also removes this underpromotion from qsearch.
STC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 37776 W: 3113 L: 3023 D: 31640
Ptnml(0-2): 103, 2419, 13755, 2507, 104
https://tests.stockfishchess.org/tests/view/60be6a06457376eb8bcaa775
LTC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 39760 W: 1257 L: 1203 D: 37300
Ptnml(0-2): 11, 1079, 17646, 1133, 11
https://tests.stockfishchess.org/tests/view/60beb972457376eb8bcaa7c5
closes https://github.com/official-stockfish/Stockfish/pull/3536
Bench: 5530620
2021-06-07 12:47:37 -06:00
|
|
|
Square ksq = pos.square<KING>(Them);
|
Simplify pawn moves generator
This patch simplifies QUIET_CHECKS pawn move generator by merging discovery check
move generator with direct check move generator. It also simplifies emptySquares
instantiation. In addition, I added a comment in generate_moves() to clarify Check
branches.
STC:
LLR: 2.95 (-2.94,2.94) <-2.50,0.50>
Total: 112648 W: 9952 L: 9945 D: 92751
Ptnml(0-2): 369, 7682, 40195, 7729, 349
https://tests.stockfishchess.org/tests/view/6088226895e7f1852abd2978
LTC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 74656 W: 2797 L: 2765 D: 69094
Ptnml(0-2): 38, 2328, 32554, 2380, 28
https://tests.stockfishchess.org/tests/view/60884e5095e7f1852abd2994
closes https://github.com/official-stockfish/Stockfish/pull/3447
No functional change
2021-04-27 16:59:46 -06:00
|
|
|
Bitboard dcCandidatePawns = pos.blockers_for_king(Them) & ~file_bb(ksq);
|
|
|
|
b1 &= pawn_attacks_bb(Them, ksq) | shift< Up>(dcCandidatePawns);
|
|
|
|
b2 &= pawn_attacks_bb(Them, ksq) | shift<Up+Up>(dcCandidatePawns);
|
2012-01-04 06:10:53 -07:00
|
|
|
}
|
2012-01-04 08:40:12 -07:00
|
|
|
|
2014-03-09 04:03:02 -06:00
|
|
|
while (b1)
|
|
|
|
{
|
2021-03-13 09:40:07 -07:00
|
|
|
Square to = pop_lsb(b1);
|
2015-02-01 08:32:21 -07:00
|
|
|
*moveList++ = make_move(to - Up, to);
|
2014-03-09 04:03:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
while (b2)
|
|
|
|
{
|
2021-03-13 09:40:07 -07:00
|
|
|
Square to = pop_lsb(b2);
|
2015-02-01 08:32:21 -07:00
|
|
|
*moveList++ = make_move(to - Up - Up, to);
|
2014-03-09 04:03:02 -06:00
|
|
|
}
|
2012-01-04 06:10:53 -07:00
|
|
|
}
|
|
|
|
|
2012-01-04 08:40:12 -07:00
|
|
|
// Promotions and underpromotions
|
2019-01-01 05:35:53 -07:00
|
|
|
if (pawnsOn7)
|
2012-01-04 06:10:53 -07:00
|
|
|
{
|
2018-02-21 13:46:25 -07:00
|
|
|
Bitboard b1 = shift<UpRight>(pawnsOn7) & enemies;
|
|
|
|
Bitboard b2 = shift<UpLeft >(pawnsOn7) & enemies;
|
|
|
|
Bitboard b3 = shift<Up >(pawnsOn7) & emptySquares;
|
2014-12-24 03:36:04 -07:00
|
|
|
|
Simplify pawn moves generator
This patch simplifies QUIET_CHECKS pawn move generator by merging discovery check
move generator with direct check move generator. It also simplifies emptySquares
instantiation. In addition, I added a comment in generate_moves() to clarify Check
branches.
STC:
LLR: 2.95 (-2.94,2.94) <-2.50,0.50>
Total: 112648 W: 9952 L: 9945 D: 92751
Ptnml(0-2): 369, 7682, 40195, 7729, 349
https://tests.stockfishchess.org/tests/view/6088226895e7f1852abd2978
LTC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 74656 W: 2797 L: 2765 D: 69094
Ptnml(0-2): 38, 2328, 32554, 2380, 28
https://tests.stockfishchess.org/tests/view/60884e5095e7f1852abd2994
closes https://github.com/official-stockfish/Stockfish/pull/3447
No functional change
2021-04-27 16:59:46 -06:00
|
|
|
if (Type == EVASIONS)
|
|
|
|
b3 &= target;
|
|
|
|
|
2014-12-24 03:36:04 -07:00
|
|
|
while (b1)
|
Simplify promotion move generator
This patch removes Knight promotion checks from Captures. As a consequence,
it also removes this underpromotion from qsearch.
STC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 37776 W: 3113 L: 3023 D: 31640
Ptnml(0-2): 103, 2419, 13755, 2507, 104
https://tests.stockfishchess.org/tests/view/60be6a06457376eb8bcaa775
LTC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 39760 W: 1257 L: 1203 D: 37300
Ptnml(0-2): 11, 1079, 17646, 1133, 11
https://tests.stockfishchess.org/tests/view/60beb972457376eb8bcaa7c5
closes https://github.com/official-stockfish/Stockfish/pull/3536
Bench: 5530620
2021-06-07 12:47:37 -06:00
|
|
|
moveList = make_promotions<Type, UpRight>(moveList, pop_lsb(b1));
|
2014-12-24 03:36:04 -07:00
|
|
|
|
|
|
|
while (b2)
|
Simplify promotion move generator
This patch removes Knight promotion checks from Captures. As a consequence,
it also removes this underpromotion from qsearch.
STC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 37776 W: 3113 L: 3023 D: 31640
Ptnml(0-2): 103, 2419, 13755, 2507, 104
https://tests.stockfishchess.org/tests/view/60be6a06457376eb8bcaa775
LTC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 39760 W: 1257 L: 1203 D: 37300
Ptnml(0-2): 11, 1079, 17646, 1133, 11
https://tests.stockfishchess.org/tests/view/60beb972457376eb8bcaa7c5
closes https://github.com/official-stockfish/Stockfish/pull/3536
Bench: 5530620
2021-06-07 12:47:37 -06:00
|
|
|
moveList = make_promotions<Type, UpLeft >(moveList, pop_lsb(b2));
|
2014-12-24 03:36:04 -07:00
|
|
|
|
|
|
|
while (b3)
|
Simplify promotion move generator
This patch removes Knight promotion checks from Captures. As a consequence,
it also removes this underpromotion from qsearch.
STC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 37776 W: 3113 L: 3023 D: 31640
Ptnml(0-2): 103, 2419, 13755, 2507, 104
https://tests.stockfishchess.org/tests/view/60be6a06457376eb8bcaa775
LTC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 39760 W: 1257 L: 1203 D: 37300
Ptnml(0-2): 11, 1079, 17646, 1133, 11
https://tests.stockfishchess.org/tests/view/60beb972457376eb8bcaa7c5
closes https://github.com/official-stockfish/Stockfish/pull/3536
Bench: 5530620
2021-06-07 12:47:37 -06:00
|
|
|
moveList = make_promotions<Type, Up >(moveList, pop_lsb(b3));
|
2012-01-04 08:40:12 -07:00
|
|
|
}
|
2012-01-04 06:10:53 -07:00
|
|
|
|
2021-01-09 08:46:06 -07:00
|
|
|
// Standard and en passant captures
|
2012-06-24 03:08:16 -06:00
|
|
|
if (Type == CAPTURES || Type == EVASIONS || Type == NON_EVASIONS)
|
2012-01-04 08:40:12 -07:00
|
|
|
{
|
2018-02-21 13:46:25 -07:00
|
|
|
Bitboard b1 = shift<UpRight>(pawnsNotOn7) & enemies;
|
|
|
|
Bitboard b2 = shift<UpLeft >(pawnsNotOn7) & enemies;
|
2012-01-17 13:31:49 -07:00
|
|
|
|
2014-03-09 04:03:02 -06:00
|
|
|
while (b1)
|
|
|
|
{
|
2021-03-13 09:40:07 -07:00
|
|
|
Square to = pop_lsb(b1);
|
2018-02-21 13:46:25 -07:00
|
|
|
*moveList++ = make_move(to - UpRight, to);
|
2014-03-09 04:03:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
while (b2)
|
|
|
|
{
|
2021-03-13 09:40:07 -07:00
|
|
|
Square to = pop_lsb(b2);
|
2018-02-21 13:46:25 -07:00
|
|
|
*moveList++ = make_move(to - UpLeft, to);
|
2014-03-09 04:03:02 -06:00
|
|
|
}
|
2012-01-04 06:10:53 -07:00
|
|
|
|
2012-01-04 08:40:12 -07:00
|
|
|
if (pos.ep_square() != SQ_NONE)
|
2012-01-04 06:10:53 -07:00
|
|
|
{
|
2012-01-17 13:31:49 -07:00
|
|
|
assert(rank_of(pos.ep_square()) == relative_rank(Us, RANK_6));
|
2012-01-04 08:40:12 -07:00
|
|
|
|
Change definition of between_bb()
We remark that in current master, most of our use cases for between_bb() can be
optimized if the second parameter of the function is added to the segment. So we
change the definition of between_bb(s1, s2) such that it excludes s1 but includes s2.
We also use a precomputed array for between_bb() for another small speed gain
(see https://tests.stockfishchess.org/tests/view/604d09f72433018de7a389fb).
Passed STC:
LLR: 2.96 (-2.94,2.94) {-0.25,1.25}
Total: 18736 W: 1746 L: 1607 D: 15383
Ptnml(0-2): 61, 1226, 6644, 1387, 50
https://tests.stockfishchess.org/tests/view/60428c84ddcba5f0627bb6e4
Yellow LTC:
LTC:
LLR: -3.00 (-2.94,2.94) {0.25,1.25}
Total: 39144 W: 1431 L: 1413 D: 36300
Ptnml(0-2): 13, 1176, 17184, 1178, 21
https://tests.stockfishchess.org/tests/view/605128702433018de7a38ca1
Closes https://github.com/official-stockfish/Stockfish/pull/3397
---------
Verified for correctness by running perft on the following position:
./stockfish
position fen 4rrk1/1p1nq3/p7/2p1P1pp/3P2bp/3Q1Bn1/PPPB4/1K2R1NR w - - 40 21
go perft 6
Nodes searched: 6136386434
--------
No functional change
2021-03-15 13:06:42 -06:00
|
|
|
// An en passant capture cannot resolve a discovered check
|
2021-01-08 10:03:26 -07:00
|
|
|
if (Type == EVASIONS && (target & (pos.ep_square() + Up)))
|
2014-12-07 16:53:33 -07:00
|
|
|
return moveList;
|
2012-01-04 08:40:12 -07:00
|
|
|
|
2020-05-28 09:48:31 -06:00
|
|
|
b1 = pawnsNotOn7 & pawn_attacks_bb(Them, pos.ep_square());
|
2012-01-04 08:40:12 -07:00
|
|
|
|
|
|
|
assert(b1);
|
|
|
|
|
|
|
|
while (b1)
|
2021-03-13 09:40:07 -07:00
|
|
|
*moveList++ = make<EN_PASSANT>(pop_lsb(b1), pos.ep_square());
|
2012-01-04 06:10:53 -07:00
|
|
|
}
|
|
|
|
}
|
2012-01-04 08:40:12 -07:00
|
|
|
|
2014-12-07 16:53:33 -07:00
|
|
|
return moveList;
|
2012-01-04 06:10:53 -07:00
|
|
|
}
|
2009-02-10 09:31:07 -07:00
|
|
|
|
2009-02-10 09:44:55 -07:00
|
|
|
|
Merge all move generators
Merging `generate<EVASIONS>` and `generate<QUIET_CHECKS>` into `generate_all()`.
verified to yield correct perft results, even though bench changes due to different order of generated moves.
No regresion playing games:
passed STC:
LLR: 2.94 (-2.94,2.94) {-1.00,0.20}
Total: 161800 W: 14585 L: 14624 D: 132591
Ptnml(0-2): 577, 11681, 56451, 11586, 605
https://tests.stockfishchess.org/tests/view/606532732b2df919fd5f026d
passed LTC:
LLR: 2.98 (-2.94,2.94) {-0.70,0.20}
Total: 188504 W: 6906 L: 6961 D: 174637
Ptnml(0-2): 87, 6272, 81610, 6175, 108
https://tests.stockfishchess.org/tests/view/6065b0772b2df919fd5f02ae
closes https://github.com/official-stockfish/Stockfish/pull/3418
Bench: 4536129
2021-04-22 11:07:37 -06:00
|
|
|
template<Color Us, PieceType Pt, bool Checks>
|
|
|
|
ExtMove* generate_moves(const Position& pos, ExtMove* moveList, Bitboard target) {
|
2012-08-22 03:13:09 -06:00
|
|
|
|
2019-10-18 18:20:38 -06:00
|
|
|
static_assert(Pt != KING && Pt != PAWN, "Unsupported piece type in generate_moves()");
|
2011-01-05 01:49:58 -07:00
|
|
|
|
Merge all move generators
Merging `generate<EVASIONS>` and `generate<QUIET_CHECKS>` into `generate_all()`.
verified to yield correct perft results, even though bench changes due to different order of generated moves.
No regresion playing games:
passed STC:
LLR: 2.94 (-2.94,2.94) {-1.00,0.20}
Total: 161800 W: 14585 L: 14624 D: 132591
Ptnml(0-2): 577, 11681, 56451, 11586, 605
https://tests.stockfishchess.org/tests/view/606532732b2df919fd5f026d
passed LTC:
LLR: 2.98 (-2.94,2.94) {-0.70,0.20}
Total: 188504 W: 6906 L: 6961 D: 174637
Ptnml(0-2): 87, 6272, 81610, 6175, 108
https://tests.stockfishchess.org/tests/view/6065b0772b2df919fd5f02ae
closes https://github.com/official-stockfish/Stockfish/pull/3418
Bench: 4536129
2021-04-22 11:07:37 -06:00
|
|
|
Bitboard bb = pos.pieces(Us, Pt);
|
Remove piece lists
This patch removes the incrementally updated piece lists from the Position object.
This has been tried before but always failed. My reasons for trying again are:
* 32-bit systems (including phones) are now much less important than they were some years ago (and are absent from fishtest);
* NNUE may have made SF less finely tuned to the order in which moves were generated.
STC:
LLR: 2.94 (-2.94,2.94) {-1.25,0.25}
Total: 55272 W: 5260 L: 5216 D: 44796
Ptnml(0-2): 208, 4147, 18898, 4159, 224
https://tests.stockfishchess.org/tests/view/5fc2986a42a050a89f02c926
LTC:
LLR: 2.96 (-2.94,2.94) {-0.75,0.25}
Total: 16600 W: 673 L: 608 D: 15319
Ptnml(0-2): 14, 533, 7138, 604, 11
https://tests.stockfishchess.org/tests/view/5fc2f98342a050a89f02c95c
closes https://github.com/official-stockfish/Stockfish/pull/3247
Bench: 3940967
2020-11-29 04:05:26 -07:00
|
|
|
|
2021-03-19 12:43:25 -06:00
|
|
|
while (bb)
|
|
|
|
{
|
2021-03-13 09:40:07 -07:00
|
|
|
Square from = pop_lsb(bb);
|
2020-05-28 09:48:31 -06:00
|
|
|
Bitboard b = attacks_bb<Pt>(from, pos.pieces()) & target;
|
Simplify pawn moves generator
This patch simplifies QUIET_CHECKS pawn move generator by merging discovery check
move generator with direct check move generator. It also simplifies emptySquares
instantiation. In addition, I added a comment in generate_moves() to clarify Check
branches.
STC:
LLR: 2.95 (-2.94,2.94) <-2.50,0.50>
Total: 112648 W: 9952 L: 9945 D: 92751
Ptnml(0-2): 369, 7682, 40195, 7729, 349
https://tests.stockfishchess.org/tests/view/6088226895e7f1852abd2978
LTC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 74656 W: 2797 L: 2765 D: 69094
Ptnml(0-2): 38, 2328, 32554, 2380, 28
https://tests.stockfishchess.org/tests/view/60884e5095e7f1852abd2994
closes https://github.com/official-stockfish/Stockfish/pull/3447
No functional change
2021-04-27 16:59:46 -06:00
|
|
|
|
|
|
|
// To check, you either move freely a blocker or make a direct check.
|
Merge all move generators
Merging `generate<EVASIONS>` and `generate<QUIET_CHECKS>` into `generate_all()`.
verified to yield correct perft results, even though bench changes due to different order of generated moves.
No regresion playing games:
passed STC:
LLR: 2.94 (-2.94,2.94) {-1.00,0.20}
Total: 161800 W: 14585 L: 14624 D: 132591
Ptnml(0-2): 577, 11681, 56451, 11586, 605
https://tests.stockfishchess.org/tests/view/606532732b2df919fd5f026d
passed LTC:
LLR: 2.98 (-2.94,2.94) {-0.70,0.20}
Total: 188504 W: 6906 L: 6961 D: 174637
Ptnml(0-2): 87, 6272, 81610, 6175, 108
https://tests.stockfishchess.org/tests/view/6065b0772b2df919fd5f02ae
closes https://github.com/official-stockfish/Stockfish/pull/3418
Bench: 4536129
2021-04-22 11:07:37 -06:00
|
|
|
if (Checks && (Pt == QUEEN || !(pos.blockers_for_king(~Us) & from)))
|
Simplify move generation (1/2)
STC:
LLR: 2.95 (-2.94,2.94) {-1.25,0.25}
Total: 29792 W: 2611 L: 2545 D: 24636
Ptnml(0-2): 94, 1982, 10659, 2086, 75
https://tests.stockfishchess.org/tests/view/604fe5b62433018de7a38ba8
LTC:
LLR: 2.92 (-2.94,2.94) {-0.75,0.25}
Total: 22040 W: 826 L: 777 D: 20437
Ptnml(0-2): 8, 646, 9664, 693, 9
https://tests.stockfishchess.org/tests/view/604fec892433018de7a38bac
Closes https://github.com/official-stockfish/Stockfish/pull/3399
No functional change
2021-03-15 16:52:45 -06:00
|
|
|
b &= pos.check_squares(Pt);
|
2012-01-04 06:10:53 -07:00
|
|
|
|
2014-03-09 04:03:02 -06:00
|
|
|
while (b)
|
2021-03-13 09:40:07 -07:00
|
|
|
*moveList++ = make_move(from, pop_lsb(b));
|
2012-08-22 01:29:49 -06:00
|
|
|
}
|
2012-01-14 15:01:09 -07:00
|
|
|
|
2014-12-07 16:53:33 -07:00
|
|
|
return moveList;
|
2011-01-05 01:49:58 -07:00
|
|
|
}
|
2009-09-23 04:29:10 -06:00
|
|
|
|
2012-09-09 06:30:22 -06:00
|
|
|
|
Retire FORCE_INLINE
No speed regression on my machine (i7-3770k, gcc 4.9.1, linux 3.16):
stat test master diff
mean 2,482,415 2,474,987 7,906
stdev 4,603 5,644 2,497
speedup 0.32%
P(speedup>0) 100.0%
Fishtest 9+0.03:
ELO: 0.26 +-1.8 (95%) LOS: 61.2%
Total: 60000 W: 12437 L: 12392 D: 35171
No functional change.
Resolves #334
2015-04-15 14:21:45 -06:00
|
|
|
template<Color Us, GenType Type>
|
2020-05-23 05:26:13 -06:00
|
|
|
ExtMove* generate_all(const Position& pos, ExtMove* moveList) {
|
2021-01-10 04:22:52 -07:00
|
|
|
|
|
|
|
static_assert(Type != LEGAL, "Unsupported type in generate_all()");
|
|
|
|
|
2021-01-12 06:59:51 -07:00
|
|
|
constexpr bool Checks = Type == QUIET_CHECKS; // Reduce template instantiations
|
Merge all move generators
Merging `generate<EVASIONS>` and `generate<QUIET_CHECKS>` into `generate_all()`.
verified to yield correct perft results, even though bench changes due to different order of generated moves.
No regresion playing games:
passed STC:
LLR: 2.94 (-2.94,2.94) {-1.00,0.20}
Total: 161800 W: 14585 L: 14624 D: 132591
Ptnml(0-2): 577, 11681, 56451, 11586, 605
https://tests.stockfishchess.org/tests/view/606532732b2df919fd5f026d
passed LTC:
LLR: 2.98 (-2.94,2.94) {-0.70,0.20}
Total: 188504 W: 6906 L: 6961 D: 174637
Ptnml(0-2): 87, 6272, 81610, 6175, 108
https://tests.stockfishchess.org/tests/view/6065b0772b2df919fd5f02ae
closes https://github.com/official-stockfish/Stockfish/pull/3418
Bench: 4536129
2021-04-22 11:07:37 -06:00
|
|
|
const Square ksq = pos.square<KING>(Us);
|
|
|
|
Bitboard target;
|
2021-04-15 03:18:38 -06:00
|
|
|
|
2021-05-12 12:15:21 -06:00
|
|
|
// 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);
|
|
|
|
}
|
Simplify promotion move generator
This patch removes Knight promotion checks from Captures. As a consequence,
it also removes this underpromotion from qsearch.
STC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 37776 W: 3113 L: 3023 D: 31640
Ptnml(0-2): 103, 2419, 13755, 2507, 104
https://tests.stockfishchess.org/tests/view/60be6a06457376eb8bcaa775
LTC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 39760 W: 1257 L: 1203 D: 37300
Ptnml(0-2): 11, 1079, 17646, 1133, 11
https://tests.stockfishchess.org/tests/view/60beb972457376eb8bcaa7c5
closes https://github.com/official-stockfish/Stockfish/pull/3536
Bench: 5530620
2021-06-07 12:47:37 -06:00
|
|
|
|
Merge all move generators
Merging `generate<EVASIONS>` and `generate<QUIET_CHECKS>` into `generate_all()`.
verified to yield correct perft results, even though bench changes due to different order of generated moves.
No regresion playing games:
passed STC:
LLR: 2.94 (-2.94,2.94) {-1.00,0.20}
Total: 161800 W: 14585 L: 14624 D: 132591
Ptnml(0-2): 577, 11681, 56451, 11586, 605
https://tests.stockfishchess.org/tests/view/606532732b2df919fd5f026d
passed LTC:
LLR: 2.98 (-2.94,2.94) {-0.70,0.20}
Total: 188504 W: 6906 L: 6961 D: 174637
Ptnml(0-2): 87, 6272, 81610, 6175, 108
https://tests.stockfishchess.org/tests/view/6065b0772b2df919fd5f02ae
closes https://github.com/official-stockfish/Stockfish/pull/3418
Bench: 4536129
2021-04-22 11:07:37 -06:00
|
|
|
if (!Checks || pos.blockers_for_king(~Us) & ksq)
|
2013-01-26 14:07:28 -07:00
|
|
|
{
|
Merge all move generators
Merging `generate<EVASIONS>` and `generate<QUIET_CHECKS>` into `generate_all()`.
verified to yield correct perft results, even though bench changes due to different order of generated moves.
No regresion playing games:
passed STC:
LLR: 2.94 (-2.94,2.94) {-1.00,0.20}
Total: 161800 W: 14585 L: 14624 D: 132591
Ptnml(0-2): 577, 11681, 56451, 11586, 605
https://tests.stockfishchess.org/tests/view/606532732b2df919fd5f026d
passed LTC:
LLR: 2.98 (-2.94,2.94) {-0.70,0.20}
Total: 188504 W: 6906 L: 6961 D: 174637
Ptnml(0-2): 87, 6272, 81610, 6175, 108
https://tests.stockfishchess.org/tests/view/6065b0772b2df919fd5f02ae
closes https://github.com/official-stockfish/Stockfish/pull/3418
Bench: 4536129
2021-04-22 11:07:37 -06:00
|
|
|
Bitboard b = attacks_bb<KING>(ksq) & (Type == EVASIONS ? ~pos.pieces(Us) : target);
|
|
|
|
if (Checks)
|
|
|
|
b &= ~attacks_bb<QUEEN>(pos.square<KING>(~Us));
|
|
|
|
|
2014-03-09 04:03:02 -06:00
|
|
|
while (b)
|
2021-03-13 09:40:07 -07:00
|
|
|
*moveList++ = make_move(ksq, pop_lsb(b));
|
2012-09-09 06:30:22 -06:00
|
|
|
|
Merge all move generators
Merging `generate<EVASIONS>` and `generate<QUIET_CHECKS>` into `generate_all()`.
verified to yield correct perft results, even though bench changes due to different order of generated moves.
No regresion playing games:
passed STC:
LLR: 2.94 (-2.94,2.94) {-1.00,0.20}
Total: 161800 W: 14585 L: 14624 D: 132591
Ptnml(0-2): 577, 11681, 56451, 11586, 605
https://tests.stockfishchess.org/tests/view/606532732b2df919fd5f026d
passed LTC:
LLR: 2.98 (-2.94,2.94) {-0.70,0.20}
Total: 188504 W: 6906 L: 6961 D: 174637
Ptnml(0-2): 87, 6272, 81610, 6175, 108
https://tests.stockfishchess.org/tests/view/6065b0772b2df919fd5f02ae
closes https://github.com/official-stockfish/Stockfish/pull/3418
Bench: 4536129
2021-04-22 11:07:37 -06:00
|
|
|
if ((Type == QUIETS || Type == NON_EVASIONS) && pos.can_castle(Us & ANY_CASTLING))
|
2020-07-11 08:59:33 -06:00
|
|
|
for (CastlingRights cr : { Us & KING_SIDE, Us & QUEEN_SIDE } )
|
2020-03-11 16:27:51 -06:00
|
|
|
if (!pos.castling_impeded(cr) && pos.can_castle(cr))
|
|
|
|
*moveList++ = make<CASTLING>(ksq, pos.castling_rook_square(cr));
|
2012-09-09 06:30:22 -06:00
|
|
|
}
|
|
|
|
|
2014-12-07 16:53:33 -07:00
|
|
|
return moveList;
|
2012-09-09 06:30:22 -06:00
|
|
|
}
|
|
|
|
|
2012-01-04 06:10:53 -07:00
|
|
|
} // namespace
|
2008-08-31 23:59:13 -06:00
|
|
|
|
|
|
|
|
Simplify promotion move generator
This patch removes Knight promotion checks from Captures. As a consequence,
it also removes this underpromotion from qsearch.
STC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 37776 W: 3113 L: 3023 D: 31640
Ptnml(0-2): 103, 2419, 13755, 2507, 104
https://tests.stockfishchess.org/tests/view/60be6a06457376eb8bcaa775
LTC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 39760 W: 1257 L: 1203 D: 37300
Ptnml(0-2): 11, 1079, 17646, 1133, 11
https://tests.stockfishchess.org/tests/view/60beb972457376eb8bcaa7c5
closes https://github.com/official-stockfish/Stockfish/pull/3536
Bench: 5530620
2021-06-07 12:47:37 -06:00
|
|
|
/// <CAPTURES> Generates all pseudo-legal captures plus queen promotions
|
|
|
|
/// <QUIETS> Generates all pseudo-legal non-captures and underpromotions
|
Merge all move generators
Merging `generate<EVASIONS>` and `generate<QUIET_CHECKS>` into `generate_all()`.
verified to yield correct perft results, even though bench changes due to different order of generated moves.
No regresion playing games:
passed STC:
LLR: 2.94 (-2.94,2.94) {-1.00,0.20}
Total: 161800 W: 14585 L: 14624 D: 132591
Ptnml(0-2): 577, 11681, 56451, 11586, 605
https://tests.stockfishchess.org/tests/view/606532732b2df919fd5f026d
passed LTC:
LLR: 2.98 (-2.94,2.94) {-0.70,0.20}
Total: 188504 W: 6906 L: 6961 D: 174637
Ptnml(0-2): 87, 6272, 81610, 6175, 108
https://tests.stockfishchess.org/tests/view/6065b0772b2df919fd5f02ae
closes https://github.com/official-stockfish/Stockfish/pull/3418
Bench: 4536129
2021-04-22 11:07:37 -06:00
|
|
|
/// <EVASIONS> Generates all pseudo-legal check evasions when the side to move is in check
|
Simplify promotion move generator
This patch removes Knight promotion checks from Captures. As a consequence,
it also removes this underpromotion from qsearch.
STC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 37776 W: 3113 L: 3023 D: 31640
Ptnml(0-2): 103, 2419, 13755, 2507, 104
https://tests.stockfishchess.org/tests/view/60be6a06457376eb8bcaa775
LTC:
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 39760 W: 1257 L: 1203 D: 37300
Ptnml(0-2): 11, 1079, 17646, 1133, 11
https://tests.stockfishchess.org/tests/view/60beb972457376eb8bcaa7c5
closes https://github.com/official-stockfish/Stockfish/pull/3536
Bench: 5530620
2021-06-07 12:47:37 -06:00
|
|
|
/// <QUIET_CHECKS> Generates all pseudo-legal non-captures giving check, except castling and promotions
|
2019-02-08 02:36:03 -07:00
|
|
|
/// <NON_EVASIONS> Generates all pseudo-legal captures and non-captures
|
2011-01-05 11:47:01 -07:00
|
|
|
///
|
2019-02-08 02:36:03 -07:00
|
|
|
/// Returns a pointer to the end of the move list.
|
2011-01-05 11:47:01 -07:00
|
|
|
|
2012-06-24 03:08:16 -06:00
|
|
|
template<GenType Type>
|
2014-12-07 16:53:33 -07:00
|
|
|
ExtMove* generate(const Position& pos, ExtMove* moveList) {
|
2010-08-06 05:01:21 -06:00
|
|
|
|
Merge all move generators
Merging `generate<EVASIONS>` and `generate<QUIET_CHECKS>` into `generate_all()`.
verified to yield correct perft results, even though bench changes due to different order of generated moves.
No regresion playing games:
passed STC:
LLR: 2.94 (-2.94,2.94) {-1.00,0.20}
Total: 161800 W: 14585 L: 14624 D: 132591
Ptnml(0-2): 577, 11681, 56451, 11586, 605
https://tests.stockfishchess.org/tests/view/606532732b2df919fd5f026d
passed LTC:
LLR: 2.98 (-2.94,2.94) {-0.70,0.20}
Total: 188504 W: 6906 L: 6961 D: 174637
Ptnml(0-2): 87, 6272, 81610, 6175, 108
https://tests.stockfishchess.org/tests/view/6065b0772b2df919fd5f02ae
closes https://github.com/official-stockfish/Stockfish/pull/3418
Bench: 4536129
2021-04-22 11:07:37 -06:00
|
|
|
static_assert(Type != LEGAL, "Unsupported type in generate()");
|
|
|
|
assert((Type == EVASIONS) == (bool)pos.checkers());
|
2010-08-06 05:01:21 -06:00
|
|
|
|
|
|
|
Color us = pos.side_to_move();
|
2012-01-03 07:16:01 -07:00
|
|
|
|
2020-05-23 05:26:13 -06:00
|
|
|
return us == WHITE ? generate_all<WHITE, Type>(pos, moveList)
|
|
|
|
: generate_all<BLACK, Type>(pos, moveList);
|
2010-08-06 05:01:21 -06:00
|
|
|
}
|
|
|
|
|
2011-04-13 03:54:41 -06:00
|
|
|
// Explicit template instantiations
|
2013-07-19 02:27:15 -06:00
|
|
|
template ExtMove* generate<CAPTURES>(const Position&, ExtMove*);
|
|
|
|
template ExtMove* generate<QUIETS>(const Position&, ExtMove*);
|
Merge all move generators
Merging `generate<EVASIONS>` and `generate<QUIET_CHECKS>` into `generate_all()`.
verified to yield correct perft results, even though bench changes due to different order of generated moves.
No regresion playing games:
passed STC:
LLR: 2.94 (-2.94,2.94) {-1.00,0.20}
Total: 161800 W: 14585 L: 14624 D: 132591
Ptnml(0-2): 577, 11681, 56451, 11586, 605
https://tests.stockfishchess.org/tests/view/606532732b2df919fd5f026d
passed LTC:
LLR: 2.98 (-2.94,2.94) {-0.70,0.20}
Total: 188504 W: 6906 L: 6961 D: 174637
Ptnml(0-2): 87, 6272, 81610, 6175, 108
https://tests.stockfishchess.org/tests/view/6065b0772b2df919fd5f02ae
closes https://github.com/official-stockfish/Stockfish/pull/3418
Bench: 4536129
2021-04-22 11:07:37 -06:00
|
|
|
template ExtMove* generate<EVASIONS>(const Position&, ExtMove*);
|
|
|
|
template ExtMove* generate<QUIET_CHECKS>(const Position&, ExtMove*);
|
2013-07-19 02:27:15 -06:00
|
|
|
template ExtMove* generate<NON_EVASIONS>(const Position&, ExtMove*);
|
2011-01-05 11:47:01 -07:00
|
|
|
|
2010-08-06 05:01:21 -06:00
|
|
|
|
2012-06-24 03:08:16 -06:00
|
|
|
/// generate<LEGAL> generates all the legal moves in the given position
|
2011-01-05 11:47:01 -07:00
|
|
|
|
|
|
|
template<>
|
2014-12-07 16:53:33 -07:00
|
|
|
ExtMove* generate<LEGAL>(const Position& pos, ExtMove* moveList) {
|
2008-10-17 07:11:19 -06:00
|
|
|
|
2018-02-26 17:18:33 -07:00
|
|
|
Color us = pos.side_to_move();
|
|
|
|
Bitboard pinned = pos.blockers_for_king(us) & pos.pieces(us);
|
|
|
|
Square ksq = pos.square<KING>(us);
|
2014-12-24 03:36:04 -07:00
|
|
|
ExtMove* cur = moveList;
|
2009-03-02 08:20:00 -07:00
|
|
|
|
2014-12-24 03:36:04 -07:00
|
|
|
moveList = pos.checkers() ? generate<EVASIONS >(pos, moveList)
|
|
|
|
: generate<NON_EVASIONS>(pos, moveList);
|
|
|
|
while (cur != moveList)
|
2021-01-19 05:21:59 -07:00
|
|
|
if ( ((pinned && pinned & from_sq(*cur)) || from_sq(*cur) == ksq || type_of(*cur) == EN_PASSANT)
|
2016-07-03 02:35:44 -06:00
|
|
|
&& !pos.legal(*cur))
|
2015-02-01 08:32:21 -07:00
|
|
|
*cur = (--moveList)->move;
|
2011-04-13 03:54:41 -06:00
|
|
|
else
|
2013-10-02 22:01:38 -06:00
|
|
|
++cur;
|
2009-11-06 06:33:34 -07:00
|
|
|
|
2014-12-24 03:36:04 -07:00
|
|
|
return moveList;
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
2021-02-26 02:02:13 -07:00
|
|
|
|
|
|
|
} // namespace Stockfish
|