usiReporter.cc
Go to the documentation of this file.
00001 /* usiReporter.cc
00002  */
00003 #include "osl/search/usiReporter.h"
00004 #include "osl/record/usi.h"
00005 #include "osl/misc/lightMutex.h"
00006 #include "osl/misc/milliSeconds.h"
00007 #include "osl/oslConfig.h"
00008 #include <iostream>
00009 
00010 void osl::search::
00011 UsiReporter::newDepth(int depth)
00012 {
00013   if (OslConfig::usiModeInSilent())
00014     return;
00015   std::ostream& os = std::cout;
00016   os << "info depth " << depth << "\n";
00017 }
00018 void osl::search::
00019 UsiReporter::showPV(int depth, size_t node_count, double elapsed, int value, Move cur, const Move *first, const Move *last, bool ignore_silent)
00020 {
00021   if (OslConfig::usiModeInSilent() && ! ignore_silent)
00022     return;
00023   int seldepth = last-first;
00024   if (last - first && *first != cur)
00025     ++seldepth;
00026   if (ignore_silent)
00027     std::cerr << "info depth " << depth << " seldepth " << seldepth
00028               << " time " << static_cast<int>(elapsed*1000) << " score cp " << value
00029               << " nodes " << node_count
00030               << " nps " << static_cast<int>(node_count/elapsed)
00031               << " pv " << record::usi::show(cur) << "\n";
00032   std::ostream& os = std::cout;
00033   os << "info depth " << depth << " seldepth " << seldepth
00034      << " time " << static_cast<int>(elapsed*1000) << " score cp " << value
00035      << " nodes " << node_count << " nps " << static_cast<int>(node_count/elapsed);
00036   os << " pv " << record::usi::show(cur);
00037   if (first != last) {
00038     if (cur == *first)
00039       ++first;
00040     while (first != last) {
00041       os << ' ' << record::usi::show(*first++);
00042     }
00043   }
00044   os << "\n";
00045 }
00046 
00047 static osl::misc::LightMutex usi_root_move_mutex;
00048 void osl::search::
00049 UsiReporter::rootMove(Move cur, bool allow_frequent_display)
00050 {
00051   if (OslConfig::usiModeInSilent())
00052     return;
00053   static MilliSeconds prev;
00054   if (! allow_frequent_display) 
00055   {
00056     MilliSeconds now = MilliSeconds::now();
00057     {
00058       SCOPED_LOCK(lk, usi_root_move_mutex);
00059       if ((now - prev).toSeconds() < 0.5)
00060         return;
00061       prev = now;
00062     }
00063   }
00064   std::ostream& os = std::cout;
00065   os << "info currmove " << record::usi::show(cur) << "\n";
00066 }
00067 
00068 void osl::search::
00069 UsiReporter::timeInfo(size_t node_count, double elapsed)
00070 {
00071   if (OslConfig::usiModeInSilent())
00072     return;
00073   std::ostream& os = std::cout;
00074     os << "info time " << static_cast<int>(elapsed*1000)
00075        << " nodes " << node_count << " nps " << static_cast<int>(node_count/elapsed) << "\n";
00076   os << std::flush;
00077 }
00078 
00079 void osl::search::
00080 UsiReporter::hashInfo(double ratio)
00081 {
00082   if (OslConfig::usiModeInSilent())
00083     return;
00084   std::ostream& os = std::cout;
00085     os << "info hashfull " << static_cast<int>(ratio*1000) << "\n";
00086   os << std::flush;
00087 }
00088 
00089 
00090 
00091 osl::search::
00092 UsiMonitor::~UsiMonitor()
00093 {
00094 }
00095 
00096 void osl::search::
00097 UsiMonitor::newDepth(int depth)
00098 {
00099   UsiReporter::newDepth(depth);
00100   last_root_move = Move();
00101 }
00102 
00103 void osl::search::
00104 UsiMonitor::showPV(int depth, size_t node_count, double elapsed, int value, Move cur, const Move *first, const Move *last)
00105 {
00106   UsiReporter::showPV(depth, node_count, elapsed, value, cur, first, last);
00107 }
00108 
00109 void osl::search::
00110 UsiMonitor::rootMove(Move cur)
00111 {
00112   last_root_move = cur;
00113 }
00114 
00115 void osl::search::
00116 UsiMonitor::rootFirstMove(Move cur)
00117 {
00118   last_root_move = cur;
00119   UsiReporter::rootMove(cur, true);
00120 }
00121 
00122 void osl::search::
00123 UsiMonitor::timeInfo(size_t node_count, double elapsed)
00124 {
00125   UsiReporter::timeInfo(node_count, elapsed);
00126   UsiReporter::rootMove(last_root_move);
00127 }
00128 
00129 void osl::search::
00130 UsiMonitor::hashInfo(double ratio)
00131 {
00132   UsiReporter::hashInfo(ratio);
00133 }
00134 
00135 void osl::search::
00136 UsiMonitor::rootForcedMove(Move the_move)
00137 {
00138   if (OslConfig::usiModeInSilent())
00139     return;
00140   std::ostream& os = std::cout;
00141   os << "info string forced move at the root: "
00142      << record::usi::show(the_move) << "\n";
00143   os << std::flush;
00144 }
00145 
00146 void osl::search::
00147 UsiMonitor::rootLossByCheckmate()
00148 {
00149   if (OslConfig::usiModeInSilent())
00150     return;
00151   std::ostream& os = std::cout;
00152   os << "info string loss by checkmate\n";
00153   os << std::flush;
00154 }
00155 
00156 // ;;; Local Variables:
00157 // ;;; mode:c++
00158 // ;;; c-basic-offset:2
00159 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines