2 Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3 Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
4 Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
6 Stockfish is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Stockfish is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
35 /// value_to_tt() adjusts a mate score from "plies to mate from the root" to
36 /// "plies to mate from the current ply". Non-mate scores are unchanged.
37 /// The function is called before storing a value to the transposition table.
39 Value value_to_tt(Value v, int ply) {
40 if(v >= value_mate_in(100))
42 else if(v <= value_mated_in(100))
49 /// value_from_tt() is the inverse of value_to_tt(): It adjusts a mate score
50 /// from the transposition table to a mate score corrected for the current
53 Value value_from_tt(Value v, int ply) {
54 if(v >= value_mate_in(100))
56 else if(v <= value_mated_in(100))
63 /// value_to_centipawns() converts a value from Stockfish's somewhat unusual
64 /// scale of pawn = 256 to the more conventional pawn = 100.
66 int value_to_centipawns(Value v) {
67 return (int(v) * 100) / int(PawnValueMidgame);
71 /// value_from_centipawns() converts a centipawn value to Stockfish's internal
72 /// evaluation scale. It's used when reading the values of UCI options
73 /// containing material values (e.g. futility pruning margins).
75 Value value_from_centipawns(int cp) {
76 return Value((cp * 256) / 100);
80 /// value_to_string() converts a value to a string suitable for use with the
83 const std::string value_to_string(Value v) {
86 if(abs(v) < VALUE_MATE - 200)
87 s << "cp " << value_to_centipawns(v);
91 s << (VALUE_MATE - v + 1) / 2;
93 s << -(VALUE_MATE + v) / 2;