Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

GoNodeUtil.h

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


17 Jun 2010 Doxygen 1.4.7