Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

GoNodeUtil.cpp

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


Sun Mar 13 2011 Doxygen 1.7.1