00001 //---------------------------------------------------------------------------- 00002 /** @file GoUtil.cpp 00003 See GoUtil.h 00004 */ 00005 //---------------------------------------------------------------------------- 00006 00007 #include "SgSystem.h" 00008 #include "GoUtil.h" 00009 00010 #include <cmath> 00011 #include <iomanip> 00012 #include <sstream> 00013 00014 using namespace std; 00015 00016 //---------------------------------------------------------------------------- 00017 00018 std::string GoUtil::ScoreToString(float score) 00019 { 00020 bool blackWin = (score > 0); 00021 score = fabs(score); 00022 const float epsilon = 0.01f; 00023 if (score < epsilon) 00024 return "0"; 00025 ostringstream out; 00026 bool isFractional = (fabs(static_cast<int>(score) - score) > epsilon); 00027 int precision = (isFractional ? 1 : 0); 00028 out << (blackWin ? "B+" : "W+") << fixed << setprecision(precision) 00029 << score; 00030 return out.str(); 00031 } 00032 00033 //----------------------------------------------------------------------------