Skip to content

Commit 1b947aa

Browse files
committed
Convert Reductions[] from int8_t to Depth
This is the type anyhow. Assorted cleanup while there. No functional change.
1 parent f6f1d24 commit 1b947aa

1 file changed

Lines changed: 31 additions & 36 deletions

File tree

src/search.cpp

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,29 @@ namespace {
6666
// Different node types, used as template parameter
6767
enum NodeType { Root, PV, NonPV };
6868

69-
// Dynamic razoring margin based on depth
69+
// Razoring and futility margin based on depth
7070
inline Value razor_margin(Depth d) { return Value(512 + 32 * d); }
71+
inline Value futility_margin(Depth d) { return Value(200 * d); }
7172

72-
// Futility lookup tables (initialized at startup) and their access functions
73-
int FutilityMoveCounts[2][16]; // [improving][depth]
73+
// Futility and reductions lookup tables, initialized at startup
74+
int FutilityMoveCounts[2][16]; // [improving][depth]
75+
Depth Reductions[2][2][64][64]; // [pv][improving][depth][moveNumber]
7476

75-
inline Value futility_margin(Depth d) {
76-
return Value(200 * d);
77+
template <bool PvNode> inline Depth reduction(bool i, Depth d, int mn) {
78+
return Reductions[PvNode][i][std::min(d, 63 * ONE_PLY)][std::min(mn, 63)];
7779
}
7880

79-
// Reduction lookup tables (initialized at startup) and their access function
80-
int8_t Reductions[2][2][64][64]; // [pv][improving][depth][moveNumber]
81+
// Skill struct is used to implement strength limiting
82+
struct Skill {
83+
Skill(int l) : level(l) {}
84+
bool enabled() const { return level < 20; }
85+
bool time_to_pick(Depth depth) const { return depth / ONE_PLY == 1 + level; }
86+
Move best_move(size_t multiPV) { return best ? best : pick_best(multiPV); }
87+
Move pick_best(size_t multiPV);
8188

82-
template <bool PvNode> inline Depth reduction(bool i, Depth d, int mn) {
83-
return (Depth) Reductions[PvNode][i][std::min(int(d), 63)][std::min(mn, 63)];
84-
}
89+
int level;
90+
Move best = MOVE_NONE;
91+
};
8592

8693
size_t PVIdx;
8794
TimeManager TimeMgr;
@@ -104,43 +111,30 @@ namespace {
104111
void update_stats(const Position& pos, Stack* ss, Move move, Depth depth, Move* quiets, int quietsCnt);
105112
string uci_pv(const Position& pos, Depth depth, Value alpha, Value beta);
106113

107-
struct Skill {
108-
Skill(int l) : level(l) {}
109-
bool enabled() const { return level < 20; }
110-
bool time_to_pick(Depth depth) const { return depth / ONE_PLY == 1 + level; }
111-
Move best_move(size_t multiPV) { return best ? best : pick_best(multiPV); }
112-
Move pick_best(size_t multiPV);
113-
114-
int level;
115-
Move best = MOVE_NONE;
116-
};
117-
118114
} // namespace
119115

120116

121117
/// Search::init() is called during startup to initialize various lookup tables
122118

123119
void Search::init() {
124120

125-
// Init reductions array
126-
for (int d = 1; d < 64; ++d)
127-
for (int mc = 1; mc < 64; ++mc)
128-
{
129-
double pvRed = 0.00 + log(double(d)) * log(double(mc)) / 3.00;
130-
double nonPVRed = 0.33 + log(double(d)) * log(double(mc)) / 2.25;
121+
const double K[][2] = {{ 0.83, 2.25 }, { 0.50, 3.00 }};
131122

132-
Reductions[1][1][d][mc] = int8_t( pvRed >= 1.0 ? pvRed + 0.5: 0);
133-
Reductions[0][1][d][mc] = int8_t(nonPVRed >= 1.0 ? nonPVRed + 0.5: 0);
123+
for (int pv = 0; pv <= 1; ++pv)
124+
for (int imp = 0; imp <= 1; ++imp)
125+
for (int d = 1; d < 64; ++d)
126+
for (int mc = 1; mc < 64; ++mc)
127+
{
128+
double r = K[pv][0] + log(d) * log(mc) / K[pv][1];
134129

135-
Reductions[1][0][d][mc] = Reductions[1][1][d][mc];
136-
Reductions[0][0][d][mc] = Reductions[0][1][d][mc];
130+
if (r >= 1.5)
131+
Reductions[pv][imp][d][mc] = int(r) * ONE_PLY;
137132

138-
// Increase reduction when eval is not improving
139-
if (Reductions[0][0][d][mc] >= 2)
140-
Reductions[0][0][d][mc] += 1;
141-
}
133+
// Increase reduction when eval is not improving
134+
if (!pv && !imp && Reductions[pv][imp][d][mc] >= 2 * ONE_PLY)
135+
Reductions[pv][imp][d][mc] += ONE_PLY;
136+
}
142137

143-
// Init futility move count array
144138
for (int d = 0; d < 16; ++d)
145139
{
146140
FutilityMoveCounts[0][d] = int(2.4 + 0.773 * pow(d + 0.00, 1.8));
@@ -1351,6 +1345,7 @@ namespace {
13511345
// played quiet moves.
13521346
Value bonus = Value((depth / ONE_PLY) * (depth / ONE_PLY));
13531347
History.update(pos.moved_piece(move), to_sq(move), bonus);
1348+
13541349
for (int i = 0; i < quietsCnt; ++i)
13551350
{
13561351
Move m = quiets[i];

0 commit comments

Comments
 (0)