Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgSearchValue.cpp

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


17 Jun 2010 Doxygen 1.4.7