Line data Source code
1 : #pragma once
2 :
3 : #include "definition.hpp"
4 : #include "searchConfig.hpp"
5 : #include "tables.hpp"
6 : #include "timers.hpp"
7 : #include "transposition.hpp"
8 :
9 : /*!
10 : * Minic is not sorting move on the fly, but once and for all
11 : * MoveSorter is storing needed information and computeScore function
12 : * will give each move a score. After that, sort is called on the MoveList
13 : * */
14 :
15 : struct MoveSortOperator {
16 149118285 : constexpr bool operator()(const Move& a, const Move& b) const {
17 149118285 : assert(a != INVALIDMOVE);
18 149118285 : assert(b != INVALIDMOVE);
19 149118285 : return Move2Score(a) > Move2Score(b);
20 : }
21 : };
22 :
23 : struct MoveSorter {
24 : MoveSorter(const Searcher& _context,
25 : const Position& _p,
26 : float _gp,
27 : DepthType _height,
28 : const CMHPtrArray& _cmhPtr,
29 : bool _useSEE = true,
30 : bool _isInCheck = false,
31 : const TT::Entry* _e = nullptr,
32 4260014 : const MiniMove _refutation = INVALIDMINIMOVE):
33 4260014 : context(_context), p(_p), gp(_gp), height(_height), cmhPtr(_cmhPtr), useSEE(_useSEE), isInCheck(_isInCheck), e(_e), refutation(_refutation) {
34 4260014 : assert(e == nullptr || e->h != nullHash);
35 : }
36 :
37 : template<Color C> void computeScore(Move& m) const;
38 :
39 : const Position& p;
40 : const TT::Entry* e;
41 : const Searcher& context;
42 : const bool useSEE;
43 : const bool isInCheck;
44 : const MiniMove refutation;
45 : const DepthType height;
46 : const CMHPtrArray& cmhPtr;
47 : const float gp;
48 :
49 : bool skipSort = false;
50 :
51 2321803 : inline void score(MoveList & moves) const{
52 2321803 : score(context, moves, p, gp, height, cmhPtr, useSEE, isInCheck, e, refutation);
53 2321803 : }
54 :
55 : static void score(const Searcher& context,
56 : MoveList& moves,
57 : const Position& p,
58 : const float gp,
59 : const DepthType height,
60 : const CMHPtrArray& cmhPtr,
61 : const bool useSEE = true,
62 : const bool isInCheck = false,
63 : const TT::Entry* e = nullptr,
64 : const MiniMove refutation = INVALIDMINIMOVE);
65 :
66 : inline void scoreAndSort(MoveList & moves) const {
67 : scoreAndSort(context, moves, p, gp, height, cmhPtr, useSEE, isInCheck, e, refutation);
68 : }
69 :
70 : static void scoreAndSort(const Searcher& context,
71 : MoveList& moves,
72 : const Position& p,
73 : const float gp,
74 : const DepthType height,
75 : const CMHPtrArray& cmhPtr,
76 : const bool useSEE = true,
77 : const bool isInCheck = false,
78 : const TT::Entry* e = nullptr,
79 : const MiniMove refutation = INVALIDMINIMOVE);
80 :
81 : static void sort(MoveList& moves);
82 :
83 13088837 : [[nodiscard]] inline const Move* pickNextLazy(MoveList& moves,
84 : size_t& begin,
85 : bool sorted = false,
86 : ScoreType threshold = SearchConfig::lazySortThreshold){
87 : // if move has very low chance of raising alpha, no need to sort anymore ...
88 20133135 : skipSort = skipSort || sorted || (begin != 0 && Move2Score(*(moves.begin() + begin - 1)) < threshold);
89 13088837 : return pickNext(moves, begin, skipSort);
90 : }
91 :
92 : [[nodiscard]] static const Move* pickNext(MoveList& moves, size_t& begin, bool skipSort = false);
93 : };
|