00001 //---------------------------------------------------------------------------- 00002 /** @file GoNodeUtil.h 00003 Utility functions for Go trees. */ 00004 //---------------------------------------------------------------------------- 00005 00006 #ifndef GO_NODEUTIL_H 00007 #define GO_NODEUTIL_H 00008 00009 #include "GoKomi.h" 00010 #include "SgBlackWhite.h" 00011 #include "SgBWArray.h" 00012 #include "SgPoint.h" 00013 #include "SgVector.h" 00014 00015 class GoBoard; 00016 class SgNode; 00017 00018 //---------------------------------------------------------------------------- 00019 00020 namespace GoNodeUtil 00021 { 00022 /** Create a root node containing a given board position. */ 00023 template<class BOARD> SgNode* CreateRoot(const BOARD& board); 00024 00025 /** Create a position with given size, toPlay, b and w points */ 00026 SgNode* CreatePosition(int boardSize, SgBlackWhite toPlay, 00027 const SgVector<SgPoint>& bPoints, 00028 const SgVector<SgPoint>& wPoints); 00029 00030 /** Find komi that is valid for this node. 00031 Search parent nodes until a node with a komi property is found. */ 00032 GoKomi GetKomi(const SgNode* node); 00033 00034 /** Find handicap that is valid for this node. 00035 Search parent nodes until a node with a handicap property is found. */ 00036 int GetHandicap(const SgNode* node); 00037 } 00038 00039 //---------------------------------------------------------------------------- 00040 00041 template<class BOARD> 00042 SgNode* GoNodeUtil::CreateRoot(const BOARD& board) 00043 { 00044 SgBWArray<SgVector<SgPoint> > pointList; 00045 for (typename BOARD::Iterator it(board); it; ++it) 00046 { 00047 if (board.Occupied(*it)) 00048 pointList[board.GetColor(*it)].PushBack(*it); 00049 } 00050 return CreatePosition(board.Size(), board.ToPlay(), 00051 pointList[SG_BLACK], pointList[SG_WHITE]); 00052 } 00053 00054 //---------------------------------------------------------------------------- 00055 00056 #endif // GO_NODEUTIL_H 00057