00001 //---------------------------------------------------------------------------- 00002 /** @file SgUctTreeUtil.h 00003 Utility functions for users of SgUctSearch.h */ 00004 //---------------------------------------------------------------------------- 00005 00006 #ifndef SG_UCTTREEUTIL_H 00007 #define SG_UCTTREEUTIL_H 00008 00009 #include <cstddef> 00010 #include <iosfwd> 00011 #include "SgUctValue.h" 00012 #include "SgStatistics.h" 00013 00014 class SgUctNode; 00015 class SgUctTree; 00016 00017 //---------------------------------------------------------------------------- 00018 00019 /** Statistical properties of a SgUctTree. 00020 @ingroup sguctgroup */ 00021 class SgUctTreeStatistics 00022 { 00023 public: 00024 /** See m_posCounts */ 00025 static const std::size_t MAX_MOVECOUNT = 5; 00026 00027 std::size_t m_nuNodes; 00028 00029 /** Number of nodes that have a certain move count. */ 00030 std::size_t m_moveCounts[MAX_MOVECOUNT]; 00031 00032 /** Difference between move value and RAVE value. */ 00033 SgStatisticsExt<SgUctValue,std::size_t> m_biasRave; 00034 00035 SgUctTreeStatistics(); 00036 00037 void Clear(); 00038 00039 /** Clear statistics and traverse tree to compute statistics. */ 00040 void Compute(const SgUctTree& tree); 00041 00042 void Write(std::ostream& out) const; 00043 }; 00044 00045 /** Write a SgUctTreeStatistics. 00046 @relatesalso SgUctTreeStatistics */ 00047 std::ostream& operator<<(std::ostream& out, const SgUctTreeStatistics& stat); 00048 00049 //---------------------------------------------------------------------------- 00050 00051 /** Utility functions for users of SgUctTree. 00052 @ingroup sguctgroup */ 00053 namespace SgUctTreeUtil 00054 { 00055 /** Extract the subtree from the node after a sequence of moves. 00056 The result is an empty tree, if the sequence of moves does 00057 not correspond to a sequence of nodes from the root node in the 00058 given tree. 00059 @param tree The source tree. 00060 @param[out] target The target tree (will be cleared before using it). 00061 @param sequence The sequence of moves. 00062 @param warnTruncate See SgUctTree::ExtractSubtree 00063 @param maxTime See SgUctTree::ExtractSubtree 00064 @param minCount */ 00065 void ExtractSubtree(const SgUctTree& tree, SgUctTree& target, 00066 const std::vector<SgMove>& sequence, 00067 bool warnTruncate, 00068 double maxTime = std::numeric_limits<double>::max(), 00069 SgUctValue minCount = 0); 00070 00071 /** Find move node with a given move. 00072 @return The child node or 0, if the position node has no such child. */ 00073 const SgUctNode* FindChildWithMove(const SgUctTree& tree, 00074 const SgUctNode& node, SgMove move); 00075 00076 } // namespace SgUctTreeUtil 00077 00078 //---------------------------------------------------------------------------- 00079 00080 #endif // SG_UCTTREEUTIL_H