mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-25 03:26:24 +08:00
Merge branch 'master' of github.com:official-stockfish/Stockfish into nnue-player-merge
# Conflicts: # README.md # Readme.md # src/Makefile # src/evaluate.cpp # src/evaluate.h # src/misc.cpp # src/nnue/architectures/halfkp_256x2-32-32.h # src/nnue/evaluate_nnue.cpp # src/nnue/evaluate_nnue.h # src/nnue/features/feature_set.h # src/nnue/features/features_common.h # src/nnue/features/half_kp.cpp # src/nnue/features/half_kp.h # src/nnue/features/index_list.h # src/nnue/layers/affine_transform.h # src/nnue/layers/clipped_relu.h # src/nnue/layers/input_slice.h # src/nnue/nnue_accumulator.h # src/nnue/nnue_architecture.h # src/nnue/nnue_common.h # src/nnue/nnue_feature_transformer.h # src/position.cpp # src/position.h # src/types.h # src/ucioption.cpp # stockfish.md
This commit is contained in:
190
src/uci.cpp
190
src/uci.cpp
@@ -1,8 +1,6 @@
|
||||
/*
|
||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
||||
Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
|
||||
Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
|
||||
Copyright (C) 2004-2020 The Stockfish developers (see AUTHORS file)
|
||||
|
||||
Stockfish is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -34,10 +32,6 @@
|
||||
#include "uci.h"
|
||||
#include "syzygy/tbprobe.h"
|
||||
|
||||
#if defined(EVAL_NNUE) && defined(ENABLE_TEST_CMD)
|
||||
#include "nnue/nnue_test_command.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern vector<string> setup_bench(const Position&, istream&);
|
||||
@@ -45,44 +39,8 @@ extern vector<string> setup_bench(const Position&, istream&);
|
||||
// FEN string of the initial position, normal chess
|
||||
const char* StartFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
||||
|
||||
// Command to automatically generate a game record
|
||||
#if defined (EVAL_LEARN)
|
||||
namespace Learner
|
||||
{
|
||||
// Automatic generation of teacher position
|
||||
void gen_sfen(Position& pos, istringstream& is);
|
||||
|
||||
// Learning from the generated game record
|
||||
void learn(Position& pos, istringstream& is);
|
||||
|
||||
#if defined(GENSFEN2019)
|
||||
// Automatic generation command of teacher phase under development
|
||||
void gen_sfen2019(Position& pos, istringstream& is);
|
||||
#endif
|
||||
|
||||
// A pair of reader and evaluation value. Returned by Learner::search(),Learner::qsearch().
|
||||
typedef std::pair<Value, std::vector<Move> > ValueAndPV;
|
||||
|
||||
ValueAndPV qsearch(Position& pos);
|
||||
ValueAndPV search(Position& pos, int depth_, size_t multiPV = 1, uint64_t nodesLimit = 0);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(EVAL_NNUE) && defined(ENABLE_TEST_CMD)
|
||||
void test_cmd(Position& pos, istringstream& is)
|
||||
{
|
||||
// Initialize as it may be searched.
|
||||
init_nnue();
|
||||
|
||||
std::string param;
|
||||
is >> param;
|
||||
|
||||
if (param == "nnue") Eval::NNUE::TestCommand(pos, is);
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
// position() is called when engine receives the "position" UCI command.
|
||||
// The function sets up the position described in the given FEN string ("fen")
|
||||
// or the starting position ("startpos") and then makes the moves given in the
|
||||
@@ -117,6 +75,20 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
// trace_eval() prints the evaluation for the current position, consistent with the UCI
|
||||
// options set so far.
|
||||
|
||||
void trace_eval(Position& pos) {
|
||||
|
||||
StateListPtr states(new std::deque<StateInfo>(1));
|
||||
Position p;
|
||||
p.set(pos.fen(), Options["UCI_Chess960"], &states->back(), Threads.main());
|
||||
|
||||
Eval::verify_NNUE();
|
||||
|
||||
sync_cout << "\n" << Eval::trace(p) << sync_endl;
|
||||
}
|
||||
|
||||
|
||||
// setoption() is called when engine receives the "setoption" UCI command. The
|
||||
// function updates the UCI option ("name") to the given value ("value").
|
||||
@@ -205,18 +177,11 @@ namespace {
|
||||
nodes += Threads.nodes_searched();
|
||||
}
|
||||
else
|
||||
sync_cout << "\n" << Eval::trace(pos) << sync_endl;
|
||||
trace_eval(pos);
|
||||
}
|
||||
else if (token == "setoption") setoption(is);
|
||||
else if (token == "position") position(pos, is, states);
|
||||
else if (token == "ucinewgame")
|
||||
{
|
||||
#if defined(EVAL_NNUE)
|
||||
init_nnue();
|
||||
#endif
|
||||
Search::clear();
|
||||
elapsed = now(); // Search::clear() may take some while
|
||||
}
|
||||
else if (token == "ucinewgame") { Search::clear(); elapsed = now(); } // Search::clear() may take some while
|
||||
}
|
||||
|
||||
elapsed = now() - elapsed + 1; // Ensure positivity to avoid a 'divide by zero'
|
||||
@@ -251,85 +216,8 @@ namespace {
|
||||
return int(0.5 + 1000 / (1 + std::exp((a - x) / b)));
|
||||
}
|
||||
|
||||
// When you calculate check sum, save it and check the consistency later.
|
||||
uint64_t eval_sum;
|
||||
} // namespace
|
||||
|
||||
// Make is_ready_cmd() callable from outside. (Because I want to call it from the bench command etc.)
|
||||
// Note that the phase is not initialized.
|
||||
void init_nnue(bool skipCorruptCheck)
|
||||
{
|
||||
#if defined(EVAL_NNUE)
|
||||
// After receiving "isready", modify so that a line feed is sent every 5 seconds until "readyok" is returned. (keep alive processing)
|
||||
// From USI 2.0 specifications.
|
||||
// -The time out time after "is ready" is about 30 seconds. Beyond this, if you want to initialize the evaluation function and secure the hash table,
|
||||
// You should send some kind of message (breakable) from the thinking engine side.
|
||||
// -Shogi GUI already does so, so MyShogi will follow along.
|
||||
//-Also, the engine side of Yaneura King modifies it so that after "isready" is received, a line feed is sent every 5 seconds until "readyok" is returned.
|
||||
|
||||
// Perform processing that may take time, such as reading the evaluation function, at this timing.
|
||||
// If you do a time-consuming process at startup, Shogi place will make a timeout judgment and retire the recognition as a thinking engine.
|
||||
if (!UCI::load_eval_finished)
|
||||
{
|
||||
// Read evaluation function
|
||||
Eval::load_eval();
|
||||
|
||||
// Calculate and save checksum (to check for subsequent memory corruption)
|
||||
eval_sum = Eval::calc_check_sum();
|
||||
|
||||
// display soft name
|
||||
Eval::print_softname(eval_sum);
|
||||
|
||||
UCI::load_eval_finished = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check the checksum every time to see if the memory has been corrupted.
|
||||
// It seems that the time is a little wasteful, but it is good because it is about 0.1 seconds.
|
||||
if (!skipCorruptCheck && eval_sum != Eval::calc_check_sum())
|
||||
sync_cout << "Error! : EVAL memory is corrupted" << sync_endl;
|
||||
}
|
||||
#endif // defined(EVAL_NNUE)
|
||||
}
|
||||
|
||||
|
||||
// --------------------
|
||||
// Call qsearch(),search() directly for testing
|
||||
// --------------------
|
||||
|
||||
#if defined(EVAL_LEARN)
|
||||
void qsearch_cmd(Position& pos)
|
||||
{
|
||||
cout << "qsearch : ";
|
||||
auto pv = Learner::qsearch(pos);
|
||||
cout << "Value = " << pv.first << " , " << UCI::value(pv.first) << " , PV = ";
|
||||
for (auto m : pv.second)
|
||||
cout << UCI::move(m, false) << " ";
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
void search_cmd(Position& pos, istringstream& is)
|
||||
{
|
||||
string token;
|
||||
int depth = 1;
|
||||
int multi_pv = (int)Options["MultiPV"];
|
||||
while (is >> token)
|
||||
{
|
||||
if (token == "depth")
|
||||
is >> depth;
|
||||
if (token == "multipv")
|
||||
is >> multi_pv;
|
||||
}
|
||||
|
||||
cout << "search depth = " << depth << " , multi_pv = " << multi_pv << " : ";
|
||||
auto pv = Learner::search(pos, depth, multi_pv);
|
||||
cout << "Value = " << pv.first << " , " << UCI::value(pv.first) << " , PV = ";
|
||||
for (auto m : pv.second)
|
||||
cout << UCI::move(m, false) << " ";
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/// UCI::loop() waits for a command from stdin, parses it and calls the appropriate
|
||||
/// function. Also intercepts EOF from stdin to ensure gracefully exiting if the
|
||||
@@ -376,48 +264,16 @@ void UCI::loop(int argc, char* argv[]) {
|
||||
else if (token == "setoption") setoption(is);
|
||||
else if (token == "go") go(pos, is, states);
|
||||
else if (token == "position") position(pos, is, states);
|
||||
else if (token == "ucinewgame")
|
||||
{
|
||||
#if defined(EVAL_NNUE)
|
||||
init_nnue();
|
||||
#endif
|
||||
Search::clear();
|
||||
}
|
||||
else if (token == "isready") {
|
||||
#if defined(EVAL_NNUE)
|
||||
init_nnue(true);
|
||||
#endif
|
||||
sync_cout << "readyok" << sync_endl;
|
||||
}
|
||||
else if (token == "ucinewgame") Search::clear();
|
||||
else if (token == "isready") sync_cout << "readyok" << sync_endl;
|
||||
|
||||
// Additional custom non-UCI commands, mainly for debugging.
|
||||
// Do not use these commands during a search!
|
||||
else if (token == "flip") pos.flip();
|
||||
else if (token == "bench") bench(pos, is, states);
|
||||
else if (token == "d") sync_cout << pos << sync_endl;
|
||||
else if (token == "eval") sync_cout << Eval::trace(pos) << sync_endl;
|
||||
else if (token == "eval") trace_eval(pos);
|
||||
else if (token == "compiler") sync_cout << compiler_info() << sync_endl;
|
||||
#if defined (EVAL_LEARN)
|
||||
else if (token == "gensfen") Learner::gen_sfen(pos, is);
|
||||
else if (token == "learn") Learner::learn(pos, is);
|
||||
|
||||
#if defined (GENSFEN2019)
|
||||
// Command to generate teacher phase under development
|
||||
else if (token == "gensfen2019") Learner::gen_sfen2019(pos, is);
|
||||
#endif
|
||||
// Command to call qsearch(),search() directly for testing
|
||||
else if (token == "qsearch") qsearch_cmd(pos);
|
||||
else if (token == "search") search_cmd(pos, is);
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(EVAL_NNUE)
|
||||
else if (token == "eval_nnue") sync_cout << "eval_nnue = " << Eval::compute_eval(pos) << sync_endl;
|
||||
#endif
|
||||
|
||||
#if defined(EVAL_NNUE) && defined(ENABLE_TEST_CMD)
|
||||
// test command
|
||||
else if (token == "test") test_cmd(pos, is);
|
||||
#endif
|
||||
else
|
||||
sync_cout << "Unknown command: " << cmd << sync_endl;
|
||||
|
||||
@@ -511,4 +367,4 @@ Move UCI::to_move(const Position& pos, string& str) {
|
||||
return m;
|
||||
|
||||
return MOVE_NONE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user