mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-25 11:36:51 +08:00
learn -> tools
This commit is contained in:
16
src/Makefile
16
src/Makefile
@@ -57,17 +57,17 @@ SRCS = benchmark.cpp bitbase.cpp bitboard.cpp endgame.cpp evaluate.cpp main.cpp
|
||||
nnue/features/a.cpp \
|
||||
nnue/features/castling_right.cpp \
|
||||
nnue/features/enpassant.cpp \
|
||||
learn/sfen_packer.cpp \
|
||||
learn/gensfen.cpp \
|
||||
learn/gensfen_nonpv.cpp \
|
||||
learn/opening_book.cpp \
|
||||
learn/convert.cpp \
|
||||
learn/transform.cpp \
|
||||
learn/stats.cpp
|
||||
tools/sfen_packer.cpp \
|
||||
tools/gensfen.cpp \
|
||||
tools/gensfen_nonpv.cpp \
|
||||
tools/opening_book.cpp \
|
||||
tools/convert.cpp \
|
||||
tools/transform.cpp \
|
||||
tools/stats.cpp
|
||||
|
||||
OBJS = $(notdir $(SRCS:.cpp=.o))
|
||||
|
||||
VPATH = syzygy:nnue:nnue/features:eval:extra:learn
|
||||
VPATH = syzygy:nnue:nnue/features:eval:extra:tools
|
||||
|
||||
### ==========================================================================
|
||||
### Section 2. High-level Configuration
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
#include "uci.h"
|
||||
#include "syzygy/tbprobe.h"
|
||||
|
||||
#include "learn/packed_sfen.h"
|
||||
#include "learn/sfen_packer.h"
|
||||
#include "tools/packed_sfen.h"
|
||||
#include "tools/sfen_packer.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
@@ -1373,13 +1373,13 @@ bool Position::pos_is_ok() const {
|
||||
// Add a function that directly unpacks for speed. It's pretty tough.
|
||||
// Write it by combining packer::unpack() and Position::set().
|
||||
// If there is a problem with the passed phase and there is an error, non-zero is returned.
|
||||
int Position::set_from_packed_sfen(const Learner::PackedSfen& sfen , StateInfo* si, Thread* th)
|
||||
int Position::set_from_packed_sfen(const Tools::PackedSfen& sfen , StateInfo* si, Thread* th)
|
||||
{
|
||||
return Learner::set_from_packed_sfen(*this, sfen, si, th);
|
||||
return Tools::set_from_packed_sfen(*this, sfen, si, th);
|
||||
}
|
||||
|
||||
// Get the packed sfen. Returns to the buffer specified in the argument.
|
||||
void Position::sfen_pack(Learner::PackedSfen& sfen)
|
||||
void Position::sfen_pack(Tools::PackedSfen& sfen)
|
||||
{
|
||||
sfen = Learner::sfen_pack(*this);
|
||||
sfen = Tools::sfen_pack(*this);
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
|
||||
#include "nnue/nnue_accumulator.h"
|
||||
|
||||
#include "learn/packed_sfen.h"
|
||||
#include "learn/sfen_packer.h"
|
||||
#include "tools/packed_sfen.h"
|
||||
#include "tools/sfen_packer.h"
|
||||
|
||||
|
||||
/// StateInfo struct stores information needed to restore a Position object to
|
||||
@@ -179,17 +179,17 @@ public:
|
||||
|
||||
// --sfenization helper
|
||||
|
||||
friend int Learner::set_from_packed_sfen(Position& pos, const Learner::PackedSfen& sfen, StateInfo* si, Thread* th);
|
||||
friend int Tools::set_from_packed_sfen(Position& pos, const Tools::PackedSfen& sfen, StateInfo* si, Thread* th);
|
||||
|
||||
// Get the packed sfen. Returns to the buffer specified in the argument.
|
||||
// Do not include gamePly in pack.
|
||||
void sfen_pack(Learner::PackedSfen& sfen);
|
||||
void sfen_pack(Tools::PackedSfen& sfen);
|
||||
|
||||
// It is slow to go through sfen, so I made a function to set packed sfen directly.
|
||||
// Equivalent to pos.set(sfen_unpack(data),si,th);.
|
||||
// If there is a problem with the passed phase and there is an error, non-zero is returned.
|
||||
// PackedSfen does not include gamePly so it cannot be restored. If you want to set it, specify it with an argument.
|
||||
int set_from_packed_sfen(const Learner::PackedSfen& sfen, StateInfo* si, Thread* th);
|
||||
int set_from_packed_sfen(const Tools::PackedSfen& sfen, StateInfo* si, Thread* th);
|
||||
|
||||
void clear() { std::memset(this, 0, sizeof(Position)); }
|
||||
|
||||
|
||||
@@ -311,7 +311,7 @@ void Thread::search() {
|
||||
|
||||
if (!this->rootMoves.empty())
|
||||
Tablebases::rank_root_moves(this->rootPos, this->rootMoves);
|
||||
|
||||
|
||||
if (mainThread)
|
||||
{
|
||||
if (mainThread->bestPreviousScore == VALUE_INFINITE)
|
||||
@@ -1995,7 +1995,7 @@ namespace Search
|
||||
// It might have been good.
|
||||
|
||||
// Initialization for learning.
|
||||
// Called from Learner::search(),Learner::qsearch().
|
||||
// Called from Tools::search(),Tools::qsearch().
|
||||
static bool init_for_search(Position& pos, Stack* ss)
|
||||
{
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ extern LimitsType Limits;
|
||||
void init();
|
||||
void clear();
|
||||
|
||||
// A pair of reader and evaluation value. Returned by Learner::search(),Learner::qsearch().
|
||||
// A pair of reader and evaluation value. Returned by Tools::search(),Tools::qsearch().
|
||||
using ValueAndPV = std::pair<Value, std::vector<Move>>;
|
||||
|
||||
ValueAndPV qsearch(Position& pos);
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Learner
|
||||
namespace Tools
|
||||
{
|
||||
bool fen_is_ok(Position& pos, std::string input_fen) {
|
||||
std::string pos_fen = pos.fen();
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace Learner {
|
||||
namespace Tools {
|
||||
void convert(std::istringstream& is);
|
||||
|
||||
void convert_bin_from_pgn_extract(std::istringstream& is);
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Learner
|
||||
namespace Tools
|
||||
{
|
||||
// Class to generate sfen with multiple threads
|
||||
struct Gensfen
|
||||
@@ -220,7 +220,7 @@ namespace Learner
|
||||
// If you use this, it will be compared with the accumulated nodes of each thread. Therefore, do not use it.
|
||||
limits.nodes = 0;
|
||||
|
||||
// depth is also processed by the one passed as an argument of Learner::search().
|
||||
// depth is also processed by the one passed as an argument of Tools::search().
|
||||
limits.depth = 0;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace Learner {
|
||||
namespace Tools {
|
||||
|
||||
// Automatic generation of teacher position
|
||||
void gensfen(std::istringstream& is);
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Learner
|
||||
namespace Tools
|
||||
{
|
||||
// Class to generate sfen with multiple threads
|
||||
struct GensfenNonPv
|
||||
@@ -163,7 +163,7 @@ namespace Learner
|
||||
// If you use this, it will be compared with the accumulated nodes of each thread. Therefore, do not use it.
|
||||
limits.nodes = 0;
|
||||
|
||||
// depth is also processed by the one passed as an argument of Learner::search().
|
||||
// depth is also processed by the one passed as an argument of Tools::search().
|
||||
limits.depth = 0;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace Learner {
|
||||
namespace Tools {
|
||||
|
||||
// Automatic generation of teacher position
|
||||
void gensfen_nonpv(std::istringstream& is);
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace Learner {
|
||||
namespace Tools {
|
||||
|
||||
EpdOpeningBook::EpdOpeningBook(const std::string& file, PRNG& prng) :
|
||||
OpeningBook(file)
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace Learner {
|
||||
namespace Tools {
|
||||
|
||||
struct OpeningBook {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
namespace Learner {
|
||||
namespace Tools {
|
||||
|
||||
// packed sfen
|
||||
struct PackedSfen { std::uint8_t data[32]; };
|
||||
@@ -17,7 +17,7 @@ namespace Learner {
|
||||
// phase
|
||||
PackedSfen sfen;
|
||||
|
||||
// Evaluation value returned from Learner::search()
|
||||
// Evaluation value returned from Tools::search()
|
||||
std::int16_t score;
|
||||
|
||||
// PV first move
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Learner {
|
||||
namespace Tools {
|
||||
|
||||
// Class that handles bitstream
|
||||
// useful when doing aspect encoding
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include "learn/packed_sfen.h"
|
||||
#include "packed_sfen.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -11,7 +11,7 @@ class Position;
|
||||
struct StateInfo;
|
||||
class Thread;
|
||||
|
||||
namespace Learner {
|
||||
namespace Tools {
|
||||
|
||||
int set_from_packed_sfen(Position& pos, const PackedSfen& sfen, StateInfo* si, Thread* th);
|
||||
PackedSfen sfen_pack(Position& pos);
|
||||
@@ -17,7 +17,7 @@
|
||||
#include <thread>
|
||||
#include <functional>
|
||||
|
||||
namespace Learner{
|
||||
namespace Tools{
|
||||
|
||||
enum struct SfenReaderMode
|
||||
{
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace Learner {
|
||||
namespace Tools {
|
||||
|
||||
enum struct SfenOutputType
|
||||
{
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Learner {
|
||||
namespace Tools {
|
||||
|
||||
// Helper class for exporting Sfen
|
||||
struct SfenWriter
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
|
||||
namespace Learner::Stats
|
||||
namespace Tools::Stats
|
||||
{
|
||||
struct StatisticGathererBase
|
||||
{
|
||||
@@ -566,7 +566,7 @@ namespace Learner::Stats
|
||||
Position& pos = th->rootPos;
|
||||
StateInfo si;
|
||||
|
||||
auto in = Learner::open_sfen_input_file(filename);
|
||||
auto in = Tools::open_sfen_input_file(filename);
|
||||
|
||||
auto on_move = [&](const Position& position, const Move& move) {
|
||||
statistic_gatherers.on_move(position, move);
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace Learner::Stats {
|
||||
namespace Tools::Stats {
|
||||
|
||||
void gather_statistics(std::istringstream& is);
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
|
||||
namespace Learner
|
||||
namespace Tools
|
||||
{
|
||||
using CommandFunc = void(*)(std::istringstream&);
|
||||
|
||||
@@ -120,8 +120,8 @@ namespace Learner
|
||||
Position& pos = th->rootPos;
|
||||
StateInfo si;
|
||||
|
||||
auto in = Learner::open_sfen_input_file(params.input_filename);
|
||||
auto out = Learner::create_new_sfen_output(params.output_filename);
|
||||
auto in = Tools::open_sfen_input_file(params.input_filename);
|
||||
auto out = Tools::create_new_sfen_output(params.output_filename);
|
||||
|
||||
if (in == nullptr)
|
||||
{
|
||||
@@ -261,7 +261,7 @@ namespace Learner
|
||||
|
||||
buffer.reserve(batch_size);
|
||||
|
||||
auto out = Learner::create_new_sfen_output(params.output_filename);
|
||||
auto out = Tools::create_new_sfen_output(params.output_filename);
|
||||
|
||||
std::mutex mutex;
|
||||
uint64_t num_processed = 0;
|
||||
@@ -279,7 +279,7 @@ namespace Learner
|
||||
// If you use this, it will be compared with the accumulated nodes of each thread. Therefore, do not use it.
|
||||
limits.nodes = 0;
|
||||
|
||||
// depth is also processed by the one passed as an argument of Learner::search().
|
||||
// depth is also processed by the one passed as an argument of Tools::search().
|
||||
limits.depth = 0;
|
||||
|
||||
Threads.execute_with_workers([&](auto& th){
|
||||
@@ -343,7 +343,7 @@ namespace Learner
|
||||
void do_rescore_data(RescoreParams& params)
|
||||
{
|
||||
// TODO: Use SfenReader once it works correctly in sequential mode. See issue #271
|
||||
auto in = Learner::open_sfen_input_file(params.input_filename);
|
||||
auto in = Tools::open_sfen_input_file(params.input_filename);
|
||||
auto readsome = [&in, mutex = std::mutex{}](int n) mutable -> PSVector {
|
||||
|
||||
PSVector psv;
|
||||
@@ -388,7 +388,7 @@ namespace Learner
|
||||
// If you use this, it will be compared with the accumulated nodes of each thread. Therefore, do not use it.
|
||||
limits.nodes = 0;
|
||||
|
||||
// depth is also processed by the one passed as an argument of Learner::search().
|
||||
// depth is also processed by the one passed as an argument of Tools::search().
|
||||
limits.depth = 0;
|
||||
|
||||
std::atomic<std::uint64_t> num_processed = 0;
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace Learner {
|
||||
namespace Tools {
|
||||
|
||||
void transform(std::istringstream& is);
|
||||
|
||||
26
src/uci.cpp
26
src/uci.cpp
@@ -33,11 +33,11 @@
|
||||
#include "tt.h"
|
||||
#include "uci.h"
|
||||
|
||||
#include "learn/gensfen.h"
|
||||
#include "learn/gensfen_nonpv.h"
|
||||
#include "learn/convert.h"
|
||||
#include "learn/transform.h"
|
||||
#include "learn/stats.h"
|
||||
#include "tools/gensfen.h"
|
||||
#include "tools/gensfen_nonpv.h"
|
||||
#include "tools/convert.h"
|
||||
#include "tools/transform.h"
|
||||
#include "tools/stats.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -328,14 +328,14 @@ void UCI::loop(int argc, char* argv[]) {
|
||||
else if (token == "eval") trace_eval(pos);
|
||||
else if (token == "compiler") sync_cout << compiler_info() << sync_endl;
|
||||
|
||||
else if (token == "gensfen") Learner::gensfen(is);
|
||||
else if (token == "gensfen_nonpv") Learner::gensfen_nonpv(is);
|
||||
else if (token == "convert") Learner::convert(is);
|
||||
else if (token == "convert_bin") Learner::convert_bin(is);
|
||||
else if (token == "convert_plain") Learner::convert_plain(is);
|
||||
else if (token == "convert_bin_from_pgn_extract") Learner::convert_bin_from_pgn_extract(is);
|
||||
else if (token == "transform") Learner::transform(is);
|
||||
else if (token == "gather_statistics") Learner::Stats::gather_statistics(is);
|
||||
else if (token == "gensfen") Tools::gensfen(is);
|
||||
else if (token == "gensfen_nonpv") Tools::gensfen_nonpv(is);
|
||||
else if (token == "convert") Tools::convert(is);
|
||||
else if (token == "convert_bin") Tools::convert_bin(is);
|
||||
else if (token == "convert_plain") Tools::convert_plain(is);
|
||||
else if (token == "convert_bin_from_pgn_extract") Tools::convert_bin_from_pgn_extract(is);
|
||||
else if (token == "transform") Tools::transform(is);
|
||||
else if (token == "gather_statistics") Tools::Stats::gather_statistics(is);
|
||||
|
||||
// Command to call qsearch(),search() directly for testing
|
||||
else if (token == "qsearch") qsearch_cmd(pos);
|
||||
|
||||
Reference in New Issue
Block a user