]> git.sesse.net Git - stockfish/blobdiff - src/benchmark.cpp
Retire RootMoveList
[stockfish] / src / benchmark.cpp
index df4978709f1e758a96b5b5aeac22c1e6bc67662b..9f32dbae3a2f3e6a1d2b0c76152c59090b6e59fb 100644 (file)
 
 #include "position.h"
 #include "search.h"
+#include "thread.h"
 #include "ucioption.h"
 
 using namespace std;
 
-static const string Defaults[] = {
+static const char* Defaults[] = {
   "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
-  "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -",
-  "8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -",
+  "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 10",
+  "8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - 0 11",
   "4rrk1/pp1n3p/3q2pQ/2p1pb2/2PP4/2P3N1/P2B2PP/4RRK1 b - - 7 19",
   "rq3rk1/ppp2ppp/1bnpb3/3N2B1/3NP3/7P/PPPQ1PP1/2KR3R w - - 7 14",
   "r1bq1r1k/1pp1n1pp/1p1p4/4p2Q/4Pp2/1BNP4/PPP2PPP/3R1RK1 w - - 2 14",
@@ -49,25 +50,20 @@ static const string Defaults[] = {
 
 
 /// benchmark() runs a simple benchmark by letting Stockfish analyze a set
-/// of positions for a given limit each.  There are five parameters; the
+/// of positions for a given limit each. There are five parameters; the
 /// transposition table size, the number of search threads that should
-/// be used, the limit value spent for each position (optional, default
-/// is ply 12), an optional file name where to look for positions in fen
-/// format (default are the BenchmarkPositions defined above) and the type
-/// of the limit value: depth (default), time in secs or number of nodes.
-/// The analysis is written to a file named bench.txt.
+/// be used, the limit value spent for each position (optional, default is
+/// depth 12), an optional file name where to look for positions in fen
+/// format (defaults are the positions defined above) and the type of the
+/// limit value: depth (default), time in secs or number of nodes.
 
 void benchmark(int argc, char* argv[]) {
 
   vector<string> fenList;
-  SearchLimits limits;
+  Search::LimitsType limits;
   int64_t totalNodes;
   int time;
 
-  // Load default positions
-  for (int i = 0; !Defaults[i].empty(); i++)
-      fenList.push_back(Defaults[i]);
-
   // Assign default values to missing arguments
   string ttSize  = argc > 2 ? argv[2] : "128";
   string threads = argc > 3 ? argv[3] : "1";
@@ -87,27 +83,26 @@ void benchmark(int argc, char* argv[]) {
   else
       limits.maxDepth = atoi(valStr.c_str());
 
-  // Do we need to load positions from a given FEN file ?
-  if (fenFile != "default")
+  // 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
   {
       string fen;
       ifstream f(fenFile.c_str());
 
-      if (f.is_open())
-      {
-          fenList.clear();
-
-          while (getline(f, fen))
-              if (!fen.empty())
-                  fenList.push_back(fen);
-
-          f.close();
-      }
-      else
+      if (!f.is_open())
       {
-          cerr << "Unable to open FEN file " << fenFile << endl;
+          cerr << "Unable to open file " << fenFile << endl;
           exit(EXIT_FAILURE);
       }
+
+      while (getline(f, fen))
+          if (!fen.empty())
+              fenList.push_back(fen);
+
+      f.close();
   }
 
   // Ok, let's start the benchmark !
@@ -116,24 +111,23 @@ void benchmark(int argc, char* argv[]) {
 
   for (size_t i = 0; i < fenList.size(); i++)
   {
-      Move moves[] = { MOVE_NONE };
       Position pos(fenList[i], false, 0);
 
       cerr << "\nBench position: " << i + 1 << '/' << fenList.size() << endl;
 
       if (valType == "perft")
       {
-          int64_t cnt = perft(pos, limits.maxDepth * ONE_PLY);
-          totalNodes += cnt;
+          int64_t cnt = Search::perft(pos, limits.maxDepth * ONE_PLY);
 
-          cerr << "\nPerft " << limits.maxDepth << " nodes counted: " << cnt << endl;
+          cerr << "\nPerft " << limits.maxDepth
+               << " nodes counted: " << cnt << endl;
+
+          totalNodes += cnt;
       }
       else
       {
-          if (!think(pos, limits, moves))
-              break;
-
-          totalNodes += pos.nodes_searched();
+          Threads.start_thinking(pos, limits, vector<Move>(), false);
+          totalNodes += Search::RootPosition.nodes_searched();
       }
   }
 
@@ -142,12 +136,5 @@ void benchmark(int argc, char* argv[]) {
   cerr << "\n==============================="
        << "\nTotal time (ms) : " << time
        << "\nNodes searched  : " << totalNodes
-       << "\nNodes/second    : " << (int)(totalNodes / (time / 1000.0)) << endl << endl;
-
-  // MS Visual C++ debug window always unconditionally closes when program
-  // exits, this is bad because we want to read results before.
-  #if (defined(WINDOWS) || defined(WIN32) || defined(WIN64))
-  cerr << "Press any key to exit" << endl;
-  cin >> time;
-  #endif
+       << "\nNodes/second    : " << (int)(totalNodes / (time / 1000.0)) << endl;
 }