1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-29 16:23:09 +00:00

Use std::abs over abs

closes https://github.com/official-stockfish/Stockfish/pull/4926
closes https://github.com/official-stockfish/Stockfish/pull/4909

No functional change

Co-Authored-By: fffelix-huang <72808219+fffelix-huang@users.noreply.github.com>
This commit is contained in:
FauziAkram 2023-12-18 16:20:41 +03:00 committed by Disservin
parent 07a2619b62
commit a069a1bbbf
7 changed files with 20 additions and 16 deletions

View file

@ -214,6 +214,7 @@ Taras Vuk (TarasVuk)
Thanar2
thaspel
theo77186
Ting-Hsuan Huang (fffelix-huang)
Tomasz Sobczyk (Sopel97)
Tom Truscott
Tom Vijlbrief (tomtor)

View file

@ -20,6 +20,7 @@
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iomanip>
@ -164,9 +165,9 @@ Value Eval::evaluate(const Position& pos) {
int shuffling = pos.rule50_count();
int simpleEval = simple_eval(pos, stm) + (int(pos.key() & 7) - 3);
bool lazy = abs(simpleEval) >= RookValue + KnightValue + 16 * shuffling * shuffling
+ abs(pos.this_thread()->bestValue)
+ abs(pos.this_thread()->rootSimpleEval);
bool lazy = std::abs(simpleEval) >= RookValue + KnightValue + 16 * shuffling * shuffling
+ std::abs(pos.this_thread()->bestValue)
+ std::abs(pos.this_thread()->rootSimpleEval);
if (lazy)
v = Value(simpleEval);
@ -178,8 +179,8 @@ Value Eval::evaluate(const Position& pos) {
Value optimism = pos.this_thread()->optimism[stm];
// Blend optimism and eval with nnue complexity and material imbalance
optimism += optimism * (nnueComplexity + abs(simpleEval - nnue)) / 512;
nnue -= nnue * (nnueComplexity + abs(simpleEval - nnue)) / 32768;
optimism += optimism * (nnueComplexity + std::abs(simpleEval - nnue)) / 512;
nnue -= nnue * (nnueComplexity + std::abs(simpleEval - nnue)) / 32768;
int npm = pos.non_pawn_material() / 64;
v = (nnue * (915 + npm + 9 * pos.count<PAWN>()) + optimism * (154 + npm)) / 1024;

View file

@ -21,6 +21,7 @@
#include <array>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <limits>
@ -55,12 +56,12 @@ class StatsEntry {
operator const T&() const { return entry; }
void operator<<(int bonus) {
assert(abs(bonus) <= D); // Ensure range is [-D, D]
assert(std::abs(bonus) <= D); // Ensure range is [-D, D]
static_assert(D <= std::numeric_limits<T>::max(), "D overflows T");
entry += bonus - entry * abs(bonus) / D;
entry += bonus - entry * std::abs(bonus) / D;
assert(abs(entry) <= D);
assert(std::abs(entry) <= D);
}
};

View file

@ -180,7 +180,7 @@ Value evaluate(const Position& pos, bool adjusted, int* complexity) {
const auto positional = network[bucket]->propagate(transformedFeatures);
if (complexity)
*complexity = abs(psqt - positional) / OutputScale;
*complexity = std::abs(psqt - positional) / OutputScale;
// Give more value to positional evaluation when adjusted flag is set
if (adjusted)

View file

@ -847,7 +847,7 @@ Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, boo
// much above beta, we can (almost) safely prune the previous move.
if (
!PvNode && depth > 3
&& abs(beta) < VALUE_TB_WIN_IN_MAX_PLY
&& std::abs(beta) < VALUE_TB_WIN_IN_MAX_PLY
// If value from transposition table is lower than probCutBeta, don't attempt probCut
// there and in further interactions with transposition table cutoff depth is set to depth - 3
// because probCut search has depth set to depth - 4 but we also do a move before it
@ -901,7 +901,7 @@ moves_loop: // When in check, search starts here
probCutBeta = beta + 425;
if (ss->inCheck && !PvNode && ttCapture && (tte->bound() & BOUND_LOWER)
&& tte->depth() >= depth - 4 && ttValue >= probCutBeta
&& abs(ttValue) < VALUE_TB_WIN_IN_MAX_PLY && abs(beta) < VALUE_TB_WIN_IN_MAX_PLY)
&& std::abs(ttValue) < VALUE_TB_WIN_IN_MAX_PLY && std::abs(beta) < VALUE_TB_WIN_IN_MAX_PLY)
return probCutBeta;
const PieceToHistory* contHist[] = {(ss - 1)->continuationHistory,
@ -1042,7 +1042,7 @@ moves_loop: // When in check, search starts here
// Recursive singular search is avoided.
if (!rootNode && move == ttMove && !excludedMove
&& depth >= 4 - (thisThread->completedDepth > 27) + 2 * (PvNode && tte->is_pv())
&& abs(ttValue) < VALUE_TB_WIN_IN_MAX_PLY && (tte->bound() & BOUND_LOWER)
&& std::abs(ttValue) < VALUE_TB_WIN_IN_MAX_PLY && (tte->bound() & BOUND_LOWER)
&& tte->depth() >= depth - 3)
{
Value singularBeta = ttValue - (66 + 58 * (ss->ttPv && !PvNode)) * depth / 64;
@ -1890,7 +1890,7 @@ string UCI::pv(const Position& pos, Depth depth) {
if (v == -VALUE_INFINITE)
v = VALUE_ZERO;
bool tb = TB::RootInTB && abs(v) <= VALUE_TB;
bool tb = TB::RootInTB && std::abs(v) <= VALUE_TB;
v = tb ? rootMoves[i].tbScore : v;
if (ss.rdbuf()->in_avail()) // Not at first line

View file

@ -20,6 +20,7 @@
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <initializer_list>
@ -235,7 +236,7 @@ Thread* ThreadPool::get_best_thread() const {
votes[th->rootMoves[0].pv[0]] += thread_value(th);
for (Thread* th : threads)
if (abs(bestThread->rootMoves[0].score) >= VALUE_TB_WIN_IN_MAX_PLY)
if (std::abs(bestThread->rootMoves[0].score) >= VALUE_TB_WIN_IN_MAX_PLY)
{
// Make sure we pick the shortest mate / TB conversion or stave off mate the longest
if (th->rootMoves[0].score > bestThread->rootMoves[0].score)

View file

@ -354,9 +354,9 @@ std::string UCI::value(Value v) {
std::stringstream ss;
if (abs(v) < VALUE_TB_WIN_IN_MAX_PLY)
if (std::abs(v) < VALUE_TB_WIN_IN_MAX_PLY)
ss << "cp " << UCI::to_cp(v);
else if (abs(v) <= VALUE_TB)
else if (std::abs(v) <= VALUE_TB)
{
const int ply = VALUE_TB - std::abs(v); // recompute ss->ply
ss << "cp " << (v > 0 ? 20000 - ply : -20000 + ply);