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