00001 //---------------------------------------------------------------------------- 00002 /** @file SgNodeUtil.cpp 00003 See SgNodeUtil.h 00004 */ 00005 //---------------------------------------------------------------------------- 00006 00007 #include "SgSystem.h" 00008 #include "SgNodeUtil.h" 00009 00010 #include <vector> 00011 #include "SgNode.h" 00012 #include "SgTimeRecord.h" 00013 00014 using namespace std; 00015 00016 //---------------------------------------------------------------------------- 00017 00018 int SgNodeUtil::GetMoveNumber(const SgNode* node) 00019 { 00020 int nuMoves = 0; 00021 while (node != 0) 00022 { 00023 if (node->HasProp(SG_PROP_MOVE)) 00024 ++nuMoves; 00025 if (node->HasProp(SG_PROP_ADD_BLACK) 00026 || node->HasProp(SG_PROP_ADD_WHITE) 00027 || node->HasProp(SG_PROP_ADD_EMPTY)) 00028 break; 00029 node = node->Father(); 00030 } 00031 return nuMoves; 00032 } 00033 00034 void SgNodeUtil::UpdateTime(SgTimeRecord& time, const SgNode* node) 00035 { 00036 vector<const SgNode*> nodes; 00037 while (node != 0) 00038 { 00039 nodes.push_back(node); 00040 node = node->Father(); 00041 } 00042 for (vector<const SgNode*>::reverse_iterator it = nodes.rbegin(); 00043 it != nodes.rend(); ++it) 00044 { 00045 const SgNode* node = *it; 00046 if (node->HasProp(SG_PROP_LOSE_TIME)) 00047 time.SetLoseOnTime(true); 00048 if (node->HasProp(SG_PROP_OT_NU_MOVES)) 00049 time.SetOTNumMoves(node->GetIntProp(SG_PROP_OT_NU_MOVES)); 00050 if (node->HasProp(SG_PROP_OT_PERIOD)) 00051 time.SetOTPeriod(node->GetRealProp(SG_PROP_OT_PERIOD)); 00052 if (node->HasProp(SG_PROP_OVERHEAD)) 00053 time.SetOverhead(node->GetRealProp(SG_PROP_OVERHEAD)); 00054 } 00055 } 00056 00057 //----------------------------------------------------------------------------