Skip to content

Commit 2c52147

Browse files
lucasartglinscott
authored andcommitted
Introduce ratio operation
Just like in Physics, the ratio of 2 things in the same unit, should be without unit. Example use case: - Ratio of a Depth by a Depth (eg. ONE_PLY) should be an int. - Ratio of a Value by a Value (eg. PawnValueEg) should be an int. Remove a bunch of useless const while there. No functional change. Resolves #128
1 parent 7caa6cd commit 2c52147

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/search.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ namespace {
112112
}
113113

114114
size_t candidates_size() const { return candidates; }
115-
bool time_to_pick(Depth depth) const { return depth == 1 + level; }
115+
bool time_to_pick(Depth depth) const { return depth / ONE_PLY == 1 + level; }
116116
Move pick_move();
117117

118118
int level;
@@ -660,7 +660,7 @@ namespace {
660660
assert(eval - beta >= 0);
661661

662662
// Null move dynamic reduction based on depth and value
663-
Depth R = (3 + depth / 4 + std::min(int(eval - beta) / PawnValueMg, 3)) * ONE_PLY;
663+
Depth R = (3 + depth / 4 + std::min((eval - beta) / PawnValueMg, 3)) * ONE_PLY;
664664

665665
pos.do_null_move(st);
666666
(ss+1)->skipNullMove = true;
@@ -793,7 +793,7 @@ namespace {
793793
Signals.firstRootMove = (moveCount == 1);
794794

795795
if (thisThread == Threads.main() && Time::now() - SearchTime > 3000)
796-
sync_cout << "info depth " << depth
796+
sync_cout << "info depth " << depth / ONE_PLY
797797
<< " currmove " << UCI::format_move(move, pos.is_chess960())
798798
<< " currmovenumber " << moveCount + PVIdx << sync_endl;
799799
}
@@ -826,7 +826,7 @@ namespace {
826826
&& !ext
827827
&& pos.legal(move, ci.pinned))
828828
{
829-
Value rBeta = ttValue - int(2 * depth);
829+
Value rBeta = ttValue - 2 * depth / ONE_PLY;
830830
ss->excludedMove = move;
831831
ss->skipNullMove = true;
832832
value = search<NonPV, false>(pos, ss, rBeta - 1, rBeta, depth / 2, cutNode);
@@ -1362,7 +1362,7 @@ namespace {
13621362

13631363
// Increase history value of the cut-off move and decrease all the other
13641364
// played quiet moves.
1365-
Value bonus = Value(int(depth) * int(depth));
1365+
Value bonus = Value((depth / ONE_PLY) * (depth / ONE_PLY));
13661366
History.update(pos.moved_piece(move), to_sq(move), bonus);
13671367
for (int i = 0; i < quietsCnt; ++i)
13681368
{
@@ -1445,7 +1445,7 @@ namespace {
14451445
{
14461446
bool updated = (i <= PVIdx);
14471447

1448-
if (depth == 1 && !updated)
1448+
if (depth == ONE_PLY && !updated)
14491449
continue;
14501450

14511451
Depth d = updated ? depth : depth - ONE_PLY;

src/types.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -275,23 +275,24 @@ inline Value eg_value(Score s) {
275275
return Value((int)(unsigned(s) & 0x7FFFU) - (int)(unsigned(s) & 0x8000U));
276276
}
277277

278-
#define ENABLE_BASE_OPERATORS_ON(T) \
279-
inline T operator+(const T d1, const T d2) { return T(int(d1) + int(d2)); } \
280-
inline T operator-(const T d1, const T d2) { return T(int(d1) - int(d2)); } \
281-
inline T operator*(int i, const T d) { return T(i * int(d)); } \
282-
inline T operator*(const T d, int i) { return T(int(d) * i); } \
283-
inline T operator-(const T d) { return T(-int(d)); } \
284-
inline T& operator+=(T& d1, const T d2) { return d1 = d1 + d2; } \
285-
inline T& operator-=(T& d1, const T d2) { return d1 = d1 - d2; } \
278+
#define ENABLE_BASE_OPERATORS_ON(T) \
279+
inline T operator+(T d1, T d2) { return T(int(d1) + int(d2)); } \
280+
inline T operator-(T d1, T d2) { return T(int(d1) - int(d2)); } \
281+
inline T operator*(int i, T d) { return T(i * int(d)); } \
282+
inline T operator*(T d, int i) { return T(int(d) * i); } \
283+
inline T operator-(T d) { return T(-int(d)); } \
284+
inline T& operator+=(T& d1, T d2) { return d1 = d1 + d2; } \
285+
inline T& operator-=(T& d1, T d2) { return d1 = d1 - d2; } \
286286
inline T& operator*=(T& d, int i) { return d = T(int(d) * i); }
287287

288288
ENABLE_BASE_OPERATORS_ON(Score)
289289

290-
#define ENABLE_FULL_OPERATORS_ON(T) \
291-
ENABLE_BASE_OPERATORS_ON(T) \
292-
inline T& operator++(T& d) { return d = T(int(d) + 1); } \
293-
inline T& operator--(T& d) { return d = T(int(d) - 1); } \
294-
inline T operator/(const T d, int i) { return T(int(d) / i); } \
290+
#define ENABLE_FULL_OPERATORS_ON(T) \
291+
ENABLE_BASE_OPERATORS_ON(T) \
292+
inline T& operator++(T& d) { return d = T(int(d) + 1); } \
293+
inline T& operator--(T& d) { return d = T(int(d) - 1); } \
294+
inline T operator/(T d, int i) { return T(int(d) / i); } \
295+
inline int operator/(T d1, T d2) { return int(d1) / int(d2); } \
295296
inline T& operator/=(T& d, int i) { return d = T(int(d) / i); }
296297

297298
ENABLE_FULL_OPERATORS_ON(Value)

0 commit comments

Comments
 (0)