00001 //---------------------------------------------------------------------------- 00002 /** @file SgSearchValue.cpp 00003 See SgSearchValue.h. */ 00004 //---------------------------------------------------------------------------- 00005 00006 #include "SgSystem.h" 00007 #include "SgSearchValue.h" 00008 00009 #include <algorithm> 00010 #include <iomanip> 00011 #include <limits> 00012 #include <sstream> 00013 #include <math.h> 00014 00015 using namespace std; 00016 00017 //---------------------------------------------------------------------------- 00018 00019 /** Set '*s' to the string for this value. 00020 e.g. "B+3.5", "W+20", or "W+(ko)[12]". The value is divided by 00021 'unitPerPoint' to determine the number of points. */ 00022 string SgSearchValue::ToString(int unitPerPoint) const 00023 { 00024 if (m_value == 0) 00025 return "0"; 00026 ostringstream stream; 00027 stream << (m_value > 0 ? "B+" : "W+"); 00028 if (IsEstimate()) 00029 { 00030 if (unitPerPoint == 1) 00031 stream << (abs(m_value) / unitPerPoint); 00032 else 00033 stream << setprecision(1) 00034 << (float(abs(m_value)) / float(unitPerPoint)); 00035 } 00036 else 00037 { 00038 if (KoLevel() != 0) 00039 stream << "(ko)"; 00040 if (Depth() != 0) 00041 { 00042 stream << " (" << Depth() << " moves)"; 00043 } 00044 } 00045 return stream.str(); 00046 } 00047 00048 bool SgSearchValue::FromString(const string& s) 00049 { 00050 SG_UNUSED(s); 00051 SG_ASSERT(false); // AR: not yet implemented 00052 return false; 00053 } 00054 00055 int SgSearchValue::KoLevel() const 00056 { 00057 if (IsEstimate()) 00058 return 0; 00059 else 00060 { 00061 int level = (abs(m_value) - 1) / SgSearch::MAX_DEPTH; 00062 return (MAX_LEVEL - 1) - level; 00063 } 00064 } 00065 00066 //---------------------------------------------------------------------------- 00067