Book.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #ifndef OPENINGBOOK_HPP
00007 #define OPENINGBOOK_HPP
00008
00009 #include "Hex.hpp"
00010 #include "HexBoard.hpp"
00011 #include "HashDB.hpp"
00012 #include "HexEval.hpp"
00013 #include "StateDB.hpp"
00014 #include "SgBookBuilder.h"
00015
00016 _BEGIN_BENZENE_NAMESPACE_
00017
00018
00019
00020
00021 class HexBookNode : public SgBookNode
00022 {
00023 public:
00024 HexBookNode();
00025
00026 HexBookNode(float heurValue);
00027
00028 HexBookNode(const SgBookNode& node);
00029
00030
00031
00032
00033 int PackedSize() const;
00034
00035 byte* Pack() const;
00036
00037 void Unpack(const byte* t);
00038
00039 void Rotate(const ConstBoard& brd);
00040
00041
00042
00043 private:
00044 };
00045
00046 inline HexBookNode::HexBookNode()
00047 : SgBookNode()
00048 {
00049 }
00050
00051 inline HexBookNode::HexBookNode(float heurValue)
00052 : SgBookNode(heurValue)
00053 {
00054 }
00055
00056 inline HexBookNode::HexBookNode(const SgBookNode& node)
00057 : SgBookNode(node)
00058 {
00059 }
00060
00061 inline int HexBookNode::PackedSize() const
00062 {
00063 return sizeof(HexBookNode);
00064 }
00065
00066 inline byte* HexBookNode::Pack() const
00067 {
00068 return (byte*)this;
00069 }
00070
00071 inline void HexBookNode::Unpack(const byte* t)
00072 {
00073 *this = *(const HexBookNode*)t;
00074 }
00075
00076 inline void HexBookNode::Rotate(const ConstBoard& brd)
00077 {
00078 SG_UNUSED(brd);
00079
00080 }
00081
00082
00083
00084
00085 class Book : public StateDB<HexBookNode>
00086 {
00087 public:
00088 static const std::string BOOK_DB_VERSION;
00089
00090 Book(const std::string& filename)
00091 : StateDB<HexBookNode>(filename, BOOK_DB_VERSION)
00092 { }
00093 };
00094
00095
00096
00097
00098
00099
00100 namespace BookUtil
00101 {
00102
00103 float Value(const SgBookNode& node, const HexState& brd);
00104
00105
00106
00107
00108
00109
00110 float Score(const SgBookNode& node, const HexState& brd,
00111 float countWeight);
00112
00113
00114 float InverseEval(float eval);
00115
00116
00117
00118
00119
00120
00121
00122 HexPoint BestMove(const Book& book, const HexState& state,
00123 unsigned minCount, float countWeight);
00124
00125
00126
00127
00128
00129 void DumpVisualizationData(const Book& book, const HexState& state,
00130 int depth, std::ostream& out);
00131
00132
00133
00134
00135
00136
00137 void DumpPolarizedLeafs(const Book& book, const HexState& state,
00138 float polarization, PointSequence& pv,
00139 std::ostream& out, const StateSet& ignoreSet);
00140
00141
00142
00143 void ImportSolvedStates(Book& book, const ConstBoard& constBoard,
00144 std::istream& positions);
00145
00146
00147
00148
00149 int GetMainLineDepth(const Book& book, const HexState& state);
00150
00151
00152
00153 std::size_t GetTreeSize(const Book& book, const HexState& state);
00154 }
00155
00156
00157
00158 _END_BENZENE_NAMESPACE_
00159
00160 #endif // OPENINGBOOK_HPP