mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 01:03:09 +00:00
Use bench to implement UI 'perft' command
Now that we can call bench on current position we can directly use it to perform our perft. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
cc04a745e2
commit
9546b79e20
2 changed files with 23 additions and 42 deletions
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <istream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
@ -58,11 +58,11 @@ static const char* Defaults[] = {
|
||||||
/// format (defaults are the positions defined above) and the type of the
|
/// format (defaults are the positions defined above) and the type of the
|
||||||
/// limit value: depth (default), time in secs or number of nodes.
|
/// limit value: depth (default), time in secs or number of nodes.
|
||||||
|
|
||||||
void benchmark(istringstream& is) {
|
void benchmark(const Position& current, istream& is) {
|
||||||
|
|
||||||
string token;
|
string token;
|
||||||
Search::LimitsType limits;
|
Search::LimitsType limits;
|
||||||
vector<string> fens(Defaults, Defaults + 16);
|
vector<string> fens;
|
||||||
|
|
||||||
// Assign default values to missing arguments
|
// Assign default values to missing arguments
|
||||||
string ttSize = (is >> token) ? token : "128";
|
string ttSize = (is >> token) ? token : "128";
|
||||||
|
@ -83,14 +83,14 @@ void benchmark(istringstream& is) {
|
||||||
else
|
else
|
||||||
limits.depth = atoi(limit.c_str());
|
limits.depth = atoi(limit.c_str());
|
||||||
|
|
||||||
if (fenFile == "current")
|
if (fenFile == "default")
|
||||||
|
fens.assign(Defaults, Defaults + 16);
|
||||||
|
|
||||||
|
else if (fenFile == "current")
|
||||||
|
fens.push_back(current.to_fen());
|
||||||
|
|
||||||
|
else
|
||||||
{
|
{
|
||||||
fens.clear();
|
|
||||||
fens.push_back(Search::RootPosition.to_fen());
|
|
||||||
}
|
|
||||||
else if (fenFile != "default")
|
|
||||||
{
|
|
||||||
fens.clear();
|
|
||||||
string fen;
|
string fen;
|
||||||
ifstream file(fenFile.c_str());
|
ifstream file(fenFile.c_str());
|
||||||
|
|
||||||
|
|
45
src/uci.cpp
45
src/uci.cpp
|
@ -22,7 +22,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "evaluate.h"
|
#include "evaluate.h"
|
||||||
#include "misc.h"
|
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
@ -30,7 +29,7 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
extern void benchmark(istringstream& is);
|
extern void benchmark(const Position& pos, istream& is);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -45,7 +44,6 @@ namespace {
|
||||||
void set_option(istringstream& up);
|
void set_option(istringstream& up);
|
||||||
void set_position(Position& pos, istringstream& up);
|
void set_position(Position& pos, istringstream& up);
|
||||||
void go(Position& pos, istringstream& up);
|
void go(Position& pos, istringstream& up);
|
||||||
void perft(Position& pos, istringstream& up);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,8 +57,6 @@ void uci_loop(const string& args) {
|
||||||
Position pos(StartFEN, false, Threads.main_thread()); // The root position
|
Position pos(StartFEN, false, Threads.main_thread()); // The root position
|
||||||
string cmd, token;
|
string cmd, token;
|
||||||
|
|
||||||
Search::RootPosition = pos;
|
|
||||||
|
|
||||||
while (token != "quit")
|
while (token != "quit")
|
||||||
{
|
{
|
||||||
if (!args.empty())
|
if (!args.empty())
|
||||||
|
@ -108,9 +104,6 @@ void uci_loop(const string& args) {
|
||||||
else if (token == "setoption")
|
else if (token == "setoption")
|
||||||
set_option(is);
|
set_option(is);
|
||||||
|
|
||||||
else if (token == "perft")
|
|
||||||
perft(pos, is);
|
|
||||||
|
|
||||||
else if (token == "d")
|
else if (token == "d")
|
||||||
pos.print();
|
pos.print();
|
||||||
|
|
||||||
|
@ -121,7 +114,7 @@ void uci_loop(const string& args) {
|
||||||
cout << Eval::trace(pos) << endl;
|
cout << Eval::trace(pos) << endl;
|
||||||
|
|
||||||
else if (token == "bench")
|
else if (token == "bench")
|
||||||
benchmark(is);
|
benchmark(pos, is);
|
||||||
|
|
||||||
else if (token == "key")
|
else if (token == "key")
|
||||||
cout << "key: " << hex << pos.key()
|
cout << "key: " << hex << pos.key()
|
||||||
|
@ -132,6 +125,17 @@ void uci_loop(const string& args) {
|
||||||
cout << "id name " << engine_info(true)
|
cout << "id name " << engine_info(true)
|
||||||
<< "\n" << Options
|
<< "\n" << Options
|
||||||
<< "\nuciok" << endl;
|
<< "\nuciok" << endl;
|
||||||
|
|
||||||
|
else if (token == "perft" && (is >> token)) // Read depth
|
||||||
|
{
|
||||||
|
stringstream ss;
|
||||||
|
|
||||||
|
ss << Options["Hash"] << " "
|
||||||
|
<< Options["Threads"] << " " << token << " current perft";
|
||||||
|
|
||||||
|
benchmark(pos, ss);
|
||||||
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
cout << "Unknown command: " << cmd << endl;
|
cout << "Unknown command: " << cmd << endl;
|
||||||
|
|
||||||
|
@ -246,27 +250,4 @@ namespace {
|
||||||
|
|
||||||
Threads.start_searching(pos, limits, searchMoves);
|
Threads.start_searching(pos, limits, searchMoves);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// perft() is called when engine receives the "perft" command. The function
|
|
||||||
// calls perft() with the required search depth then prints counted leaf nodes
|
|
||||||
// and elapsed time.
|
|
||||||
|
|
||||||
void perft(Position& pos, istringstream& is) {
|
|
||||||
|
|
||||||
int depth;
|
|
||||||
|
|
||||||
if (!(is >> depth))
|
|
||||||
return;
|
|
||||||
|
|
||||||
Time time = Time::current_time();
|
|
||||||
|
|
||||||
int64_t n = Search::perft(pos, depth * ONE_PLY);
|
|
||||||
|
|
||||||
int e = time.elapsed();
|
|
||||||
|
|
||||||
cout << "\nNodes " << n
|
|
||||||
<< "\nTime (ms) " << e
|
|
||||||
<< "\nNodes/second " << int(n / (e / 1000.0)) << endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue