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