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

Retire value.cpp

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2010-07-15 11:00:20 +02:00
parent 605b3aedd5
commit bc0c1c8d7b
3 changed files with 54 additions and 115 deletions

View file

@ -291,6 +291,8 @@ namespace {
bool connected_moves(const Position& pos, Move m1, Move m2);
bool value_is_mate(Value value);
Value value_to_tt(Value v, int ply);
Value value_from_tt(Value v, int ply);
bool move_is_killer(Move m, SearchStack* ss);
bool ok_to_use_TT(const TTEntry* tte, Depth depth, Value beta, int ply);
bool connected_threat(const Position& pos, Move m, Move threat);
@ -300,6 +302,7 @@ namespace {
void update_gains(const Position& pos, Move move, Value before, Value after);
int current_search_time();
std::string value_to_uci(Value v);
int nps();
void poll();
void ponderhit();
@ -584,7 +587,7 @@ namespace {
// so to output information also for iteration 1.
cout << "info depth " << 1
<< "\ninfo depth " << 1
<< " score " << value_to_string(rml.get_move_score(0))
<< " score " << value_to_uci(rml.get_move_score(0))
<< " time " << current_search_time()
<< " nodes " << TM.nodes_searched()
<< " nps " << nps()
@ -960,7 +963,7 @@ namespace {
for (int j = 0; j < Min(MultiPV, rml.move_count()); j++)
{
cout << "info multipv " << j + 1
<< " score " << value_to_string(rml.get_move_score(j))
<< " score " << value_to_uci(rml.get_move_score(j))
<< " depth " << (j <= i ? Iteration : Iteration - 1)
<< " time " << current_search_time()
<< " nodes " << TM.nodes_searched()
@ -1824,8 +1827,8 @@ namespace {
}
// value_is_mate() checks if the given value is a mate one
// eventually compensated for the ply.
// value_is_mate() checks if the given value is a mate one eventually
// compensated for the ply.
bool value_is_mate(Value value) {
@ -1836,8 +1839,38 @@ namespace {
}
// move_is_killer() checks if the given move is among the
// killer moves of that ply.
// value_to_tt() adjusts a mate score from "plies to mate from the root" to
// "plies to mate from the current ply". Non-mate scores are unchanged.
// The function is called before storing a value to the transposition table.
Value value_to_tt(Value v, int ply) {
if (v >= value_mate_in(PLY_MAX))
return v + ply;
if (v <= value_mated_in(PLY_MAX))
return v - ply;
return v;
}
// value_from_tt() is the inverse of value_to_tt(): It adjusts a mate score from
// the transposition table to a mate score corrected for the current ply.
Value value_from_tt(Value v, int ply) {
if (v >= value_mate_in(PLY_MAX))
return v - ply;
if (v <= value_mated_in(PLY_MAX))
return v + ply;
return v;
}
// move_is_killer() checks if the given move is among the killer moves
bool move_is_killer(Move m, SearchStack* ss) {
@ -2052,6 +2085,20 @@ namespace {
}
// value_to_uci() converts a value to a string suitable for use with the UCI protocol
std::string value_to_uci(Value v) {
std::stringstream s;
if (abs(v) < VALUE_MATE - PLY_MAX * OnePly)
s << "cp " << int(v) * 100 / int(PawnValueMidgame); // Scale to pawn = 100
else
s << "mate " << (v > 0 ? (VALUE_MATE - v + 1) / 2 : -(VALUE_MATE + v) / 2 );
return s.str();
}
// nps() computes the current nodes/second count.
int nps() {
@ -2209,7 +2256,7 @@ namespace {
void print_pv_info(const Position& pos, Move pv[], Value alpha, Value beta, Value value) {
cout << "info depth " << Iteration
<< " score " << value_to_string(value)
<< " score " << value_to_uci(value)
<< (value >= beta ? " lowerbound" : value <= alpha ? " upperbound" : "")
<< " time " << current_search_time()
<< " nodes " << TM.nodes_searched()

View file

@ -1,96 +0,0 @@
/*
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
Stockfish is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Stockfish is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////
//// Includes
////
#include <sstream>
#include <string>
#include "value.h"
////
//// Functions
////
/// value_to_tt() adjusts a mate score from "plies to mate from the root" to
/// "plies to mate from the current ply". Non-mate scores are unchanged.
/// The function is called before storing a value to the transposition table.
Value value_to_tt(Value v, int ply) {
if(v >= value_mate_in(100))
return v + ply;
else if(v <= value_mated_in(100))
return v - ply;
else
return v;
}
/// value_from_tt() is the inverse of value_to_tt(): It adjusts a mate score
/// from the transposition table to a mate score corrected for the current
/// ply depth.
Value value_from_tt(Value v, int ply) {
if(v >= value_mate_in(100))
return v - ply;
else if(v <= value_mated_in(100))
return v + ply;
else
return v;
}
/// value_to_centipawns() converts a value from Stockfish's somewhat unusual
/// scale of pawn = 256 to the more conventional pawn = 100.
int value_to_centipawns(Value v) {
return (int(v) * 100) / int(PawnValueMidgame);
}
/// value_from_centipawns() converts a centipawn value to Stockfish's internal
/// evaluation scale. It's used when reading the values of UCI options
/// containing material values (e.g. futility pruning margins).
Value value_from_centipawns(int cp) {
return Value((cp * 256) / 100);
}
/// value_to_string() converts a value to a string suitable for use with the
/// UCI protocol.
const std::string value_to_string(Value v) {
std::stringstream s;
if(abs(v) < VALUE_MATE - 200)
s << "cp " << value_to_centipawns(v);
else {
s << "mate ";
if(v > 0)
s << (VALUE_MATE - v + 1) / 2;
else
s << -(VALUE_MATE + v) / 2;
}
return s.str();
}

View file

@ -190,16 +190,4 @@ inline Value piece_value_endgame(Piece p) {
return PieceValueEndgame[p];
}
////
//// Prototypes
////
extern Value value_to_tt(Value v, int ply);
extern Value value_from_tt(Value v, int ply);
extern int value_to_centipawns(Value v);
extern Value value_from_centipawns(int cp);
extern const std::string value_to_string(Value v);
#endif // !defined(VALUE_H_INCLUDED)