00001 //---------------------------------------------------------------------------- 00002 /** @file 00003 */ 00004 //---------------------------------------------------------------------------- 00005 00006 #ifndef HEXSGUTIL_HPP 00007 #define HEXSGUTIL_HPP 00008 00009 #include "SgBlackWhite.h" 00010 #include "SgPoint.h" 00011 #include "SgProp.h" 00012 #include "SgNode.h" 00013 00014 #include "Hex.hpp" 00015 #include "StoneBoard.hpp" 00016 00017 _BEGIN_BENZENE_NAMESPACE_ 00018 00019 //---------------------------------------------------------------------------- 00020 00021 /** Utilities to convert from/to Hex and Sg. */ 00022 namespace HexSgUtil 00023 { 00024 /** Converts a HexPoint to a SgPoint. */ 00025 SgPoint HexPointToSgPoint(HexPoint p, int height); 00026 00027 /** Converts from from a SgPoint to a HexPoint. */ 00028 HexPoint SgPointToHexPoint(SgPoint p, int height); 00029 00030 /** Converts a HexColor to SgBlackWhite, color must not equal 00031 EMPTY. */ 00032 SgBlackWhite HexColorToSgColor(HexColor color); 00033 00034 /** Converts a SgBlackWhite to a HexColor. */ 00035 HexColor SgColorToHexColor(SgBlackWhite player); 00036 00037 /** Convert a bitset to an SgList of points. */ 00038 SgVector<SgPoint> BitsetToSgVector(const bitset_t& b, int height); 00039 00040 //------------------------------------------------------------------------ 00041 00042 /** Adds the move to the sg node; does proper conversions. */ 00043 void AddMoveToNode(SgNode* node, HexColor color, 00044 HexPoint cell, int height); 00045 00046 /** Returns true if node constains any of the following 00047 properties: propAddBlack, propAddWhite, propAddEmpty, 00048 propPlayer. */ 00049 bool NodeHasSetupInfo(SgNode* node); 00050 00051 /** Set the position setup properties of this node to encode the 00052 given board.*/ 00053 void SetPositionInNode(SgNode* root, 00054 const StoneBoard& brd, 00055 HexColor color); 00056 00057 /** Puts the position in the given vectors. */ 00058 void GetSetupPosition(const SgNode* node, 00059 int height, 00060 std::vector<HexPoint>& black, 00061 std::vector<HexPoint>& white, 00062 std::vector<HexPoint>& empty); 00063 00064 /** Sets node's position in the board. */ 00065 void SetPositionInBoard(const SgNode* node, StoneBoard& brd); 00066 00067 //------------------------------------------------------------------------ 00068 00069 /** Write the given tree to a sgf file. Returns true on success, 00070 false otherwise. */ 00071 bool WriteSgf(SgNode* tree, const char* filename, int boardsize); 00072 } 00073 00074 //---------------------------------------------------------------------------- 00075 00076 _END_BENZENE_NAMESPACE_ 00077 00078 #endif // HEXSGUTIL_HPP