Skip to content

Commit

Permalink
Rename UciHandler to UCI
Browse files Browse the repository at this point in the history
  • Loading branch information
Disservin committed Jan 8, 2024
1 parent 4fc8077 commit 61f3ade
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/evaluate.cpp
Expand Up @@ -246,11 +246,11 @@ std::string Eval::trace(Position& pos, Search::Worker& workerThread) {
Value v;
v = NNUE::evaluate<NNUE::Big>(pos, false);
v = pos.side_to_move() == WHITE ? v : -v;
ss << "NNUE evaluation " << 0.01 * UciHandler::to_cp(v) << " (white side)\n";
ss << "NNUE evaluation " << 0.01 * UCI::to_cp(v) << " (white side)\n";

v = evaluate(pos, workerThread);
v = pos.side_to_move() == WHITE ? v : -v;
ss << "Final evaluation " << 0.01 * UciHandler::to_cp(v) << " (white side)";
ss << "Final evaluation " << 0.01 * UCI::to_cp(v) << " (white side)";
ss << " [with scaled NNUE, ...]";
ss << "\n";

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Expand Up @@ -33,7 +33,7 @@ int main(int argc, char* argv[]) {

std::cout << engine_info() << std::endl;

UciHandler uci(argc, argv);
UCI uci(argc, argv);

Tune::init(uci.options);
Bitboards::init();
Expand Down
4 changes: 2 additions & 2 deletions src/nnue/evaluate_nnue.cpp
Expand Up @@ -284,7 +284,7 @@ static void format_cp_compact(Value v, char* buffer) {

buffer[0] = (v < 0 ? '-' : v > 0 ? '+' : ' ');

int cp = std::abs(UciHandler::to_cp(v));
int cp = std::abs(UCI::to_cp(v));
if (cp >= 10000)
{
buffer[1] = '0' + cp / 10000;
Expand Down Expand Up @@ -318,7 +318,7 @@ static void format_cp_compact(Value v, char* buffer) {
// Converts a Value into pawns, always keeping two decimals
static void format_cp_aligned_dot(Value v, std::stringstream& stream) {

const double pawns = std::abs(0.01 * UciHandler::to_cp(v));
const double pawns = std::abs(0.01 * UCI::to_cp(v));

stream << (v < 0 ? '-'
: v > 0 ? '+'
Expand Down
6 changes: 3 additions & 3 deletions src/position.cpp
Expand Up @@ -77,7 +77,7 @@ std::ostream& operator<<(std::ostream& os, const Position& pos) {
<< std::setw(16) << pos.key() << std::setfill(' ') << std::dec << "\nCheckers: ";

for (Bitboard b = pos.checkers(); b;)
os << UciHandler::square(pop_lsb(b)) << " ";
os << UCI::square(pop_lsb(b)) << " ";

if (int(Tablebases::MaxCardinality) >= popcount(pos.pieces()) && !pos.can_castle(ANY_CASTLING))
{
Expand Down Expand Up @@ -431,8 +431,8 @@ string Position::fen() const {
if (!can_castle(ANY_CASTLING))
ss << '-';

ss << (ep_square() == SQ_NONE ? " - " : " " + UciHandler::square(ep_square()) + " ")
<< st->rule50 << " " << 1 + (gamePly - (sideToMove == BLACK)) / 2;
ss << (ep_square() == SQ_NONE ? " - " : " " + UCI::square(ep_square()) + " ") << st->rule50
<< " " << 1 + (gamePly - (sideToMove == BLACK)) / 2;

return ss.str();
}
Expand Down
30 changes: 14 additions & 16 deletions src/search.cpp
Expand Up @@ -162,7 +162,7 @@ uint64_t perft(Position& pos, Depth depth) {
pos.undo_move(m);
}
if (Root)
sync_cout << UciHandler::move(m, pos.is_chess960()) << ": " << cnt << sync_endl;
sync_cout << UCI::move(m, pos.is_chess960()) << ": " << cnt << sync_endl;
}
return nodes;
}
Expand Down Expand Up @@ -198,7 +198,7 @@ void Search::Worker::start_searching() {
{
rootMoves.emplace_back(Move::none());
sync_cout << "info depth 0 score "
<< UciHandler::value(rootPos.checkers() ? -VALUE_MATE : VALUE_DRAW) << sync_endl;
<< UCI::value(rootPos.checkers() ? -VALUE_MATE : VALUE_DRAW) << sync_endl;
}
else
{
Expand Down Expand Up @@ -240,18 +240,16 @@ void Search::Worker::start_searching() {

// Send again PV info if we have a new best thread
if (bestThread != this)
sync_cout << UciHandler::pv(
*bestThread, main_manager()->tm.elapsed(threads.nodes_searched()),
threads.nodes_searched(), threads.tb_hits(), tt.hashfull(), TB::RootInTB)
sync_cout << UCI::pv(*bestThread, main_manager()->tm.elapsed(threads.nodes_searched()),
threads.nodes_searched(), threads.tb_hits(), tt.hashfull(),
TB::RootInTB)
<< sync_endl;

sync_cout << "bestmove "
<< UciHandler::move(bestThread->rootMoves[0].pv[0], rootPos.is_chess960());
sync_cout << "bestmove " << UCI::move(bestThread->rootMoves[0].pv[0], rootPos.is_chess960());

if (bestThread->rootMoves[0].pv.size() > 1
|| bestThread->rootMoves[0].extract_ponder_from_tt(tt, rootPos))
std::cout << " ponder "
<< UciHandler::move(bestThread->rootMoves[0].pv[1], rootPos.is_chess960());
std::cout << " ponder " << UCI::move(bestThread->rootMoves[0].pv[1], rootPos.is_chess960());

std::cout << sync_endl;
}
Expand Down Expand Up @@ -384,9 +382,9 @@ void Search::Worker::iterative_deepening() {
// the UI) before a re-search.
if (mainThread && multiPV == 1 && (iterBestValue <= alpha || iterBestValue >= beta)
&& mainThread->tm.elapsed(threads.nodes_searched()) > 3000)
sync_cout << UciHandler::pv(
*this, mainThread->tm.elapsed(threads.nodes_searched()),
threads.nodes_searched(), threads.tb_hits(), tt.hashfull(), TB::RootInTB)
sync_cout << UCI::pv(*this, mainThread->tm.elapsed(threads.nodes_searched()),
threads.nodes_searched(), threads.tb_hits(), tt.hashfull(),
TB::RootInTB)
<< sync_endl;

// In case of failing low/high increase aspiration window and
Expand Down Expand Up @@ -419,9 +417,9 @@ void Search::Worker::iterative_deepening() {
if (mainThread
&& (threads.stop || pvIdx + 1 == multiPV
|| mainThread->tm.elapsed(threads.nodes_searched()) > 3000))
sync_cout << UciHandler::pv(*this, mainThread->tm.elapsed(threads.nodes_searched()),
threads.nodes_searched(), threads.tb_hits(),
tt.hashfull(), TB::RootInTB)
sync_cout << UCI::pv(*this, mainThread->tm.elapsed(threads.nodes_searched()),
threads.nodes_searched(), threads.tb_hits(), tt.hashfull(),
TB::RootInTB)
<< sync_endl;
}

Expand Down Expand Up @@ -980,7 +978,7 @@ Value Search::Worker::search(
if (rootNode && is_mainthread()
&& main_manager()->tm.elapsed(threads.nodes_searched()) > 3000)
sync_cout << "info depth " << depth << " currmove "
<< UciHandler::move(move, pos.is_chess960()) << " currmovenumber "
<< UCI::move(move, pos.is_chess960()) << " currmovenumber "
<< moveCount + thisThread->pvIdx << sync_endl;
if (PvNode)
(ss + 1)->pv = nullptr;
Expand Down
6 changes: 3 additions & 3 deletions src/search.h
Expand Up @@ -45,7 +45,7 @@ enum NodeType {
class TranspositionTable;
class ThreadPool;
class OptionsMap;
class UciHandler;
class UCI;

namespace Search {

Expand Down Expand Up @@ -123,7 +123,7 @@ struct LimitsType {
};


// The UciHandler stores the uci options, thread pool, and transposition table.
// The UCI stores the uci options, thread pool, and transposition table.
// This struct is used to easily forward data to the Search::Worker class.
struct ExternalShared {
ExternalShared(const OptionsMap& o, ThreadPool& tp, TranspositionTable& t) :
Expand Down Expand Up @@ -240,7 +240,7 @@ class Worker {
size_t thread_idx;

friend class Stockfish::ThreadPool;
friend class Stockfish::UciHandler;
friend class Stockfish::UCI;
friend class SearchManager;
};

Expand Down
30 changes: 15 additions & 15 deletions src/uci.cpp
Expand Up @@ -46,7 +46,7 @@ constexpr auto StartFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKB
constexpr int NormalizeToPawnValue = 328;
constexpr int MaxHashMB = Is64Bit ? 33554432 : 2048;

UciHandler::UciHandler(int argc, char** argv) :
UCI::UCI(int argc, char** argv) :
cli(argc, argv) {

options["Debug Log File"] << Option("", [](const Option& o) { start_logger(o); });
Expand Down Expand Up @@ -83,7 +83,7 @@ UciHandler::UciHandler(int argc, char** argv) :
search_clear(); // After threads are up
}

void UciHandler::loop() {
void UCI::loop() {

Position pos;
std::string token, cmd;
Expand Down Expand Up @@ -166,7 +166,7 @@ void UciHandler::loop() {
} while (token != "quit" && cli.argc == 1); // The command-line arguments are one-shot
}

void UciHandler::go(Position& pos, std::istringstream& is, StateListPtr& states) {
void UCI::go(Position& pos, std::istringstream& is, StateListPtr& states) {


Search::LimitsType limits;
Expand Down Expand Up @@ -210,7 +210,7 @@ void UciHandler::go(Position& pos, std::istringstream& is, StateListPtr& states)
threads.start_thinking(options, pos, states, limits, ponderMode);
}

void UciHandler::bench(Position& pos, std::istream& args, StateListPtr& states) {
void UCI::bench(Position& pos, std::istream& args, StateListPtr& states) {
std::string token;
uint64_t num, nodes = 0, cnt = 1;

Expand Down Expand Up @@ -259,7 +259,7 @@ void UciHandler::bench(Position& pos, std::istream& args, StateListPtr& states)
<< "\nNodes/second : " << 1000 * nodes / elapsed << std::endl;
}

void UciHandler::trace_eval(Position& pos) {
void UCI::trace_eval(Position& pos) {
StateListPtr states(new std::deque<StateInfo>(1));
Position p;
p.set(pos.fen(), options["UCI_Chess960"], &states->back());
Expand All @@ -269,20 +269,20 @@ void UciHandler::trace_eval(Position& pos) {
sync_cout << "\n" << Eval::trace(p, *threads.main_thread()->worker.get()) << sync_endl;
}

void UciHandler::search_clear() {
void UCI::search_clear() {
threads.main_thread()->wait_for_search_finished();

tt.clear(options["Threads"]);
threads.clear();
Tablebases::init(options["SyzygyPath"]); // Free mapped files
}

void UciHandler::setoption(std::istringstream& is) {
void UCI::setoption(std::istringstream& is) {
threads.main_thread()->wait_for_search_finished();
options.setoption(is);
}

void UciHandler::position(Position& pos, std::istringstream& is, StateListPtr& states) {
void UCI::position(Position& pos, std::istringstream& is, StateListPtr& states) {
Move m;
std::string token, fen;

Expand Down Expand Up @@ -310,9 +310,9 @@ void UciHandler::position(Position& pos, std::istringstream& is, StateListPtr& s
}
}

int UciHandler::to_cp(Value v) { return 100 * v / NormalizeToPawnValue; }
int UCI::to_cp(Value v) { return 100 * v / NormalizeToPawnValue; }

std::string UciHandler::value(Value v) {
std::string UCI::value(Value v) {
assert(-VALUE_INFINITE < v && v < VALUE_INFINITE);

std::stringstream ss;
Expand All @@ -330,11 +330,11 @@ std::string UciHandler::value(Value v) {
return ss.str();
}

std::string UciHandler::square(Square s) {
std::string UCI::square(Square s) {
return std::string{char('a' + file_of(s)), char('1' + rank_of(s))};
}

std::string UciHandler::move(Move m, bool chess960) {
std::string UCI::move(Move m, bool chess960) {
if (m == Move::none())
return "(none)";

Expand All @@ -355,7 +355,7 @@ std::string UciHandler::move(Move m, bool chess960) {
return move;
}

std::string UciHandler::pv(const Search::Worker& workerThread,
std::string UCI::pv(const Search::Worker& workerThread,
TimePoint elapsed,
uint64_t nodesSearched,
uint64_t tb_hits,
Expand Down Expand Up @@ -440,7 +440,7 @@ int win_rate_model(Value v, int ply) {
}
}

std::string UciHandler::wdl(Value v, int ply) {
std::string UCI::wdl(Value v, int ply) {
std::stringstream ss;

int wdl_w = win_rate_model(v, ply);
Expand All @@ -451,7 +451,7 @@ std::string UciHandler::wdl(Value v, int ply) {
return ss.str();
}

Move UciHandler::to_move(const Position& pos, std::string& str) {
Move UCI::to_move(const Position& pos, std::string& str) {
if (str.length() == 5)
str[4] = char(tolower(str[4])); // The promotion piece character must be lowercased

Expand Down
4 changes: 2 additions & 2 deletions src/uci.h
Expand Up @@ -43,9 +43,9 @@ class Move;
enum Square : int;
using Value = int;

class UciHandler {
class UCI {
public:
UciHandler(int argc, char** argv);
UCI(int argc, char** argv);

void loop();

Expand Down

0 comments on commit 61f3ade

Please sign in to comment.