1818
1919#include " movepick.h"
2020
21- #include < algorithm>
2221#include < array>
2322#include < cassert>
2423#include < limits>
25- #include < utility>
2624
2725#include " bitboard.h"
2826#include " position.h"
@@ -158,11 +156,11 @@ void MovePicker::score() {
158156 Square to = m.to_sq ();
159157
160158 // histories
161- m.value = (*mainHistory)[pos.side_to_move ()][m.from_to ()];
159+ m.value = 2 * (*mainHistory)[pos.side_to_move ()][m.from_to ()];
162160 m.value += 2 * (*pawnHistory)[pawn_structure_index (pos)][pc][to];
163- m.value += 2 * (*continuationHistory[0 ])[pc][to];
161+ m.value += (*continuationHistory[0 ])[pc][to];
164162 m.value += (*continuationHistory[1 ])[pc][to];
165- m.value += (*continuationHistory[2 ])[pc][to] / 3 ;
163+ m.value += (*continuationHistory[2 ])[pc][to];
166164 m.value += (*continuationHistory[3 ])[pc][to];
167165 m.value += (*continuationHistory[5 ])[pc][to];
168166
@@ -199,19 +197,13 @@ void MovePicker::score() {
199197
200198// Returns the next move satisfying a predicate function.
201199// This never returns the TT move, as it was emitted before.
202- template <MovePicker::PickType T, typename Pred>
200+ template <typename Pred>
203201Move MovePicker::select (Pred filter) {
204202
205- while (cur < endMoves)
206- {
207- if constexpr (T == Best)
208- std::swap (*cur, *std::max_element (cur, endMoves));
209-
203+ for (; cur < endMoves; ++cur)
210204 if (*cur != ttMove && filter ())
211205 return *cur++;
212206
213- cur++;
214- }
215207 return Move::none ();
216208}
217209
@@ -245,7 +237,7 @@ Move MovePicker::next_move() {
245237 goto top;
246238
247239 case GOOD_CAPTURE :
248- if (select<Next> ([&]() {
240+ if (select ([&]() {
249241 // Move losing capture to endBadCaptures to be tried later
250242 return pos.see_ge (*cur, -cur->value / 18 ) ? true
251243 : (*endBadCaptures++ = *cur, false );
@@ -269,7 +261,7 @@ Move MovePicker::next_move() {
269261 [[fallthrough]];
270262
271263 case GOOD_QUIET :
272- if (!skipQuiets && select<Next> ([]() { return true ; }))
264+ if (!skipQuiets && select ([]() { return true ; }))
273265 {
274266 if ((cur - 1 )->value > -7998 || (cur - 1 )->value <= quiet_threshold (depth))
275267 return *(cur - 1 );
@@ -286,7 +278,7 @@ Move MovePicker::next_move() {
286278 [[fallthrough]];
287279
288280 case BAD_CAPTURE :
289- if (select<Next> ([]() { return true ; }))
281+ if (select ([]() { return true ; }))
290282 return *(cur - 1 );
291283
292284 // Prepare the pointers to loop over the bad quiets
@@ -298,7 +290,7 @@ Move MovePicker::next_move() {
298290
299291 case BAD_QUIET :
300292 if (!skipQuiets)
301- return select<Next> ([]() { return true ; });
293+ return select ([]() { return true ; });
302294
303295 return Move::none ();
304296
@@ -307,17 +299,16 @@ Move MovePicker::next_move() {
307299 endMoves = generate<EVASIONS>(pos, cur);
308300
309301 score<EVASIONS>();
302+ partial_insertion_sort (cur, endMoves, std::numeric_limits<int >::min ());
310303 ++stage;
311304 [[fallthrough]];
312305
313306 case EVASION :
314- return select<Best>([]() { return true ; });
307+ case QCAPTURE :
308+ return select ([]() { return true ; });
315309
316310 case PROBCUT :
317- return select<Next>([&]() { return pos.see_ge (*cur, threshold); });
318-
319- case QCAPTURE :
320- return select<Next>([]() { return true ; });
311+ return select ([&]() { return pos.see_ge (*cur, threshold); });
321312 }
322313
323314 assert (false );
0 commit comments