/*1Stockfish, a UCI chess playing engine derived from Glaurung 2.12Copyright (C) 2004-2025 The Stockfish developers (see AUTHORS file)34Stockfish is free software: you can redistribute it and/or modify5it under the terms of the GNU General Public License as published by6the Free Software Foundation, either version 3 of the License, or7(at your option) any later version.89Stockfish is distributed in the hope that it will be useful,10but WITHOUT ANY WARRANTY; without even the implied warranty of11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12GNU General Public License for more details.1314You should have received a copy of the GNU General Public License15along with this program. If not, see <http://www.gnu.org/licenses/>.16*/1718#include "score.h"1920#include <cassert>21#include <cmath>22#include <cstdlib>2324#include "uci.h"2526namespace Stockfish {2728Score::Score(Value v, const Position& pos) {29assert(-VALUE_INFINITE < v && v < VALUE_INFINITE);3031if (!is_decisive(v))32{33score = InternalUnits{UCIEngine::to_cp(v, pos)};34}35else if (std::abs(v) <= VALUE_TB)36{37auto distance = VALUE_TB - std::abs(v);38score = (v > 0) ? Tablebase{distance, true} : Tablebase{-distance, false};39}40else41{42auto distance = VALUE_MATE - std::abs(v);43score = (v > 0) ? Mate{distance} : Mate{-distance};44}45}4647}4849