1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

Assorted cleanups

- fix naming convention for `workingDirectory`
- use type alias for `EvalFiles` everywhere
- move `ponderMode` into `LimitsType`
- move limits parsing into standalone static function

closes https://github.com/official-stockfish/Stockfish/pull/5098

No functional change
This commit is contained in:
Disservin 2024-03-09 12:14:57 +01:00
parent 632f1c21cd
commit b6dfd6bd54
8 changed files with 26 additions and 33 deletions

View file

@ -17,7 +17,6 @@
*/ */
#include <iostream> #include <iostream>
#include <unordered_map>
#include "bitboard.h" #include "bitboard.h"
#include "evaluate.h" #include "evaluate.h"
@ -40,7 +39,7 @@ int main(int argc, char* argv[]) {
Tune::init(uci.options); Tune::init(uci.options);
uci.evalFiles = Eval::NNUE::load_networks(uci.workingDirectory(), uci.options, uci.evalFiles); uci.evalFiles = Eval::NNUE::load_networks(uci.working_directory(), uci.options, uci.evalFiles);
uci.loop(); uci.loop();

View file

@ -30,7 +30,6 @@
#include <sstream> #include <sstream>
#include <string_view> #include <string_view>
#include <type_traits> #include <type_traits>
#include <unordered_map>
#include "../evaluate.h" #include "../evaluate.h"
#include "../misc.h" #include "../misc.h"
@ -454,7 +453,7 @@ bool save_eval(std::ostream& stream,
// Save eval, to a file given by its name // Save eval, to a file given by its name
bool save_eval(const std::optional<std::string>& filename, bool save_eval(const std::optional<std::string>& filename,
NetSize netSize, NetSize netSize,
const std::unordered_map<Eval::NNUE::NetSize, Eval::EvalFile>& evalFiles) { const EvalFiles& evalFiles) {
std::string actualFilename; std::string actualFilename;
std::string msg; std::string msg;

View file

@ -26,8 +26,8 @@
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <string> #include <string>
#include <unordered_map>
#include "../evaluate.h"
#include "../misc.h" #include "../misc.h"
#include "../types.h" #include "../types.h"
#include "nnue_architecture.h" #include "nnue_architecture.h"
@ -35,11 +35,6 @@
namespace Stockfish { namespace Stockfish {
class Position; class Position;
namespace Eval {
struct EvalFile;
}
} }
namespace Stockfish::Eval::NNUE { namespace Stockfish::Eval::NNUE {
@ -87,9 +82,7 @@ bool save_eval(std::ostream& stream,
NetSize netSize, NetSize netSize,
const std::string& name, const std::string& name,
const std::string& netDescription); const std::string& netDescription);
bool save_eval(const std::optional<std::string>& filename, bool save_eval(const std::optional<std::string>& filename, NetSize netSize, const EvalFiles&);
NetSize netSize,
const std::unordered_map<Eval::NNUE::NetSize, Eval::EvalFile>&);
} // namespace Stockfish::Eval::NNUE } // namespace Stockfish::Eval::NNUE

View file

@ -109,6 +109,7 @@ struct LimitsType {
time[WHITE] = time[BLACK] = inc[WHITE] = inc[BLACK] = npmsec = movetime = TimePoint(0); time[WHITE] = time[BLACK] = inc[WHITE] = inc[BLACK] = npmsec = movetime = TimePoint(0);
movestogo = depth = mate = perft = infinite = 0; movestogo = depth = mate = perft = infinite = 0;
nodes = 0; nodes = 0;
ponderMode = false;
} }
bool use_time_management() const { return time[WHITE] || time[BLACK]; } bool use_time_management() const { return time[WHITE] || time[BLACK]; }
@ -117,6 +118,7 @@ struct LimitsType {
TimePoint time[COLOR_NB], inc[COLOR_NB], npmsec, movetime, startTime; TimePoint time[COLOR_NB], inc[COLOR_NB], npmsec, movetime, startTime;
int movestogo, depth, mate, perft, infinite; int movestogo, depth, mate, perft, infinite;
uint64_t nodes; uint64_t nodes;
bool ponderMode;
}; };

View file

@ -163,13 +163,12 @@ void ThreadPool::clear() {
void ThreadPool::start_thinking(const OptionsMap& options, void ThreadPool::start_thinking(const OptionsMap& options,
Position& pos, Position& pos,
StateListPtr& states, StateListPtr& states,
Search::LimitsType limits, Search::LimitsType limits) {
bool ponderMode) {
main_thread()->wait_for_search_finished(); main_thread()->wait_for_search_finished();
main_manager()->stopOnPonderhit = stop = abortedSearch = false; main_manager()->stopOnPonderhit = stop = abortedSearch = false;
main_manager()->ponder = ponderMode; main_manager()->ponder = limits.ponderMode;
increaseDepth = true; increaseDepth = true;

View file

@ -79,8 +79,7 @@ class ThreadPool {
} }
} }
void void start_thinking(const OptionsMap&, Position&, StateListPtr&, Search::LimitsType);
start_thinking(const OptionsMap&, Position&, StateListPtr&, Search::LimitsType, bool = false);
void clear(); void clear();
void set(Search::SharedState); void set(Search::SharedState);

View file

@ -175,11 +175,9 @@ void UCI::loop() {
} while (token != "quit" && cli.argc == 1); // The command-line arguments are one-shot } while (token != "quit" && cli.argc == 1); // The command-line arguments are one-shot
} }
void UCI::go(Position& pos, std::istringstream& is, StateListPtr& states) { Search::LimitsType UCI::parse_limits(const Position& pos, std::istream& is) {
Search::LimitsType limits; Search::LimitsType limits;
std::string token; std::string token;
bool ponderMode = false;
limits.startTime = now(); // The search starts as early as possible limits.startTime = now(); // The search starts as early as possible
@ -211,7 +209,14 @@ void UCI::go(Position& pos, std::istringstream& is, StateListPtr& states) {
else if (token == "infinite") else if (token == "infinite")
limits.infinite = 1; limits.infinite = 1;
else if (token == "ponder") else if (token == "ponder")
ponderMode = true; limits.ponderMode = true;
return limits;
}
void UCI::go(Position& pos, std::istringstream& is, StateListPtr& states) {
Search::LimitsType limits = parse_limits(pos, is);
Eval::NNUE::verify(options, evalFiles); Eval::NNUE::verify(options, evalFiles);
@ -221,7 +226,7 @@ void UCI::go(Position& pos, std::istringstream& is, StateListPtr& states) {
return; return;
} }
threads.start_thinking(options, pos, states, limits, ponderMode); threads.start_thinking(options, pos, states, limits);
} }
void UCI::bench(Position& pos, std::istream& args, StateListPtr& states) { void UCI::bench(Position& pos, std::istream& args, StateListPtr& states) {

View file

@ -21,7 +21,6 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <unordered_map>
#include "evaluate.h" #include "evaluate.h"
#include "misc.h" #include "misc.h"
@ -29,13 +28,10 @@
#include "thread.h" #include "thread.h"
#include "tt.h" #include "tt.h"
#include "ucioption.h" #include "ucioption.h"
#include "search.h"
namespace Stockfish { namespace Stockfish {
namespace Eval::NNUE {
enum NetSize : int;
}
class Move; class Move;
enum Square : int; enum Square : int;
using Value = int; using Value = int;
@ -53,11 +49,12 @@ class UCI {
static std::string wdl(Value v, int ply); static std::string wdl(Value v, int ply);
static Move to_move(const Position& pos, std::string& str); static Move to_move(const Position& pos, std::string& str);
const std::string& workingDirectory() const { return cli.workingDirectory; } static Search::LimitsType parse_limits(const Position& pos, std::istream& is);
const std::string& working_directory() const { return cli.workingDirectory; }
OptionsMap options; OptionsMap options;
Eval::NNUE::EvalFiles evalFiles;
std::unordered_map<Eval::NNUE::NetSize, Eval::EvalFile> evalFiles;
private: private:
TranspositionTable tt; TranspositionTable tt;