mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-25 19:46:55 +08:00
Bring the changes closer to official-stockfish/master
This commit is contained in:
@@ -25,8 +25,10 @@
|
||||
#include <chrono>
|
||||
#include <random>
|
||||
#include <regex>
|
||||
#include <filesystem>
|
||||
|
||||
using namespace std;
|
||||
namespace sys = std::filesystem;
|
||||
|
||||
namespace Stockfish::Tools
|
||||
{
|
||||
@@ -123,7 +125,7 @@ namespace Stockfish::Tools
|
||||
score = (score - src_score_min_value) / (src_score_max_value - src_score_min_value);
|
||||
// Scale to [dest_score_min_value, dest_score_max_value].
|
||||
score = score * (dest_score_max_value - dest_score_min_value) + dest_score_min_value;
|
||||
p.score = Math::clamp((int32_t)std::round(score), -(int32_t)VALUE_MATE, (int32_t)VALUE_MATE);
|
||||
p.score = std::clamp((int32_t)std::round(score), -(int32_t)VALUE_MATE, (int32_t)VALUE_MATE);
|
||||
}
|
||||
else if (token == "ply") {
|
||||
int temp;
|
||||
@@ -414,7 +416,7 @@ namespace Stockfish::Tools
|
||||
Value value = parse_score_from_pgn_extract(str_eval, success);
|
||||
if (success) {
|
||||
eval_found = true;
|
||||
psv.score = Math::clamp(value, -VALUE_MATE, VALUE_MATE);
|
||||
psv.score = std::clamp(value, -VALUE_MATE, VALUE_MATE);
|
||||
}
|
||||
|
||||
#if defined(DEBUG_CONVERT_BIN_FROM_PGN_EXTRACT)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "gensfen.h"
|
||||
#include "training_data_generator.h"
|
||||
|
||||
#include "sfen_writer.h"
|
||||
#include "packed_sfen.h"
|
||||
@@ -37,7 +37,7 @@ using namespace std;
|
||||
namespace Stockfish::Tools
|
||||
{
|
||||
// Class to generate sfen with multiple threads
|
||||
struct Gensfen
|
||||
struct TrainingDataGenerator
|
||||
{
|
||||
struct Params
|
||||
{
|
||||
@@ -123,7 +123,7 @@ namespace Stockfish::Tools
|
||||
static constexpr uint64_t REPORT_STATS_EVERY = 200000;
|
||||
static_assert(REPORT_STATS_EVERY % REPORT_DOT_EVERY == 0);
|
||||
|
||||
Gensfen(
|
||||
TrainingDataGenerator(
|
||||
const Params& prm
|
||||
) :
|
||||
params(prm),
|
||||
@@ -205,7 +205,7 @@ namespace Stockfish::Tools
|
||||
void maybe_report(uint64_t done);
|
||||
};
|
||||
|
||||
void Gensfen::set_gensfen_search_limits()
|
||||
void TrainingDataGenerator::set_gensfen_search_limits()
|
||||
{
|
||||
// About Search::Limits
|
||||
// Be careful because this member variable is global and affects other threads.
|
||||
@@ -224,7 +224,7 @@ namespace Stockfish::Tools
|
||||
limits.depth = 0;
|
||||
}
|
||||
|
||||
void Gensfen::generate(uint64_t limit)
|
||||
void TrainingDataGenerator::generate(uint64_t limit)
|
||||
{
|
||||
last_stats_report_time = 0;
|
||||
|
||||
@@ -246,7 +246,7 @@ namespace Stockfish::Tools
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void Gensfen::generate_worker(
|
||||
void TrainingDataGenerator::generate_worker(
|
||||
Thread& th,
|
||||
std::atomic<uint64_t>& counter,
|
||||
uint64_t limit)
|
||||
@@ -449,7 +449,7 @@ namespace Stockfish::Tools
|
||||
}
|
||||
}
|
||||
|
||||
bool Gensfen::was_seen_before(const Position& pos)
|
||||
bool TrainingDataGenerator::was_seen_before(const Position& pos)
|
||||
{
|
||||
// Look into the position hashtable to see if the same
|
||||
// position was seen before.
|
||||
@@ -470,7 +470,7 @@ namespace Stockfish::Tools
|
||||
}
|
||||
}
|
||||
|
||||
optional<int8_t> Gensfen::get_current_game_result(
|
||||
optional<int8_t> TrainingDataGenerator::get_current_game_result(
|
||||
Position& pos,
|
||||
const vector<int>& move_hist_scores) const
|
||||
{
|
||||
@@ -591,7 +591,7 @@ namespace Stockfish::Tools
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
vector<uint8_t> Gensfen::generate_random_move_flags(PRNG& prng)
|
||||
vector<uint8_t> TrainingDataGenerator::generate_random_move_flags(PRNG& prng)
|
||||
{
|
||||
vector<uint8_t> random_move_flag;
|
||||
|
||||
@@ -628,7 +628,7 @@ namespace Stockfish::Tools
|
||||
return random_move_flag;
|
||||
}
|
||||
|
||||
optional<Move> Gensfen::choose_random_move(
|
||||
optional<Move> TrainingDataGenerator::choose_random_move(
|
||||
PRNG& prng,
|
||||
Position& pos,
|
||||
std::vector<uint8_t>& random_move_flag,
|
||||
@@ -725,7 +725,7 @@ namespace Stockfish::Tools
|
||||
// 1 when winning. -1 when losing. Pass 0 for a draw.
|
||||
// Return value: true if the specified number of
|
||||
// sfens has already been reached and the process ends.
|
||||
bool Gensfen::commit_psv(
|
||||
bool TrainingDataGenerator::commit_psv(
|
||||
Thread& th,
|
||||
PSVector& sfens,
|
||||
int8_t result,
|
||||
@@ -770,7 +770,7 @@ namespace Stockfish::Tools
|
||||
return false;
|
||||
}
|
||||
|
||||
void Gensfen::report(uint64_t done, uint64_t new_done)
|
||||
void TrainingDataGenerator::report(uint64_t done, uint64_t new_done)
|
||||
{
|
||||
const auto now_time = now();
|
||||
const TimePoint elapsed = now_time - last_stats_report_time + 1;
|
||||
@@ -786,7 +786,7 @@ namespace Stockfish::Tools
|
||||
out = sync_region_cout.new_region();
|
||||
}
|
||||
|
||||
void Gensfen::maybe_report(uint64_t done)
|
||||
void TrainingDataGenerator::maybe_report(uint64_t done)
|
||||
{
|
||||
if (done % REPORT_DOT_EVERY == 0)
|
||||
{
|
||||
@@ -811,12 +811,12 @@ namespace Stockfish::Tools
|
||||
}
|
||||
|
||||
// Command to generate a game record
|
||||
void gensfen(istringstream& is)
|
||||
void generate_training_data(istringstream& is)
|
||||
{
|
||||
// Number of generated game records default = 8 billion phases (Ponanza specification)
|
||||
uint64_t loop_max = 8000000000UL;
|
||||
|
||||
Gensfen::Params params;
|
||||
TrainingDataGenerator::Params params;
|
||||
|
||||
// Add a random number to the end of the file name.
|
||||
bool random_file_name = false;
|
||||
@@ -966,9 +966,9 @@ namespace Stockfish::Tools
|
||||
|
||||
Threads.main()->ponder = false;
|
||||
|
||||
Gensfen gensfen(params);
|
||||
TrainingDataGenerator gensfen(params);
|
||||
gensfen.generate(loop_max);
|
||||
|
||||
std::cout << "INFO: Gensfen finished." << endl;
|
||||
std::cout << "INFO: TrainingDataGenerator finished." << endl;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
namespace Stockfish::Tools {
|
||||
|
||||
// Automatic generation of teacher position
|
||||
void gensfen(std::istringstream& is);
|
||||
void generate_training_data(std::istringstream& is);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "gensfen_nonpv.h"
|
||||
#include "training_data_generator_nonpv.h"
|
||||
|
||||
#include "sfen_writer.h"
|
||||
#include "packed_sfen.h"
|
||||
@@ -37,7 +37,7 @@ using namespace std;
|
||||
namespace Stockfish::Tools
|
||||
{
|
||||
// Class to generate sfen with multiple threads
|
||||
struct GensfenNonPv
|
||||
struct TrainingDataGeneratorNonPv
|
||||
{
|
||||
struct Params
|
||||
{
|
||||
@@ -89,7 +89,7 @@ namespace Stockfish::Tools
|
||||
static constexpr uint64_t REPORT_STATS_EVERY = 200000;
|
||||
static_assert(REPORT_STATS_EVERY % REPORT_DOT_EVERY == 0);
|
||||
|
||||
GensfenNonPv(
|
||||
TrainingDataGeneratorNonPv(
|
||||
const Params& prm
|
||||
) :
|
||||
params(prm),
|
||||
@@ -148,7 +148,7 @@ namespace Stockfish::Tools
|
||||
void maybe_report(uint64_t done);
|
||||
};
|
||||
|
||||
void GensfenNonPv::set_gensfen_search_limits()
|
||||
void TrainingDataGeneratorNonPv::set_gensfen_search_limits()
|
||||
{
|
||||
// About Search::Limits
|
||||
// Be careful because this member variable is global and affects other threads.
|
||||
@@ -167,7 +167,7 @@ namespace Stockfish::Tools
|
||||
limits.depth = 0;
|
||||
}
|
||||
|
||||
void GensfenNonPv::generate(uint64_t limit)
|
||||
void TrainingDataGeneratorNonPv::generate(uint64_t limit)
|
||||
{
|
||||
last_stats_report_time = 0;
|
||||
|
||||
@@ -189,7 +189,7 @@ namespace Stockfish::Tools
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
PSVector GensfenNonPv::do_exploration(
|
||||
PSVector TrainingDataGeneratorNonPv::do_exploration(
|
||||
Thread& th,
|
||||
int count)
|
||||
{
|
||||
@@ -253,7 +253,7 @@ namespace Stockfish::Tools
|
||||
return psv;
|
||||
}
|
||||
|
||||
void GensfenNonPv::generate_worker(
|
||||
void TrainingDataGeneratorNonPv::generate_worker(
|
||||
Thread& th,
|
||||
std::atomic<uint64_t>& counter,
|
||||
uint64_t limit)
|
||||
@@ -323,7 +323,7 @@ namespace Stockfish::Tools
|
||||
// 1 when winning. -1 when losing. Pass 0 for a draw.
|
||||
// Return value: true if the specified number of
|
||||
// sfens has already been reached and the process ends.
|
||||
bool GensfenNonPv::commit_psv(
|
||||
bool TrainingDataGeneratorNonPv::commit_psv(
|
||||
Thread& th,
|
||||
PSVector& sfens,
|
||||
std::atomic<uint64_t>& counter,
|
||||
@@ -347,7 +347,7 @@ namespace Stockfish::Tools
|
||||
return false;
|
||||
}
|
||||
|
||||
void GensfenNonPv::report(uint64_t done, uint64_t new_done)
|
||||
void TrainingDataGeneratorNonPv::report(uint64_t done, uint64_t new_done)
|
||||
{
|
||||
const auto now_time = now();
|
||||
const TimePoint elapsed = now_time - last_stats_report_time + 1;
|
||||
@@ -363,7 +363,7 @@ namespace Stockfish::Tools
|
||||
out = sync_region_cout.new_region();
|
||||
}
|
||||
|
||||
void GensfenNonPv::maybe_report(uint64_t done)
|
||||
void TrainingDataGeneratorNonPv::maybe_report(uint64_t done)
|
||||
{
|
||||
if (done % REPORT_DOT_EVERY == 0)
|
||||
{
|
||||
@@ -388,10 +388,10 @@ namespace Stockfish::Tools
|
||||
}
|
||||
|
||||
// Command to generate a game record
|
||||
void gensfen_nonpv(istringstream& is)
|
||||
void generate_training_data_nonpv(istringstream& is)
|
||||
{
|
||||
// Number of generated game records default = 8 billion phases (Ponanza specification)
|
||||
GensfenNonPv::Params params;
|
||||
TrainingDataGeneratorNonPv::Params params;
|
||||
|
||||
uint64_t count = 1'000'000;
|
||||
|
||||
@@ -480,7 +480,7 @@ namespace Stockfish::Tools
|
||||
|
||||
Threads.main()->ponder = false;
|
||||
|
||||
GensfenNonPv gensfen(params);
|
||||
TrainingDataGeneratorNonPv gensfen(params);
|
||||
gensfen.generate(count);
|
||||
|
||||
std::cout << "INFO: gensfen_nonpv finished." << endl;
|
||||
@@ -6,7 +6,7 @@
|
||||
namespace Stockfish::Tools {
|
||||
|
||||
// Automatic generation of teacher position
|
||||
void gensfen_nonpv(std::istringstream& is);
|
||||
void generate_training_data_nonpv(std::istringstream& is);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user