2525namespace {
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
6262MovePicker::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.
133134template <PickType T, typename Pred>
134135Move 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.
152153Move MovePicker::next_move (bool skipQuiets) {
153154
154155top:
@@ -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 */
0 commit comments