Simple text-based book format. More...
#include <GoAutoBook.h>
Public Member Functions | |
GoAutoBook (const std::string &filename, const GoAutoBookParam ¶m) | |
~GoAutoBook () | |
bool | Get (const GoAutoBookState &state, SgBookNode &node) const |
Read the node at the given state. | |
void | Put (const GoAutoBookState &state, const SgBookNode &node) |
Store the node in the given state. | |
void | Flush () |
Since there is no cache, same as Save(). | |
void | Save (const std::string &filename) const |
Writes book to disk. | |
SgMove | LookupMove (const GoBoard &brd) const |
Helper function: calls FindBestChild() on the given board. | |
SgMove | FindBestChild (GoAutoBookState &state) const |
Returns the move leading to the best child state. | |
void | Merge (const GoAutoBook &other) |
Merge this book with given book. | |
void | AddDisabledLines (const std::set< SgHashCode > &disabled) |
Add states to be disabled. | |
void | TruncateByDepth (int depth, GoAutoBookState &state, GoAutoBook &other) const |
Copies a truncated version of the book into other. | |
void | ImportHashValuePairs (std::istream &in) |
Overwrites values in book by reading stream of (hash, value) pairs. | |
void | ExportToOldFormat (GoAutoBookState &state, std::ostream &os) const |
Exports book states under the given state in GoBook format to the given stream. | |
Static Public Member Functions | |
static std::vector < std::vector< SgMove > > | ParseWorkList (std::istream &in) |
Parses a worklist from a stream. | |
Private Types | |
typedef std::map< SgHashCode, SgBookNode > | Map |
Private Member Functions | |
void | TruncateByDepth (int depth, GoAutoBookState &state, GoAutoBook &other, std::set< SgHashCode > &seen) const |
void | ExportToOldFormat (GoAutoBookState &state, std::ostream &out, std::set< SgHashCode > &seen) const |
Private Attributes | |
Map | m_data |
const GoAutoBookParam & | m_param |
std::set< SgHashCode > | m_disabled |
std::string | m_filename |
Simple text-based book format.
Entire book is loaded into memory.
Definition at line 88 of file GoAutoBook.h.
typedef std::map<SgHashCode, SgBookNode> GoAutoBook::Map [private] |
Definition at line 152 of file GoAutoBook.h.
GoAutoBook::GoAutoBook | ( | const std::string & | filename, | |
const GoAutoBookParam & | param | |||
) |
Definition at line 78 of file GoAutoBook.cpp.
References SgHash< N >::FromString(), m_data, and SgDebug().
GoAutoBook::~GoAutoBook | ( | ) |
Definition at line 111 of file GoAutoBook.cpp.
void GoAutoBook::AddDisabledLines | ( | const std::set< SgHashCode > & | disabled | ) |
Add states to be disabled.
These states will not be considered for selection in FindBestChild() from the parent state.
Definition at line 171 of file GoAutoBook.h.
References m_disabled, and SgDebug().
void GoAutoBook::ExportToOldFormat | ( | GoAutoBookState & | state, | |
std::ostream & | os | |||
) | const |
Exports book states under the given state in GoBook format to the given stream.
Only the move that would be selected with FindBestMove() is given as an option in each state.
Definition at line 378 of file GoAutoBook.cpp.
Referenced by ExportToOldFormat().
void GoAutoBook::ExportToOldFormat | ( | GoAutoBookState & | state, | |
std::ostream & | out, | |||
std::set< SgHashCode > & | seen | |||
) | const [private] |
Definition at line 348 of file GoAutoBook.cpp.
References GoAutoBookState::Board(), ExportToOldFormat(), FindBestChild(), Get(), GoAutoBookState::GetHashCode(), SgBookNode::IsLeaf(), GoBoard::IsLegal(), SgBookNode::IsTerminal(), GoBoard::Move(), GoBoard::MoveNumber(), GoAutoBookState::Play(), GoPlayerMove::Point(), SG_NULLMOVE, GoBoard::Size(), and GoAutoBookState::Undo().
SgMove GoAutoBook::FindBestChild | ( | GoAutoBookState & | state | ) | const |
Returns the move leading to the best child state.
The best child state depends on the move selection criteria. See GoAutoBookParam.
Definition at line 280 of file GoAutoBook.cpp.
References GoAutoBookState::Board(), Get(), GoAutoBookState::GetHashCode(), GO_AUTOBOOK_SELECT_COUNT, GO_AUTOBOOK_SELECT_VALUE, SgBookNode::IsLeaf(), GoBoard::IsLegal(), SgBookNode::IsTerminal(), SgBookNode::m_count, m_disabled, m_param, GoAutoBookParam::m_selectType, GoAutoBookParam::m_usageCountThreshold, SgBookNode::m_value, GoAutoBookState::Play(), SG_NULLMOVE, SgDebug(), and GoAutoBookState::Undo().
Referenced by ExportToOldFormat(), and LookupMove().
void GoAutoBook::Flush | ( | ) |
Since there is no cache, same as Save().
Definition at line 131 of file GoAutoBook.cpp.
References m_filename, and Save().
bool GoAutoBook::Get | ( | const GoAutoBookState & | state, | |
SgBookNode & | node | |||
) | const |
Read the node at the given state.
Returns true if node exists in the book, and false otherwise.
Definition at line 115 of file GoAutoBook.cpp.
References GoAutoBookState::GetHashCode(), and m_data.
Referenced by ExportToOldFormat(), FindBestChild(), and TruncateByDepth().
void GoAutoBook::ImportHashValuePairs | ( | std::istream & | in | ) |
Overwrites values in book by reading stream of (hash, value) pairs.
Definition at line 249 of file GoAutoBook.cpp.
References SgHash< N >::FromString(), m_data, SgBookNode::m_heurValue, SgBookNode::m_value, and SgDebug().
Helper function: calls FindBestChild() on the given board.
Definition at line 339 of file GoAutoBook.cpp.
References FindBestChild(), and GoAutoBookState::Synchronize().
void GoAutoBook::Merge | ( | const GoAutoBook & | other | ) |
Merge this book with given book.
Internal nodes in either book become internal nodes in merged book, counts are clobbered (max is taken). Leafs in both books are leafs in merged book, value is the set to be the average.
Definition at line 147 of file GoAutoBook.cpp.
References SgBookNode::IsLeaf(), SgBookNode::m_count, m_data, SgBookNode::m_heurValue, and SgDebug().
std::vector< std::vector< SgMove > > GoAutoBook::ParseWorkList | ( | std::istream & | in | ) | [static] |
Parses a worklist from a stream.
Definition at line 387 of file GoAutoBook.cpp.
References SgDebug().
void GoAutoBook::Put | ( | const GoAutoBookState & | state, | |
const SgBookNode & | node | |||
) |
Store the node in the given state.
Definition at line 126 of file GoAutoBook.cpp.
References GoAutoBookState::GetHashCode(), and m_data.
Referenced by TruncateByDepth().
void GoAutoBook::Save | ( | const std::string & | filename | ) | const |
Writes book to disk.
Definition at line 136 of file GoAutoBook.cpp.
References m_data.
Referenced by Flush().
void GoAutoBook::TruncateByDepth | ( | int | depth, | |
GoAutoBookState & | state, | |||
GoAutoBook & | other | |||
) | const |
Copies a truncated version of the book into other.
Definition at line 206 of file GoAutoBook.cpp.
Referenced by TruncateByDepth().
void GoAutoBook::TruncateByDepth | ( | int | depth, | |
GoAutoBookState & | state, | |||
GoAutoBook & | other, | |||
std::set< SgHashCode > & | seen | |||
) | const [private] |
Definition at line 213 of file GoAutoBook.cpp.
References GoAutoBookState::Board(), Get(), GoAutoBookState::GetHashCode(), SgBookNode::IsLeaf(), GoBoard::IsLegal(), SgBookNode::IsTerminal(), SgBookNode::LEAF_PRIORITY, SgBookNode::m_count, SgBookNode::m_heurValue, SgBookNode::m_priority, SgBookNode::m_value, GoAutoBookState::Play(), Put(), TruncateByDepth(), and GoAutoBookState::Undo().
Map GoAutoBook::m_data [private] |
Definition at line 154 of file GoAutoBook.h.
Referenced by Get(), GoAutoBook(), ImportHashValuePairs(), Merge(), Put(), and Save().
std::set<SgHashCode> GoAutoBook::m_disabled [private] |
Definition at line 158 of file GoAutoBook.h.
Referenced by AddDisabledLines(), and FindBestChild().
std::string GoAutoBook::m_filename [private] |
Definition at line 160 of file GoAutoBook.h.
Referenced by Flush().
const GoAutoBookParam& GoAutoBook::m_param [private] |
Definition at line 156 of file GoAutoBook.h.
Referenced by FindBestChild().