mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
Restore NPS output for Perft
Previously it was possible to also get the node counter after running a bench with perft, i.e. `./stockfish bench 1 1 5 current perft`, caused by a small regression from the uci refactoring. ``` Nodes searched: 4865609 =========================== Total time (ms) : 18 Nodes searched : 4865609 Nodes/second : 270311611 ```` closes https://github.com/official-stockfish/Stockfish/pull/5188 No functional change
This commit is contained in:
parent
d47aa639bd
commit
ddd250b9d6
7 changed files with 45 additions and 20 deletions
|
@ -93,7 +93,7 @@ const std::vector<std::string> Defaults = {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace Stockfish {
|
namespace Stockfish::Benchmark {
|
||||||
|
|
||||||
// Builds a list of UCI commands to be run by bench. There
|
// Builds a list of UCI commands to be run by bench. There
|
||||||
// are five parameters: TT size in MB, number of search threads that
|
// are five parameters: TT size in MB, number of search threads that
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Stockfish {
|
namespace Stockfish::Benchmark {
|
||||||
|
|
||||||
std::vector<std::string> setup_bench(const std::string&, std::istream&);
|
std::vector<std::string> setup_bench(const std::string&, std::istream&);
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include "evaluate.h"
|
#include "evaluate.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
@ -54,15 +55,16 @@ Engine::Engine(std::string path) :
|
||||||
pos.set(StartFEN, false, &states->back());
|
pos.set(StartFEN, false, &states->back());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::go(const Search::LimitsType& limits) {
|
std::uint64_t Engine::perft(const std::string& fen, Depth depth, bool isChess960) {
|
||||||
verify_networks();
|
verify_networks();
|
||||||
|
|
||||||
if (limits.perft)
|
return Benchmark::perft(fen, depth, isChess960);
|
||||||
{
|
|
||||||
perft(pos.fen(), limits.perft, options["UCI_Chess960"]);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Engine::go(const Search::LimitsType& limits) {
|
||||||
|
assert(limits.perft == 0);
|
||||||
|
verify_networks();
|
||||||
|
|
||||||
threads.start_thinking(options, pos, states, limits);
|
threads.start_thinking(options, pos, states, limits);
|
||||||
}
|
}
|
||||||
void Engine::stop() { threads.stop = true; }
|
void Engine::stop() { threads.stop = true; }
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
#include "nnue/network.h"
|
#include "nnue/network.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
|
@ -33,6 +34,7 @@
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
#include "ucioption.h"
|
#include "ucioption.h"
|
||||||
|
#include "syzygy/tbprobe.h" // for Stockfish::Depth
|
||||||
|
|
||||||
namespace Stockfish {
|
namespace Stockfish {
|
||||||
|
|
||||||
|
@ -45,6 +47,8 @@ class Engine {
|
||||||
Engine(std::string path = "");
|
Engine(std::string path = "");
|
||||||
~Engine() { wait_for_search_finished(); }
|
~Engine() { wait_for_search_finished(); }
|
||||||
|
|
||||||
|
std::uint64_t perft(const std::string& fen, Depth depth, bool isChess960);
|
||||||
|
|
||||||
// non blocking call to start searching
|
// non blocking call to start searching
|
||||||
void go(const Search::LimitsType&);
|
void go(const Search::LimitsType&);
|
||||||
// non blocking call to stop searching
|
// non blocking call to stop searching
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "uci.h"
|
#include "uci.h"
|
||||||
|
|
||||||
namespace Stockfish {
|
namespace Stockfish::Benchmark {
|
||||||
|
|
||||||
// Utility to verify move generation. All the leaf nodes up
|
// Utility to verify move generation. All the leaf nodes up
|
||||||
// to the given depth are generated and counted, and the sum is returned.
|
// to the given depth are generated and counted, and the sum is returned.
|
||||||
|
@ -56,13 +56,12 @@ uint64_t perft(Position& pos, Depth depth) {
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void perft(const std::string& fen, Depth depth, bool isChess960) {
|
inline uint64_t perft(const std::string& fen, Depth depth, bool isChess960) {
|
||||||
StateListPtr states(new std::deque<StateInfo>(1));
|
StateListPtr states(new std::deque<StateInfo>(1));
|
||||||
Position p;
|
Position p;
|
||||||
p.set(fen, isChess960, &states->back());
|
p.set(fen, isChess960, &states->back());
|
||||||
|
|
||||||
uint64_t nodes = perft<true>(p, depth);
|
return perft<true>(p, depth);
|
||||||
sync_cout << "\nNodes searched: " << nodes << "\n" << sync_endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
src/uci.cpp
22
src/uci.cpp
|
@ -219,6 +219,10 @@ Search::LimitsType UCIEngine::parse_limits(std::istream& is) {
|
||||||
void UCIEngine::go(std::istringstream& is) {
|
void UCIEngine::go(std::istringstream& is) {
|
||||||
|
|
||||||
Search::LimitsType limits = parse_limits(is);
|
Search::LimitsType limits = parse_limits(is);
|
||||||
|
|
||||||
|
if (limits.perft)
|
||||||
|
perft(limits);
|
||||||
|
else
|
||||||
engine.go(limits);
|
engine.go(limits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +237,7 @@ void UCIEngine::bench(std::istream& args) {
|
||||||
on_update_full(i, options["UCI_ShowWDL"]);
|
on_update_full(i, options["UCI_ShowWDL"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
std::vector<std::string> list = setup_bench(engine.fen(), args);
|
std::vector<std::string> list = Benchmark::setup_bench(engine.fen(), args);
|
||||||
|
|
||||||
num = count_if(list.begin(), list.end(),
|
num = count_if(list.begin(), list.end(),
|
||||||
[](const std::string& s) { return s.find("go ") == 0 || s.find("eval") == 0; });
|
[](const std::string& s) { return s.find("go ") == 0 || s.find("eval") == 0; });
|
||||||
|
@ -251,8 +255,16 @@ void UCIEngine::bench(std::istream& args) {
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
if (token == "go")
|
if (token == "go")
|
||||||
{
|
{
|
||||||
go(is);
|
Search::LimitsType limits = parse_limits(is);
|
||||||
|
|
||||||
|
if (limits.perft)
|
||||||
|
nodes = perft(limits);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
engine.go(limits);
|
||||||
engine.wait_for_search_finished();
|
engine.wait_for_search_finished();
|
||||||
|
}
|
||||||
|
|
||||||
nodes += nodesSearched;
|
nodes += nodesSearched;
|
||||||
nodesSearched = 0;
|
nodesSearched = 0;
|
||||||
}
|
}
|
||||||
|
@ -288,6 +300,12 @@ void UCIEngine::setoption(std::istringstream& is) {
|
||||||
engine.get_options().setoption(is);
|
engine.get_options().setoption(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::uint64_t UCIEngine::perft(const Search::LimitsType& limits) {
|
||||||
|
auto nodes = engine.perft(engine.fen(), limits.perft, engine.get_options()["UCI_Chess960"]);
|
||||||
|
sync_cout << "\nNodes searched: " << nodes << "\n" << sync_endl;
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
void UCIEngine::position(std::istringstream& is) {
|
void UCIEngine::position(std::istringstream& is) {
|
||||||
std::string token, fen;
|
std::string token, fen;
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
@ -61,6 +62,7 @@ class UCIEngine {
|
||||||
void bench(std::istream& args);
|
void bench(std::istream& args);
|
||||||
void position(std::istringstream& is);
|
void position(std::istringstream& is);
|
||||||
void setoption(std::istringstream& is);
|
void setoption(std::istringstream& is);
|
||||||
|
std::uint64_t perft(const Search::LimitsType&);
|
||||||
|
|
||||||
static void on_update_no_moves(const Engine::InfoShort& info);
|
static void on_update_no_moves(const Engine::InfoShort& info);
|
||||||
static void on_update_full(const Engine::InfoFull& info, bool showWDL);
|
static void on_update_full(const Engine::InfoFull& info, bool showWDL);
|
||||||
|
|
Loading…
Add table
Reference in a new issue