mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
Assorted cleanups in benchmark.cpp
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
9d7a36121a
commit
93e539d909
2 changed files with 34 additions and 39 deletions
|
@ -21,12 +21,14 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "misc.h"
|
||||
#include "position.h"
|
||||
#include "search.h"
|
||||
#include "thread.h"
|
||||
#include "ucioption.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Search;
|
||||
|
||||
static const char* Defaults[] = {
|
||||
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
|
||||
|
@ -44,8 +46,7 @@ static const char* Defaults[] = {
|
|||
"3r1rk1/p5pp/bpp1pp2/8/q1PP1P2/b3P3/P2NQRPP/1R2B1K1 b - - 6 22",
|
||||
"r1q2rk1/2p1bppp/2Pp4/p6b/Q1PNp3/4B3/PP1R1PPP/2K4R w - - 2 18",
|
||||
"4k2r/1pb2ppp/1p2p3/1R1p4/3P4/2r1PN2/P4PPP/1R4K1 b - - 3 22",
|
||||
"3q2k1/pb3p1p/4pbp1/2r5/PpN2N2/1P2P2P/5PP1/Q2R2K1 b - - 4 26",
|
||||
""
|
||||
"3q2k1/pb3p1p/4pbp1/2r5/PpN2N2/1P2P2P/5PP1/Q2R2K1 b - - 4 26"
|
||||
};
|
||||
|
||||
|
||||
|
@ -59,10 +60,10 @@ static const char* Defaults[] = {
|
|||
|
||||
void benchmark(int argc, char* argv[]) {
|
||||
|
||||
vector<string> fenList;
|
||||
Search::LimitsType limits;
|
||||
int64_t totalNodes;
|
||||
vector<string> fens;
|
||||
LimitsType limits;
|
||||
int time;
|
||||
int64_t nodes = 0;
|
||||
|
||||
// Assign default values to missing arguments
|
||||
string ttSize = argc > 2 ? argv[2] : "128";
|
||||
|
@ -71,70 +72,64 @@ void benchmark(int argc, char* argv[]) {
|
|||
string fenFile = argc > 5 ? argv[5] : "default";
|
||||
string valType = argc > 6 ? argv[6] : "depth";
|
||||
|
||||
Options["Hash"] = ttSize;
|
||||
Options["Hash"] = ttSize;
|
||||
Options["Threads"] = threads;
|
||||
Options["OwnBook"] = false;
|
||||
|
||||
// Search should be limited by nodes, time or depth ?
|
||||
if (valType == "nodes")
|
||||
limits.maxNodes = atoi(valStr.c_str());
|
||||
else if (valType == "time")
|
||||
if (valType == "time")
|
||||
limits.maxTime = 1000 * atoi(valStr.c_str()); // maxTime is in ms
|
||||
|
||||
else if (valType == "nodes")
|
||||
limits.maxNodes = atoi(valStr.c_str());
|
||||
|
||||
else
|
||||
limits.maxDepth = atoi(valStr.c_str());
|
||||
|
||||
// Do we need to load positions from a given FEN file?
|
||||
if (fenFile == "default")
|
||||
for (int i = 0; *Defaults[i]; i++)
|
||||
fenList.push_back(Defaults[i]);
|
||||
else
|
||||
if (fenFile != "default")
|
||||
{
|
||||
string fen;
|
||||
ifstream f(fenFile.c_str());
|
||||
ifstream file(fenFile.c_str());
|
||||
|
||||
if (!f.is_open())
|
||||
if (!file.is_open())
|
||||
{
|
||||
cerr << "Unable to open file " << fenFile << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while (getline(f, fen))
|
||||
while (getline(file, fen))
|
||||
if (!fen.empty())
|
||||
fenList.push_back(fen);
|
||||
fens.push_back(fen);
|
||||
|
||||
f.close();
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
fens.assign(Defaults, Defaults + 16);
|
||||
|
||||
// Ok, let's start the benchmark !
|
||||
totalNodes = 0;
|
||||
time = system_time();
|
||||
|
||||
for (size_t i = 0; i < fenList.size(); i++)
|
||||
for (size_t i = 0; i < fens.size(); i++)
|
||||
{
|
||||
Position pos(fenList[i], false, 0);
|
||||
Position pos(fens[i], false, 0);
|
||||
|
||||
cerr << "\nBench position: " << i + 1 << '/' << fenList.size() << endl;
|
||||
cerr << "\nPosition: " << i + 1 << '/' << fens.size() << endl;
|
||||
|
||||
if (valType == "perft")
|
||||
{
|
||||
int64_t cnt = Search::perft(pos, limits.maxDepth * ONE_PLY);
|
||||
|
||||
cerr << "\nPerft " << limits.maxDepth
|
||||
<< " nodes counted: " << cnt << endl;
|
||||
|
||||
totalNodes += cnt;
|
||||
int64_t cnt = perft(pos, limits.maxDepth * ONE_PLY);
|
||||
cerr << "\nPerft " << limits.maxDepth << " leaf nodes: " << cnt << endl;
|
||||
nodes += cnt;
|
||||
}
|
||||
else
|
||||
{
|
||||
Threads.start_thinking(pos, limits, vector<Move>(), false);
|
||||
totalNodes += Search::RootPosition.nodes_searched();
|
||||
nodes += RootPosition.nodes_searched();
|
||||
}
|
||||
}
|
||||
|
||||
time = system_time() - time;
|
||||
|
||||
cerr << "\n==============================="
|
||||
cerr << "\n==========================="
|
||||
<< "\nTotal time (ms) : " << time
|
||||
<< "\nNodes searched : " << totalNodes
|
||||
<< "\nNodes/second : " << (int)(totalNodes / (time / 1000.0)) << endl;
|
||||
<< "\nNodes searched : " << nodes
|
||||
<< "\nNodes/second : " << int(nodes / (time / 1000.0)) << endl;
|
||||
}
|
||||
|
|
|
@ -252,22 +252,22 @@ void Search::init() {
|
|||
int64_t Search::perft(Position& pos, Depth depth) {
|
||||
|
||||
StateInfo st;
|
||||
int64_t sum = 0;
|
||||
int64_t cnt = 0;
|
||||
|
||||
MoveList<MV_LEGAL> ml(pos);
|
||||
|
||||
// At the last ply just return the number of moves (leaf nodes)
|
||||
if (depth <= ONE_PLY)
|
||||
if (depth == ONE_PLY)
|
||||
return ml.size();
|
||||
|
||||
CheckInfo ci(pos);
|
||||
for ( ; !ml.end(); ++ml)
|
||||
{
|
||||
pos.do_move(ml.move(), st, ci, pos.move_gives_check(ml.move(), ci));
|
||||
sum += perft(pos, depth - ONE_PLY);
|
||||
cnt += perft(pos, depth - ONE_PLY);
|
||||
pos.undo_move(ml.move());
|
||||
}
|
||||
return sum;
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue