Skip to content

Commit d40e7ee

Browse files
vondelesnicolet
authored andcommitted
Join refutation stages in the movepicker
Unifies a bit further the three refuation stages in the MovePicker class. Also treat the skipping of TT move now always via select_move(), as discussed in pull request #1454. Passed STC: LLR: 2.95 (-2.94,2.94) [-3.00,1.00] Total: 16608 W: 3461 L: 3331 D: 9816 http://tests.stockfishchess.org/tests/view/5ab0aaf00ebc59029fb6f6c3 Closes #1502 No functional change.
1 parent ed26d71 commit d40e7ee

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

src/movepick.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
namespace {
2626

2727
enum Stages {
28-
MAIN_TT, CAPTURE_INIT, GOOD_CAPTURE, KILLER0, KILLER1, COUNTERMOVE, QUIET_INIT, QUIET, BAD_CAPTURE,
28+
MAIN_TT, CAPTURE_INIT, GOOD_CAPTURE, REFUTATION, QUIET_INIT, QUIET, BAD_CAPTURE,
2929
EVASION_TT, EVASION_INIT, EVASION,
3030
PROBCUT_TT, PROBCUT_INIT, PROBCUT,
3131
QSEARCH_TT, QCAPTURE_INIT, QCAPTURE, QCHECK_INIT, QCHECK
@@ -60,9 +60,9 @@ namespace {
6060

6161
/// MovePicker constructor for the main search
6262
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
63-
const CapturePieceToHistory* cph, const PieceToHistory** ch, Move cm, Move* killers_p)
63+
const CapturePieceToHistory* cph, const PieceToHistory** ch, Move cm, Move* killers)
6464
: pos(p), mainHistory(mh), captureHistory(cph), contHistory(ch),
65-
refutations{killers_p[0], killers_p[1], cm}, depth(d){
65+
refutations{{killers[0], 0}, {killers[1], 0}, {cm, 0}}, depth(d){
6666

6767
assert(d > DEPTH_ZERO);
6868

@@ -129,7 +129,8 @@ void MovePicker::score() {
129129
}
130130
}
131131

132-
/// MovePicker::select_move() returns the next move satisfying a predicate function
132+
/// MovePicker::select_move() returns the next move satisfying a predicate function.
133+
/// It never returns the TT move.
133134
template<PickType T, typename Pred>
134135
Move MovePicker::select_move(Pred filter) {
135136

@@ -147,8 +148,8 @@ Move MovePicker::select_move(Pred filter) {
147148
}
148149

149150
/// MovePicker::next_move() is the most important method of the MovePicker class. It
150-
/// returns a new pseudo legal move every time it is called, until there are no more
151-
/// moves left. It picks the move with the highest score from a list of generated moves.
151+
/// returns a new pseudo legal move every time it is called until there are no more
152+
/// moves left, picking the move with the highest score from a list of generated moves.
152153
Move MovePicker::next_move(bool skipQuiets) {
153154

154155
top:
@@ -176,25 +177,23 @@ Move MovePicker::next_move(bool skipQuiets) {
176177
true : (*endBadCaptures++ = move, false); }))
177178
return move;
178179

180+
// Prepare the pointers to loop over the refutations array
181+
cur = std::begin(refutations), endMoves = std::end(refutations);
182+
179183
// If the countermove is the same as a killer, skip it
180-
if ( refutations[0] == refutations[2]
181-
|| refutations[1] == refutations[2])
182-
refutations[2] = MOVE_NONE;
184+
if ( refutations[0].move == refutations[2].move
185+
|| refutations[1].move == refutations[2].move)
186+
--endMoves;
187+
183188
++stage;
184189
/* fallthrough */
185190

186-
case KILLER0:
187-
case KILLER1:
188-
case COUNTERMOVE:
189-
while (stage <= COUNTERMOVE)
190-
{
191-
move = refutations[ stage++ - KILLER0];
192-
if ( move != MOVE_NONE
193-
&& move != ttMove
194-
&& pos.pseudo_legal(move)
195-
&& !pos.capture(move))
196-
return move;
197-
}
191+
case REFUTATION:
192+
if (select_move<NEXT>([&](){ return move != MOVE_NONE
193+
&& !pos.capture(move)
194+
&& pos.pseudo_legal(move); }))
195+
return move;
196+
++stage;
198197
/* fallthrough */
199198

200199
case QUIET_INIT:
@@ -212,7 +211,7 @@ Move MovePicker::next_move(bool skipQuiets) {
212211
&& move != refutations[2];}))
213212
return move;
214213

215-
// Point to beginning and end of bad captures
214+
// Prepare the pointers to loop over the bad captures
216215
cur = moves, endMoves = endBadCaptures;
217216
++stage;
218217
/* fallthrough */

src/movepick.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ class MovePicker {
131131
const ButterflyHistory* mainHistory;
132132
const CapturePieceToHistory* captureHistory;
133133
const PieceToHistory** contHistory;
134-
Move ttMove, refutations[3];
135-
ExtMove *cur, *endMoves, *endBadCaptures;
134+
Move ttMove;
135+
ExtMove refutations[3], *cur, *endMoves, *endBadCaptures;
136136
int stage;
137137
Move move;
138138
Square recaptureSquare;

0 commit comments

Comments
 (0)