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-25 08:28:24 -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-25 08:28:24 -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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#include "movepick.h"
|
|
|
|
|
2021-02-26 02:02:13 -07:00
|
|
|
namespace Stockfish {
|
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
namespace {
|
|
|
|
|
2013-07-21 01:54:56 -06:00
|
|
|
enum Stages {
|
2018-03-20 18:48:31 -06:00
|
|
|
MAIN_TT, CAPTURE_INIT, GOOD_CAPTURE, REFUTATION, QUIET_INIT, QUIET, BAD_CAPTURE,
|
2018-03-18 17:56:19 -06:00
|
|
|
EVASION_TT, EVASION_INIT, EVASION,
|
|
|
|
PROBCUT_TT, PROBCUT_INIT, PROBCUT,
|
|
|
|
QSEARCH_TT, QCAPTURE_INIT, QCAPTURE, QCHECK_INIT, QCHECK
|
2009-08-31 06:28:11 -06:00
|
|
|
};
|
|
|
|
|
2017-04-22 01:03:17 -06:00
|
|
|
// partial_insertion_sort() sorts moves in descending order up to and including
|
|
|
|
// a given limit. The order of moves smaller than the limit is left unspecified.
|
|
|
|
void partial_insertion_sort(ExtMove* begin, ExtMove* end, int limit) {
|
|
|
|
|
2017-05-07 21:14:23 -06:00
|
|
|
for (ExtMove *sortedEnd = begin, *p = begin + 1; p < end; ++p)
|
2017-04-20 12:15:48 -06:00
|
|
|
if (p->value >= limit)
|
|
|
|
{
|
|
|
|
ExtMove tmp = *p, *q;
|
2017-05-07 21:14:23 -06:00
|
|
|
*p = *++sortedEnd;
|
|
|
|
for (q = sortedEnd; q != begin && *(q - 1) < tmp; --q)
|
|
|
|
*q = *(q - 1);
|
2017-04-20 12:15:48 -06:00
|
|
|
*q = tmp;
|
|
|
|
}
|
2013-02-10 11:10:01 -07:00
|
|
|
}
|
|
|
|
|
2014-11-01 14:35:10 -06:00
|
|
|
} // namespace
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2012-01-21 15:32:48 -07:00
|
|
|
|
|
|
|
/// Constructors of the MovePicker class. As arguments we pass information
|
2013-12-04 23:18:12 -07:00
|
|
|
/// to help it to return the (presumably) good moves first, to decide which
|
2008-08-31 23:59:13 -06:00
|
|
|
/// moves to return (in the quiescence search, for instance, we only want to
|
2016-01-16 14:34:29 -07:00
|
|
|
/// search captures, promotions, and some checks) and how important good move
|
2013-12-04 23:18:12 -07:00
|
|
|
/// ordering is at the current node.
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2017-08-21 10:59:24 -06:00
|
|
|
/// MovePicker constructor for the main search
|
Merge static history into main history,
thus simplifying and reducing the memory footprint.
I believe using static diff for better move ordering is more suited for
low depths, so restrict writing to low depths.
Todo: probably the condition for writing can be simplified
LTC:
LLR: 2.95 (-2.94,2.94) {-0.75,0.25}
Total: 18752 W: 768 L: 705 D: 17279
Ptnml(0-2): 7, 635, 8034, 688, 12
https://tests.stockfishchess.org/tests/view/5fd631791ac169120188859e
STC:
LLR: 2.95 (-2.94,2.94) {-1.25,0.25}
Total: 36504 W: 3380 L: 3313 D: 29811
Ptnml(0-2): 116, 2667, 12645, 2682, 142
https://tests.stockfishchess.org/tests/view/5fd5ed861ac1691201888569
closes https://github.com/official-stockfish/Stockfish/pull/3262
bench: 4018036
2020-12-13 13:23:30 -07:00
|
|
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh, const LowPlyHistory* lp,
|
2020-06-21 07:21:46 -06:00
|
|
|
const CapturePieceToHistory* cph, const PieceToHistory** ch, Move cm, const Move* killers, int pl)
|
Merge static history into main history,
thus simplifying and reducing the memory footprint.
I believe using static diff for better move ordering is more suited for
low depths, so restrict writing to low depths.
Todo: probably the condition for writing can be simplified
LTC:
LLR: 2.95 (-2.94,2.94) {-0.75,0.25}
Total: 18752 W: 768 L: 705 D: 17279
Ptnml(0-2): 7, 635, 8034, 688, 12
https://tests.stockfishchess.org/tests/view/5fd631791ac169120188859e
STC:
LLR: 2.95 (-2.94,2.94) {-1.25,0.25}
Total: 36504 W: 3380 L: 3313 D: 29811
Ptnml(0-2): 116, 2667, 12645, 2682, 142
https://tests.stockfishchess.org/tests/view/5fd5ed861ac1691201888569
closes https://github.com/official-stockfish/Stockfish/pull/3262
bench: 4018036
2020-12-13 13:23:30 -07:00
|
|
|
: pos(p), mainHistory(mh), lowPlyHistory(lp), captureHistory(cph), continuationHistory(ch),
|
Always remember the ttMove
In master, if the received ttMove meets the prescribed conditions in the various MovePicker constructors, it is returned as the first move, otherwise we set it to MOVE_NONE. If set to MOVE_NONE, we no longer track what the ttMove was, and it will might be returned later in a list of generated moves. This may be a waste. With this patch, if the ttMove fails to meet the prescribed conditions, we simply skip the TT stages, but still store the move and make sure it's never returned.
STC
LLR: 2.94 (-2.94,2.94) {-1.50,0.50}
Total: 66424 W: 12903 L: 12806 D: 40715
Ptnml(0-2): 1195, 7730, 15230, 7897, 1160
LTC
LLR: 2.94 (-2.94,2.94) {-1.50,0.50}
Total: 45682 W: 5989 L: 5926 D: 33767
Ptnml(0-2): 329, 4361, 13443, 4334, 374
closes https://github.com/official-stockfish/Stockfish/pull/2616
Bench 4928928
2020-04-03 15:10:50 -06:00
|
|
|
ttMove(ttm), refutations{{killers[0], 0}, {killers[1], 0}, {cm, 0}}, depth(d), ply(pl) {
|
2009-08-31 06:28:11 -06:00
|
|
|
|
2019-09-28 14:27:23 -06:00
|
|
|
assert(d > 0);
|
2011-01-23 14:59:05 -07:00
|
|
|
|
Always remember the ttMove
In master, if the received ttMove meets the prescribed conditions in the various MovePicker constructors, it is returned as the first move, otherwise we set it to MOVE_NONE. If set to MOVE_NONE, we no longer track what the ttMove was, and it will might be returned later in a list of generated moves. This may be a waste. With this patch, if the ttMove fails to meet the prescribed conditions, we simply skip the TT stages, but still store the move and make sure it's never returned.
STC
LLR: 2.94 (-2.94,2.94) {-1.50,0.50}
Total: 66424 W: 12903 L: 12806 D: 40715
Ptnml(0-2): 1195, 7730, 15230, 7897, 1160
LTC
LLR: 2.94 (-2.94,2.94) {-1.50,0.50}
Total: 45682 W: 5989 L: 5926 D: 33767
Ptnml(0-2): 329, 4361, 13443, 4334, 374
closes https://github.com/official-stockfish/Stockfish/pull/2616
Bench 4928928
2020-04-03 15:10:50 -06:00
|
|
|
stage = (pos.checkers() ? EVASION_TT : MAIN_TT) +
|
|
|
|
!(ttm && pos.pseudo_legal(ttm));
|
2011-01-23 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2017-08-21 10:59:24 -06:00
|
|
|
/// MovePicker constructor for quiescence search
|
Merge static history into main history,
thus simplifying and reducing the memory footprint.
I believe using static diff for better move ordering is more suited for
low depths, so restrict writing to low depths.
Todo: probably the condition for writing can be simplified
LTC:
LLR: 2.95 (-2.94,2.94) {-0.75,0.25}
Total: 18752 W: 768 L: 705 D: 17279
Ptnml(0-2): 7, 635, 8034, 688, 12
https://tests.stockfishchess.org/tests/view/5fd631791ac169120188859e
STC:
LLR: 2.95 (-2.94,2.94) {-1.25,0.25}
Total: 36504 W: 3380 L: 3313 D: 29811
Ptnml(0-2): 116, 2667, 12645, 2682, 142
https://tests.stockfishchess.org/tests/view/5fd5ed861ac1691201888569
closes https://github.com/official-stockfish/Stockfish/pull/3262
bench: 4018036
2020-12-13 13:23:30 -07:00
|
|
|
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
|
2018-07-19 10:26:05 -06:00
|
|
|
const CapturePieceToHistory* cph, const PieceToHistory** ch, Square rs)
|
Merge static history into main history,
thus simplifying and reducing the memory footprint.
I believe using static diff for better move ordering is more suited for
low depths, so restrict writing to low depths.
Todo: probably the condition for writing can be simplified
LTC:
LLR: 2.95 (-2.94,2.94) {-0.75,0.25}
Total: 18752 W: 768 L: 705 D: 17279
Ptnml(0-2): 7, 635, 8034, 688, 12
https://tests.stockfishchess.org/tests/view/5fd631791ac169120188859e
STC:
LLR: 2.95 (-2.94,2.94) {-1.25,0.25}
Total: 36504 W: 3380 L: 3313 D: 29811
Ptnml(0-2): 116, 2667, 12645, 2682, 142
https://tests.stockfishchess.org/tests/view/5fd5ed861ac1691201888569
closes https://github.com/official-stockfish/Stockfish/pull/3262
bench: 4018036
2020-12-13 13:23:30 -07:00
|
|
|
: pos(p), mainHistory(mh), captureHistory(cph), continuationHistory(ch), ttMove(ttm), recaptureSquare(rs), depth(d) {
|
2011-01-23 14:59:05 -07:00
|
|
|
|
2019-09-28 14:27:23 -06:00
|
|
|
assert(d <= 0);
|
2011-01-23 14:59:05 -07:00
|
|
|
|
Always remember the ttMove
In master, if the received ttMove meets the prescribed conditions in the various MovePicker constructors, it is returned as the first move, otherwise we set it to MOVE_NONE. If set to MOVE_NONE, we no longer track what the ttMove was, and it will might be returned later in a list of generated moves. This may be a waste. With this patch, if the ttMove fails to meet the prescribed conditions, we simply skip the TT stages, but still store the move and make sure it's never returned.
STC
LLR: 2.94 (-2.94,2.94) {-1.50,0.50}
Total: 66424 W: 12903 L: 12806 D: 40715
Ptnml(0-2): 1195, 7730, 15230, 7897, 1160
LTC
LLR: 2.94 (-2.94,2.94) {-1.50,0.50}
Total: 45682 W: 5989 L: 5926 D: 33767
Ptnml(0-2): 329, 4361, 13443, 4334, 374
closes https://github.com/official-stockfish/Stockfish/pull/2616
Bench 4928928
2020-04-03 15:10:50 -06:00
|
|
|
stage = (pos.checkers() ? EVASION_TT : QSEARCH_TT) +
|
Do not skip non-recapture ttMove when in check
The qsearch() MovePicker incorrectly skips a non-recapture ttMove
when in check (if depth <= DEPTH_QS_RECAPTURES). This is clearly not
intended and can cause qsearch() to return a mate score when there
is no mate. Introduced in cad300c and 6596f0e, as observed by
joergoster in #3171 and #3198.
This PR fixes the bug by not skipping the non-recapture ttMove when in check.
Passed non-regression STC:
https://tests.stockfishchess.org/tests/view/5f9867ea6a2c112b60691b10
LLR: 2.98 (-2.94,2.94) {-1.25,0.25}
Total: 27112 W: 2943 L: 2842 D: 21327
Ptnml(0-2): 127, 2170, 8878, 2237, 144
Passed non-regression LTC:
https://tests.stockfishchess.org/tests/view/5f9967326a2c112b60691bb0
LLR: 2.99 (-2.94,2.94) {-0.75,0.25}
Total: 18392 W: 807 L: 738 D: 16847
Ptnml(0-2): 9, 655, 7802, 718, 12
closes https://github.com/official-stockfish/Stockfish/pull/3199
closes https://github.com/official-stockfish/Stockfish/pull/3198
Bench: 3870606
2020-10-27 12:22:41 -06:00
|
|
|
!( ttm
|
|
|
|
&& (pos.checkers() || depth > DEPTH_QS_RECAPTURES || to_sq(ttm) == recaptureSquare)
|
|
|
|
&& pos.pseudo_legal(ttm));
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2018-03-27 08:44:47 -06:00
|
|
|
/// MovePicker constructor for ProbCut: we generate captures with SEE greater
|
2017-08-21 10:59:24 -06:00
|
|
|
/// than or equal to the given threshold.
|
2017-11-03 05:37:11 -06:00
|
|
|
MovePicker::MovePicker(const Position& p, Move ttm, Value th, const CapturePieceToHistory* cph)
|
Always remember the ttMove
In master, if the received ttMove meets the prescribed conditions in the various MovePicker constructors, it is returned as the first move, otherwise we set it to MOVE_NONE. If set to MOVE_NONE, we no longer track what the ttMove was, and it will might be returned later in a list of generated moves. This may be a waste. With this patch, if the ttMove fails to meet the prescribed conditions, we simply skip the TT stages, but still store the move and make sure it's never returned.
STC
LLR: 2.94 (-2.94,2.94) {-1.50,0.50}
Total: 66424 W: 12903 L: 12806 D: 40715
Ptnml(0-2): 1195, 7730, 15230, 7897, 1160
LTC
LLR: 2.94 (-2.94,2.94) {-1.50,0.50}
Total: 45682 W: 5989 L: 5926 D: 33767
Ptnml(0-2): 329, 4361, 13443, 4334, 374
closes https://github.com/official-stockfish/Stockfish/pull/2616
Bench 4928928
2020-04-03 15:10:50 -06:00
|
|
|
: pos(p), captureHistory(cph), ttMove(ttm), threshold(th) {
|
2011-05-21 10:17:11 -06:00
|
|
|
|
2012-12-25 09:59:35 -07:00
|
|
|
assert(!pos.checkers());
|
2011-05-21 10:17:11 -06:00
|
|
|
|
Always remember the ttMove
In master, if the received ttMove meets the prescribed conditions in the various MovePicker constructors, it is returned as the first move, otherwise we set it to MOVE_NONE. If set to MOVE_NONE, we no longer track what the ttMove was, and it will might be returned later in a list of generated moves. This may be a waste. With this patch, if the ttMove fails to meet the prescribed conditions, we simply skip the TT stages, but still store the move and make sure it's never returned.
STC
LLR: 2.94 (-2.94,2.94) {-1.50,0.50}
Total: 66424 W: 12903 L: 12806 D: 40715
Ptnml(0-2): 1195, 7730, 15230, 7897, 1160
LTC
LLR: 2.94 (-2.94,2.94) {-1.50,0.50}
Total: 45682 W: 5989 L: 5926 D: 33767
Ptnml(0-2): 329, 4361, 13443, 4334, 374
closes https://github.com/official-stockfish/Stockfish/pull/2616
Bench 4928928
2020-04-03 15:10:50 -06:00
|
|
|
stage = PROBCUT_TT + !(ttm && pos.capture(ttm)
|
|
|
|
&& pos.pseudo_legal(ttm)
|
|
|
|
&& pos.see_ge(ttm, threshold));
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2018-03-18 17:56:19 -06:00
|
|
|
/// MovePicker::score() assigns a numerical value to each move in a list, used
|
|
|
|
/// for sorting. Captures are ordered by Most Valuable Victim (MVV), preferring
|
|
|
|
/// captures with a good history. Quiets moves are ordered using the histories.
|
2017-08-21 10:59:24 -06:00
|
|
|
template<GenType Type>
|
2017-08-09 06:04:59 -06:00
|
|
|
void MovePicker::score() {
|
2008-10-25 08:28:24 -06:00
|
|
|
|
2017-08-21 10:59:24 -06:00
|
|
|
static_assert(Type == CAPTURES || Type == QUIETS || Type == EVASIONS, "Wrong type");
|
|
|
|
|
2015-05-01 18:36:39 -06:00
|
|
|
for (auto& m : *this)
|
2021-01-31 05:46:05 -07:00
|
|
|
if constexpr (Type == CAPTURES)
|
2019-07-10 17:59:33 -06:00
|
|
|
m.value = int(PieceValue[MG][pos.piece_on(to_sq(m))]) * 6
|
|
|
|
+ (*captureHistory)[pos.moved_piece(m)][to_sq(m)][type_of(pos.piece_on(to_sq(m)))];
|
2017-08-21 10:59:24 -06:00
|
|
|
|
2021-01-31 05:46:05 -07:00
|
|
|
else if constexpr (Type == QUIETS)
|
2019-10-05 08:42:36 -06:00
|
|
|
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
|
|
|
|
+ 2 * (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
|
Tune ordering of moves at internal nodes
We change the relative weights of the function used to order
quiet moves in our MovePicker class.
Passed STC:
LLR: 2.94 (-2.94,2.94) {-0.25,1.25}
Total: 32184 W: 2936 L: 2773 D: 26475
Ptnml(0-2): 115, 2196, 11328, 2317, 136
https://tests.stockfishchess.org/tests/view/60161ee1735dd7f0f03530f8
Passed LTC:
LLR: 2.93 (-2.94,2.94) {0.25,1.25}
Total: 33088 W: 1292 L: 1149 D: 30647
Ptnml(0-2): 14, 1030, 14318, 1163, 19
https://tests.stockfishchess.org/tests/view/60163146735dd7f0f03530ff
The new weight were chosen after the following SPSA session:
https://tests.stockfishchess.org/tests/view/60136857735dd7f0f0352f6c
Closes https://github.com/official-stockfish/Stockfish/pull/3331
Bench: 4398803
2021-01-30 20:05:39 -07:00
|
|
|
+ (*continuationHistory[1])[pos.moved_piece(m)][to_sq(m)]
|
|
|
|
+ (*continuationHistory[3])[pos.moved_piece(m)][to_sq(m)]
|
Improve move order near the root
Current move histories are known to work well near the leaves, whilst at
higher depths they aren't very helpful. To address this problem this
patch introduces a table dedicated for what's happening at plies 0-3.
It's structured like mainHistory with ply index instead of color.
It get cleared with each new search and is filled during iterative
deepening at higher depths when recording successful quiet moves near
the root or traversing nodes which were in the principal variation
(ttPv).
Medium TC (20+0.2):
https://tests.stockfishchess.org/tests/view/5e4d358790a0a02810d096dc
LLR: 2.94 (-2.94,2.94) {-0.50,1.50}
Total: 100910 W: 16682 L: 16376 D: 67852
Ptnml(0-2): 1177, 10983, 25883, 11181, 1231
LTC:
https://tests.stockfishchess.org/tests/view/5e4e2cb790a0a02810d09714
LLR: 2.95 (-2.94,2.94) {0.25,1.75}
Total: 80444 W: 10495 L: 10095 D: 59854
Ptnml(0-2): 551, 7479, 23803, 7797, 592
closes https://github.com/official-stockfish/Stockfish/pull/2557
Bench: 4705960
2020-02-21 06:01:59 -07:00
|
|
|
+ (*continuationHistory[5])[pos.moved_piece(m)][to_sq(m)]
|
Simplify lowply-history scoring logic
STC:
https://tests.stockfishchess.org/tests/view/60eee559d1189bed71812b16
LLR: 2.97 (-2.94,2.94) <-2.50,0.50>
Total: 33976 W: 2523 L: 2431 D: 29022
Ptnml(0-2): 66, 2030, 12730, 2070, 92
LTC:
https://tests.stockfishchess.org/tests/view/60eefa12d1189bed71812b24
LLR: 2.93 (-2.94,2.94) <-2.50,0.50>
Total: 107240 W: 3053 L: 3046 D: 101141
Ptnml(0-2): 56, 2668, 48154, 2697, 45
closes https://github.com/official-stockfish/Stockfish/pull/3616
bench: 5199177
2021-07-15 12:56:21 -06:00
|
|
|
+ (ply < MAX_LPH ? 6 * (*lowPlyHistory)[ply][from_to(m)] : 0);
|
2017-08-09 06:04:59 -06:00
|
|
|
|
2017-08-21 10:59:24 -06:00
|
|
|
else // Type == EVASIONS
|
|
|
|
{
|
|
|
|
if (pos.capture(m))
|
|
|
|
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
|
|
|
|
- Value(type_of(pos.moved_piece(m)));
|
|
|
|
else
|
Tune ordering of moves at internal nodes
We change the relative weights of the function used to order
quiet moves in our MovePicker class.
Passed STC:
LLR: 2.94 (-2.94,2.94) {-0.25,1.25}
Total: 32184 W: 2936 L: 2773 D: 26475
Ptnml(0-2): 115, 2196, 11328, 2317, 136
https://tests.stockfishchess.org/tests/view/60161ee1735dd7f0f03530f8
Passed LTC:
LLR: 2.93 (-2.94,2.94) {0.25,1.25}
Total: 33088 W: 1292 L: 1149 D: 30647
Ptnml(0-2): 14, 1030, 14318, 1163, 19
https://tests.stockfishchess.org/tests/view/60163146735dd7f0f03530ff
The new weight were chosen after the following SPSA session:
https://tests.stockfishchess.org/tests/view/60136857735dd7f0f0352f6c
Closes https://github.com/official-stockfish/Stockfish/pull/3331
Bench: 4398803
2021-01-30 20:05:39 -07:00
|
|
|
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
|
|
|
|
+ 2 * (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
|
2018-07-19 10:26:05 -06:00
|
|
|
- (1 << 28);
|
2017-08-21 10:59:24 -06:00
|
|
|
}
|
2008-08-31 23:59:13 -06:00
|
|
|
}
|
|
|
|
|
2018-03-27 08:44:47 -06:00
|
|
|
/// MovePicker::select() returns the next move satisfying a predicate function.
|
2018-03-20 18:48:31 -06:00
|
|
|
/// It never returns the TT move.
|
2018-03-27 08:44:47 -06:00
|
|
|
template<MovePicker::PickType T, typename Pred>
|
|
|
|
Move MovePicker::select(Pred filter) {
|
Lazy SMP
Start all threads searching on root position and
use only the shared TT table as synching scheme.
It seems this scheme scales better than YBWC for
high number of threads.
Verified for nor regression at STC 3 threads
LLR: -2.95 (-2.94,2.94) [-3.00,1.00]
Total: 40232 W: 6908 L: 7130 D: 26194
Verified for nor regression at LTC 3 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 28186 W: 3908 L: 3798 D: 20480
Verified for nor regression at STC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 3607 W: 674 L: 526 D: 2407
Verified for nor regression at LTC 7 threads
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 4235 W: 671 L: 528 D: 3036
Tested with fixed games at LTC with 20 threads
ELO: 44.75 +-7.6 (95%) LOS: 100.0%
Total: 2069 W: 407 L: 142 D: 1520
Tested with fixed games at XLTC (120secs) with 20 threads
ELO: 28.01 +-6.7 (95%) LOS: 100.0%
Total: 2275 W: 349 L: 166 D: 1760
Original patch of mbootsector, with additional work
from Ivan Ivec (log formula), Joerg Oster (id loop
simplification) and Marco Costalba (assorted formatting
and rework).
Bench: 8116244
2015-10-06 00:15:17 -06:00
|
|
|
|
2018-03-18 17:56:19 -06:00
|
|
|
while (cur < endMoves)
|
|
|
|
{
|
2018-03-27 08:44:47 -06:00
|
|
|
if (T == Best)
|
2018-03-18 17:56:19 -06:00
|
|
|
std::swap(*cur, *std::max_element(cur, endMoves));
|
2008-10-16 06:25:56 -06:00
|
|
|
|
2019-04-17 13:13:39 -06:00
|
|
|
if (*cur != ttMove && filter())
|
|
|
|
return *cur++;
|
2009-08-30 02:42:55 -06:00
|
|
|
|
2019-04-17 13:13:39 -06:00
|
|
|
cur++;
|
2018-03-18 17:56:19 -06:00
|
|
|
}
|
2019-04-17 13:13:39 -06:00
|
|
|
return MOVE_NONE;
|
2018-03-18 17:56:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/// MovePicker::next_move() is the most important method of the MovePicker class. It
|
2021-01-09 08:46:06 -07:00
|
|
|
/// returns a new pseudo-legal move every time it is called until there are no more
|
2018-03-20 18:48:31 -06:00
|
|
|
/// moves left, picking the move with the highest score from a list of generated moves.
|
2018-03-18 17:56:19 -06:00
|
|
|
Move MovePicker::next_move(bool skipQuiets) {
|
2018-03-11 19:47:35 -06:00
|
|
|
|
2018-03-18 17:56:19 -06:00
|
|
|
top:
|
2016-09-10 13:37:36 -06:00
|
|
|
switch (stage) {
|
2010-02-05 10:17:52 -07:00
|
|
|
|
2018-03-18 17:56:19 -06:00
|
|
|
case MAIN_TT:
|
|
|
|
case EVASION_TT:
|
|
|
|
case QSEARCH_TT:
|
|
|
|
case PROBCUT_TT:
|
2016-09-10 13:37:36 -06:00
|
|
|
++stage;
|
|
|
|
return ttMove;
|
2010-02-05 10:17:52 -07:00
|
|
|
|
2018-03-18 17:56:19 -06:00
|
|
|
case CAPTURE_INIT:
|
|
|
|
case PROBCUT_INIT:
|
|
|
|
case QCAPTURE_INIT:
|
2018-03-27 08:44:47 -06:00
|
|
|
cur = endBadCaptures = moves;
|
2016-09-10 13:37:36 -06:00
|
|
|
endMoves = generate<CAPTURES>(pos, cur);
|
2018-03-27 08:44:47 -06:00
|
|
|
|
2016-09-10 13:37:36 -06:00
|
|
|
score<CAPTURES>();
|
|
|
|
++stage;
|
2018-03-18 17:56:19 -06:00
|
|
|
goto top;
|
2018-02-25 04:49:03 -07:00
|
|
|
|
2018-03-18 17:56:19 -06:00
|
|
|
case GOOD_CAPTURE:
|
2018-03-27 08:44:47 -06:00
|
|
|
if (select<Best>([&](){
|
A combo of parameters tweaks
This patch is a combinaison of two recent parameters tweaks which had
failed narrowly (yellow) at long time control:
• improvement in move ordering during search by softening the distinction
between bad captures and good captures during move generation, leading
to improved awareness of Stockfish of potential piece sacrifices (idea
by Rahul Dsilva)
• increase in the weight of pawns in the "initiative" part of the evaluation
function. With this change Stockfish should have more incentive to exchange
pawns when losing, and to keep pawns when winning.
STC:
LLR: 2.93 (-2.94,2.94) {-0.50,1.50}
Total: 10704 W: 2178 L: 1974 D: 6552
Ptnml(0-2): 168, 1185, 2464, 1345, 190
https://tests.stockfishchess.org/tests/view/5ec5553b377121ac09e1023d
LTC:
LLR: 2.94 (-2.94,2.94) {0.25,1.75}
Total: 60592 W: 7835 L: 7494 D: 45263
Ptnml(0-2): 430, 5514, 18086, 5817, 449
https://tests.stockfishchess.org/tests/view/5ec55ca2377121ac09e10249
Closes https://github.com/official-stockfish/Stockfish/pull/2691
Bench: 4519117
2020-05-20 09:06:42 -06:00
|
|
|
return pos.see_ge(*cur, Value(-69 * cur->value / 1024)) ?
|
2018-03-27 08:44:47 -06:00
|
|
|
// Move losing capture to endBadCaptures to be tried later
|
2019-04-17 13:13:39 -06:00
|
|
|
true : (*endBadCaptures++ = *cur, false); }))
|
|
|
|
return *(cur - 1);
|
2018-03-11 19:47:35 -06:00
|
|
|
|
2018-03-20 18:48:31 -06:00
|
|
|
// Prepare the pointers to loop over the refutations array
|
2018-03-27 08:44:47 -06:00
|
|
|
cur = std::begin(refutations);
|
|
|
|
endMoves = std::end(refutations);
|
2018-03-20 18:48:31 -06:00
|
|
|
|
2018-03-11 19:47:35 -06:00
|
|
|
// If the countermove is the same as a killer, skip it
|
2018-03-20 18:48:31 -06:00
|
|
|
if ( refutations[0].move == refutations[2].move
|
|
|
|
|| refutations[1].move == refutations[2].move)
|
|
|
|
--endMoves;
|
|
|
|
|
2018-03-18 17:56:19 -06:00
|
|
|
++stage;
|
2020-07-11 08:59:33 -06:00
|
|
|
[[fallthrough]];
|
2016-09-10 13:37:36 -06:00
|
|
|
|
2018-03-20 18:48:31 -06:00
|
|
|
case REFUTATION:
|
2019-04-17 13:13:39 -06:00
|
|
|
if (select<Next>([&](){ return *cur != MOVE_NONE
|
|
|
|
&& !pos.capture(*cur)
|
|
|
|
&& pos.pseudo_legal(*cur); }))
|
|
|
|
return *(cur - 1);
|
2018-03-20 18:48:31 -06:00
|
|
|
++stage;
|
2020-07-11 08:59:33 -06:00
|
|
|
[[fallthrough]];
|
2016-09-10 13:37:36 -06:00
|
|
|
|
|
|
|
case QUIET_INIT:
|
2019-06-17 15:35:03 -06:00
|
|
|
if (!skipQuiets)
|
|
|
|
{
|
|
|
|
cur = endBadCaptures;
|
|
|
|
endMoves = generate<QUIETS>(pos, cur);
|
2018-03-27 08:44:47 -06:00
|
|
|
|
2019-06-17 15:35:03 -06:00
|
|
|
score<QUIETS>();
|
2019-10-05 08:42:36 -06:00
|
|
|
partial_insertion_sort(cur, endMoves, -3000 * depth);
|
2019-06-17 15:35:03 -06:00
|
|
|
}
|
Bonus for double attacks on unsupported pawns
This is a functional change that rewards double attacks on an unsupported pawns.
STC (non-functional difference)
LLR: 2.96 (-2.94,2.94) [0.50,4.50]
Total: 83276 W: 18981 L: 18398 D: 45897
http://tests.stockfishchess.org/tests/view/5d0970500ebc5925cf0a77d4
LTC (incomplete looping version)
LLR: 0.50 (-2.94,2.94) [0.00,3.50]
Total: 82999 W: 14244 L: 13978 D: 54777
http://tests.stockfishchess.org/tests/view/5d0a8d480ebc5925cf0a8d58
LTC (completed non-looping version).
LLR: 2.96 (-2.94,2.94) [0.00,3.50]
Total: 223381 W: 38323 L: 37512 D: 147546
http://tests.stockfishchess.org/tests/view/5d0e80510ebc5925cf0ad320
Closes https://github.com/official-stockfish/Stockfish/pull/2205
Bench 3633546
----------------------------------
Comments by Alain SAVARD:
interesting result ! I would have expected that search would resolve such positions
correctly on the very next move. This is not a very common pattern, and when it happens,
it will quickly disappear. So I'm quite surprised that it passed LTC.
I would be even more surprised if this would resist a simplification.
Anyway, let's try to imagine a few cases.
a) If you have White d5 f5 against Black e6, and White to move
last move by Black was probably a capture on e6 and White is about to recapture on e6
b) If you have White d5 f5 against e6, and Black to move
last move by White was possibly a capture on d5 or f5
or the pawn on e6 was pinned or could not move for some reason.
and white wants to blast open the position and just pushed d4-d5 or f4-f5
Some possible follow-ups
a) Motif is so rare that the popcount() can be safely replaced with a bool()
But this would not pass a SPRT[0,4],
So try a simplification with bool() and also without the & ~theirAttacks
b) If it works, we probably can simply have this in the loop
if (lever) score += S(0, 20);
c) remove all this and tweak something in search for pawn captures (priority, SEE, extension,..)
2019-06-27 01:45:53 -06:00
|
|
|
|
2016-09-10 13:37:36 -06:00
|
|
|
++stage;
|
2020-07-11 08:59:33 -06:00
|
|
|
[[fallthrough]];
|
2011-04-16 04:24:30 -06:00
|
|
|
|
2016-09-10 13:37:36 -06:00
|
|
|
case QUIET:
|
2018-03-18 17:56:19 -06:00
|
|
|
if ( !skipQuiets
|
2019-04-17 13:13:39 -06:00
|
|
|
&& select<Next>([&](){return *cur != refutations[0].move
|
|
|
|
&& *cur != refutations[1].move
|
|
|
|
&& *cur != refutations[2].move;}))
|
|
|
|
return *(cur - 1);
|
2018-03-18 17:56:19 -06:00
|
|
|
|
2018-03-20 18:48:31 -06:00
|
|
|
// Prepare the pointers to loop over the bad captures
|
2018-03-27 08:44:47 -06:00
|
|
|
cur = moves;
|
|
|
|
endMoves = endBadCaptures;
|
|
|
|
|
2016-09-10 13:37:36 -06:00
|
|
|
++stage;
|
2020-07-11 08:59:33 -06:00
|
|
|
[[fallthrough]];
|
2009-08-30 02:42:55 -06:00
|
|
|
|
2018-03-18 17:56:19 -06:00
|
|
|
case BAD_CAPTURE:
|
2019-01-01 05:36:56 -07:00
|
|
|
return select<Next>([](){ return true; });
|
2016-09-10 13:37:36 -06:00
|
|
|
|
2018-03-18 17:56:19 -06:00
|
|
|
case EVASION_INIT:
|
2016-09-10 13:37:36 -06:00
|
|
|
cur = moves;
|
|
|
|
endMoves = generate<EVASIONS>(pos, cur);
|
2018-03-27 08:44:47 -06:00
|
|
|
|
2016-10-16 07:20:05 -06:00
|
|
|
score<EVASIONS>();
|
2016-09-10 13:37:36 -06:00
|
|
|
++stage;
|
2020-07-11 08:59:33 -06:00
|
|
|
[[fallthrough]];
|
2009-10-20 04:38:20 -06:00
|
|
|
|
2018-03-18 17:56:19 -06:00
|
|
|
case EVASION:
|
2019-01-01 05:36:56 -07:00
|
|
|
return select<Best>([](){ return true; });
|
2016-09-15 00:38:20 -06:00
|
|
|
|
2018-03-18 17:56:19 -06:00
|
|
|
case PROBCUT:
|
2019-04-17 13:13:39 -06:00
|
|
|
return select<Best>([&](){ return pos.see_ge(*cur, threshold); });
|
2012-01-21 15:32:48 -07:00
|
|
|
|
2018-03-18 17:56:19 -06:00
|
|
|
case QCAPTURE:
|
2018-03-27 08:44:47 -06:00
|
|
|
if (select<Best>([&](){ return depth > DEPTH_QS_RECAPTURES
|
2019-04-17 13:13:39 -06:00
|
|
|
|| to_sq(*cur) == recaptureSquare; }))
|
|
|
|
return *(cur - 1);
|
2018-03-18 17:56:19 -06:00
|
|
|
|
|
|
|
// If we did not find any move and we do not try checks, we have finished
|
|
|
|
if (depth != DEPTH_QS_CHECKS)
|
|
|
|
return MOVE_NONE;
|
|
|
|
|
|
|
|
++stage;
|
2020-07-11 08:59:33 -06:00
|
|
|
[[fallthrough]];
|
2018-03-18 17:56:19 -06:00
|
|
|
|
|
|
|
case QCHECK_INIT:
|
2016-09-15 00:38:20 -06:00
|
|
|
cur = moves;
|
|
|
|
endMoves = generate<QUIET_CHECKS>(pos, cur);
|
2018-03-27 08:44:47 -06:00
|
|
|
|
2016-09-15 00:38:20 -06:00
|
|
|
++stage;
|
2020-07-11 08:59:33 -06:00
|
|
|
[[fallthrough]];
|
2016-09-15 00:38:20 -06:00
|
|
|
|
2018-03-18 17:56:19 -06:00
|
|
|
case QCHECK:
|
2019-01-01 05:36:56 -07:00
|
|
|
return select<Next>([](){ return true; });
|
2009-08-27 01:12:51 -06:00
|
|
|
}
|
2016-09-10 13:37:36 -06:00
|
|
|
|
2018-03-18 17:56:19 -06:00
|
|
|
assert(false);
|
|
|
|
return MOVE_NONE; // Silence warning
|
2009-08-27 01:12:51 -06:00
|
|
|
}
|
2021-02-26 02:02:13 -07:00
|
|
|
|
|
|
|
} // namespace Stockfish
|