00001 //---------------------------------------------------------------------------- 00002 /** @file GoNodeUtil.cpp 00003 */ 00004 //---------------------------------------------------------------------------- 00005 00006 #include "SgSystem.h" 00007 #include "GoNodeUtil.h" 00008 00009 #include "GoBoard.h" 00010 #include "SgNode.h" 00011 00012 using namespace std; 00013 00014 //---------------------------------------------------------------------------- 00015 00016 00017 SgNode* GoNodeUtil::CreatePosition(int boardSize, SgBlackWhite toPlay, 00018 const SgVector<SgPoint>& bPoints, 00019 const SgVector<SgPoint>& wPoints) 00020 { 00021 SgNode* node = new SgNode(); 00022 node->Add(new SgPropInt(SG_PROP_SIZE, boardSize)); 00023 node->Add(new SgPropPlayer(SG_PROP_PLAYER, toPlay)); 00024 node->Add(new SgPropAddStone(SG_PROP_ADD_BLACK, bPoints)); 00025 node->Add(new SgPropAddStone(SG_PROP_ADD_WHITE, wPoints)); 00026 return node; 00027 } 00028 00029 GoKomi GoNodeUtil::GetKomi(const SgNode* node) 00030 { 00031 while (node != 0) 00032 { 00033 if (node->HasProp(SG_PROP_KOMI)) 00034 { 00035 try 00036 { 00037 return GoKomi(static_cast<float> 00038 (node->GetRealProp(SG_PROP_KOMI))); 00039 } 00040 catch (const GoKomi::InvalidKomi&) 00041 { 00042 break; 00043 } 00044 } 00045 node = node->Father(); 00046 } 00047 return GoKomi(); 00048 } 00049 00050 int GoNodeUtil::GetHandicap(const SgNode* node) 00051 { 00052 while (node != 0) 00053 { 00054 if (node->HasProp(SG_PROP_HANDICAP)) 00055 return node->GetIntProp(SG_PROP_HANDICAP); 00056 node = node->Father(); 00057 } 00058 return 0; 00059 } 00060 00061 //---------------------------------------------------------------------------- 00062