Line data Source code
1 : #pragma once
2 :
3 : #include "definition.hpp"
4 : #include "logging.hpp"
5 :
6 : /*!
7 : All parameters for search are defined here
8 : * There are const when no CLOP tuning is use and of course need to be mutable when begin tuned
9 : */
10 : namespace SearchConfig {
11 : inline const bool doWindow = true;
12 : inline const bool doPVS = true;
13 : inline const bool doNullMove = true;
14 : inline const bool doFutility = true;
15 : inline const bool doLMR = true;
16 : inline const bool doLMP = true;
17 : inline const bool doStaticNullMove = true;
18 : inline const bool doThreatsPruning = true;
19 : inline const bool doRazoring = true;
20 : inline const bool doQFutility = false;
21 : inline const bool doQDeltaPruning = true;
22 : inline const bool doProbcut = true;
23 : inline const bool doHistoryPruning = true;
24 : inline const bool doCapHistoryPruning = true;
25 : inline const bool doCMHPruning = true;
26 : inline const bool doIID = false;
27 : inline const bool doIIR = true;
28 :
29 : enum CoeffNameType { CNT_init = 0, CNT_bonus, CNT_slopeD, CNT_slopeGP, CNT_minDepth, CNT_maxdepth };
30 :
31 : // Most often, N will be =2 for "evalScoreIsHashScore"
32 : // M will be =2 for an "improving" bonus
33 : template<size_t N_, size_t M_> struct Coeff {
34 : static constexpr size_t N {N_};
35 : static constexpr size_t M {M_};
36 : CONST_SEARCH_TUNING array1d<ScoreType, N> init;
37 : CONST_SEARCH_TUNING array1d<ScoreType, M> bonus;
38 : CONST_SEARCH_TUNING array1d<ScoreType, N> slopeDepth;
39 : CONST_SEARCH_TUNING array1d<ScoreType, N> slopeGamePhase;
40 : CONST_SEARCH_TUNING array1d<DepthType, N> minDepth;
41 : CONST_SEARCH_TUNING array1d<DepthType, N> maxDepth;
42 : const std::string name;
43 6396403 : [[nodiscard]] CONSTEXPR_SEARCH_TUNING ScoreType threshold(const DepthType d, const float gp, const size_t idx1 = 0, const size_t idx2 = 0) const {
44 6396403 : assert(idx1 < N);
45 6396403 : assert(idx2 < M);
46 6396403 : const auto value = init[idx1]
47 6396403 : + d * slopeDepth[idx1]
48 6396403 : + static_cast<double>(gp) * slopeGamePhase[idx1];
49 6396403 : assert(value > std::numeric_limits<ScoreType>::min());
50 6396403 : assert(value < std::numeric_limits<ScoreType>::max());
51 6396403 : return static_cast<ScoreType>(value * bonus[idx2] / 256.0);
52 : }
53 8870519 : [[nodiscard]] CONSTEXPR_SEARCH_TUNING bool isActive(const DepthType d, const size_t idx1 = 0) const {
54 8870519 : assert(idx1 < N);
55 8870519 : return d >= minDepth[idx1] && d <= maxDepth[idx1];
56 : }
57 : [[nodiscard]] FORCE_FINLINE std::string getName(CoeffNameType t, size_t idx)const{
58 : assert(t >= 0);
59 : assert(t <= CNT_maxdepth);
60 : static const array1d<std::string, 6> suffixes { "Init", "Bonus", "SlopeDepth", "SlopeGP", "MinDepth", "MaxDepth" };
61 : return name + suffixes[t] + std::to_string(idx);
62 : }
63 : };
64 :
65 : extern CONST_SEARCH_TUNING Coeff<2,2> staticNullMoveCoeff;
66 : extern CONST_SEARCH_TUNING Coeff<2,2> razoringCoeff;
67 : extern CONST_SEARCH_TUNING Coeff<2,2> threatCoeff;
68 : //extern CONST_SEARCH_TUNING Coeff<2,2> ownThreatCoeff;
69 : extern CONST_SEARCH_TUNING Coeff<2,2> historyPruningCoeff;
70 : extern CONST_SEARCH_TUNING Coeff<2,2> captureHistoryPruningCoeff;
71 : extern CONST_SEARCH_TUNING Coeff<2,2> futilityPruningCoeff;
72 : extern CONST_SEARCH_TUNING Coeff<2,2> failHighReductionCoeff;
73 :
74 : // first value if eval score is used, second if hash score is used
75 : extern CONST_SEARCH_TUNING colored<ScoreType> qfutilityMargin;
76 : extern CONST_SEARCH_TUNING DepthType nullMoveMinDepth;
77 : extern CONST_SEARCH_TUNING DepthType nullMoveVerifDepth;
78 : extern CONST_SEARCH_TUNING ScoreType nullMoveMargin;
79 : extern CONST_SEARCH_TUNING ScoreType nullMoveMargin2;
80 : extern CONST_SEARCH_TUNING ScoreType nullMoveReductionDepthDivisor;
81 : extern CONST_SEARCH_TUNING ScoreType nullMoveReductionInit;
82 : extern CONST_SEARCH_TUNING ScoreType nullMoveDynamicDivisor;
83 : extern CONST_SEARCH_TUNING ScoreType historyExtensionThreshold;
84 : extern CONST_SEARCH_TUNING colored<DepthType> CMHMaxDepth;
85 : //extern CONST_SEARCH_TUNING ScoreType randomAggressiveReductionFactor;
86 : extern CONST_SEARCH_TUNING DepthType iidMinDepth;
87 : extern CONST_SEARCH_TUNING DepthType iidMinDepth2;
88 : extern CONST_SEARCH_TUNING DepthType iidMinDepth3;
89 : extern CONST_SEARCH_TUNING DepthType probCutMinDepth;
90 : extern CONST_SEARCH_TUNING DepthType probCutSearchDepthFactor;
91 : extern CONST_SEARCH_TUNING int probCutMaxMoves;
92 : extern CONST_SEARCH_TUNING ScoreType probCutMargin;
93 : extern CONST_SEARCH_TUNING ScoreType probCutMarginSlope;
94 : extern CONST_SEARCH_TUNING ScoreType seeCaptureFactor;
95 : extern CONST_SEARCH_TUNING ScoreType seeCaptureInit;
96 : extern CONST_SEARCH_TUNING ScoreType seeCapDangerDivisor;
97 : extern CONST_SEARCH_TUNING ScoreType seeQuietFactor;
98 : extern CONST_SEARCH_TUNING ScoreType seeQuietInit;
99 : extern CONST_SEARCH_TUNING ScoreType seeQuietDangerDivisor;
100 : extern CONST_SEARCH_TUNING ScoreType seeQThreshold;
101 : extern CONST_SEARCH_TUNING ScoreType betaMarginDynamicHistory;
102 : //extern CONST_SEARCH_TUNING ScoreType probCutThreshold;
103 : extern CONST_SEARCH_TUNING DepthType lmrMinDepth;
104 : extern CONST_SEARCH_TUNING int lmrCapHistoryFactor;
105 : extern CONST_SEARCH_TUNING ScoreType lmrLateExtensionMargin;
106 : extern CONST_SEARCH_TUNING DepthType singularExtensionDepth;
107 : extern CONST_SEARCH_TUNING DepthType singularExtensionDepthMinus;
108 : ///@todo on move / opponent
109 : extern CONST_SEARCH_TUNING ScoreType dangerLimitPruning;
110 : extern CONST_SEARCH_TUNING ScoreType dangerLimitForwardPruning;
111 : extern CONST_SEARCH_TUNING ScoreType dangerLimitReduction;
112 : extern CONST_SEARCH_TUNING ScoreType dangerDivisor;
113 : extern CONST_SEARCH_TUNING ScoreType failLowRootMargin;
114 : extern CONST_SEARCH_TUNING ScoreType CMHMargin;
115 :
116 : extern CONST_SEARCH_TUNING ScoreType deltaBadMargin;
117 : extern CONST_SEARCH_TUNING ScoreType deltaBadSEEThreshold;
118 : extern CONST_SEARCH_TUNING ScoreType deltaGoodMargin;
119 : extern CONST_SEARCH_TUNING ScoreType deltaGoodSEEThreshold;
120 :
121 : extern CONST_SEARCH_TUNING DepthType aspirationMinDepth;
122 : extern CONST_SEARCH_TUNING ScoreType aspirationInit;
123 : extern CONST_SEARCH_TUNING ScoreType aspirationDepthCoef;
124 : extern CONST_SEARCH_TUNING ScoreType aspirationDepthInit;
125 :
126 : extern CONST_SEARCH_TUNING DepthType ttMaxFiftyValideDepth;
127 :
128 : extern CONST_SEARCH_TUNING DepthType iirMinDepth;
129 : extern CONST_SEARCH_TUNING DepthType iirReduction;
130 :
131 : extern CONST_SEARCH_TUNING DepthType ttAlphaCutDepth;
132 : extern CONST_SEARCH_TUNING ScoreType ttAlphaCutMargin;
133 : extern CONST_SEARCH_TUNING DepthType ttBetaCutDepth;
134 : extern CONST_SEARCH_TUNING ScoreType ttBetaCutMargin;
135 :
136 : extern CONST_SEARCH_TUNING ScoreType lazySortThreshold;
137 : extern CONST_SEARCH_TUNING ScoreType lazySortThresholdQS;
138 :
139 : extern CONST_SEARCH_TUNING int distributedTTBufSize;
140 :
141 : extern CONST_SEARCH_TUNING int capPSTScoreDivisor;
142 : extern CONST_SEARCH_TUNING int capMMLVAMultiplicator;
143 : extern CONST_SEARCH_TUNING int capHistoryDivisor;
144 :
145 : extern CONST_SEARCH_TUNING int quietHistoryDivisor1;
146 : extern CONST_SEARCH_TUNING int quietHistoryDivisor2;
147 : extern CONST_SEARCH_TUNING int quietHistoryDivisor3;
148 :
149 : inline const DepthType lmpMaxDepth = 10;
150 : inline const array2d<int,2,SearchConfig::lmpMaxDepth+1> lmpLimit = {{{0, 2, 3, 5, 9, 13, 18, 25, 34, 45, 55}, {0, 5, 6, 9, 14, 21, 30, 41, 55, 69, 84}}};
151 :
152 : constexpr
153 : double my_log2(double x){
154 : int N = 1;
155 : while(x>=2){
156 : ++N;
157 : x/=2;
158 : }
159 : const double ln2 = 0.6931471805599453094172321214581765680755001343602552541206800094;
160 : const double y = (x-1)/(x+1);
161 : double v = 2*y;
162 : for (int k = 1 ; k < 10; ++k){
163 : double p = y;
164 : const int n = 2*k+1;
165 : for (int i = 1 ; i < n ; ++i){
166 : p *= y;
167 : }
168 : v += 2*p/n;
169 : }
170 : return v + (N-1)*ln2;
171 : }
172 :
173 : /*
174 : void test_log(){
175 : for (int d = 1; d < MAX_DEPTH; d++)
176 : for (int m = 1; m < MAX_MOVE; m++){
177 : std::cout << (my_log2(d * 1.6) * my_log2(m) * 0.4) << std::endl;
178 : std::cout << (std::log(d * 1.6) * std::log(m) * 0.4) << std::endl;
179 : }
180 : }
181 : */
182 :
183 : ///@todo try lmr based on game phase
184 : inline const array2d<DepthType, MAX_DEPTH, MAX_MOVE> lmrReduction = [] {
185 : auto ret = decltype(lmrReduction){};
186 : //Logging::LogIt(Logging::logInfo) << "Init lmr";
187 : for (int d = 1; d < MAX_DEPTH; d++)
188 : for (int m = 1; m < MAX_MOVE; m++)
189 : ret[d][m] = DepthType(my_log2(d * 1.6) * my_log2(m * 1) * 0.4);
190 : return ret;
191 : }();
192 :
193 : inline const array2d<ScoreType, 6, 6> MvvLvaScores = [] {
194 : auto ret = decltype(MvvLvaScores){};
195 : //Logging::LogIt(Logging::logInfo) << "Init mvv-lva";
196 : constexpr array1d<ScoreType, 6> IValues = {1, 2, 3, 5, 9, 20}; ///@todo try N=B=3 ??
197 : for (int v = 0; v < 6; ++v)
198 : for (int a = 0; a < 6; ++a) ret[v][a] = static_cast<ScoreType>(IValues[v] * 20 - IValues[a]);
199 : return ret;
200 : }();
201 :
202 : } // namespace SearchConfig
|