#include <GoBook.h>
Classes | |
class | Entry |
class | MapEntry |
Public Member Functions | |
void | Add (const GoBoard &bd, SgPoint move) |
Add a book move to the current position. | |
void | Clear () |
void | Delete (const GoBoard &bd, SgPoint move) |
Deletes a book move in the current position. | |
const Entry & | GetEntry (std::size_t index) const |
Get an entry. | |
int | Line (const GoBoard &bd) const |
Return line number of current position in file the book was loaded from. | |
SgPoint | LookupMove (const GoBoard &bd) const |
Randomly select a move for the current position. | |
std::vector< SgPoint > | LookupAllMoves (const GoBoard &bd) const |
std::size_t | NuEntries () const |
void | Read (std::istream &in, const std::string &streamName="") |
Read book from stream. | |
void | Read (const std::string &filename) |
Read book from file. | |
void | Write (std::ostream &out) const |
void | WriteInfo (std::ostream &out) const |
Private Types | |
typedef std::multimap < SgHashCode, MapEntry > | Map |
Private Member Functions | |
void | InsertEntry (const std::vector< SgPoint > &sequence, const std::vector< SgPoint > &moves, int size, GoBoard &tempBoard, int line) |
Insert a new position entry and all its transformations. | |
const GoBook::MapEntry * | LookupEntry (const GoBoard &bd) const |
void | ParseLine (const std::string &line, GoBoard &tempBoard) |
std::vector< SgPoint > | ReadPoints (std::istream &in) const |
void | ThrowError (const std::string &message) const |
Private Attributes | |
bool | m_warningMaxSizeShown |
int | m_lineCount |
std::string | m_streamName |
std::vector< Entry > | m_entries |
Map | m_map |
Mapping hash key to entries. |
Definition at line 39 of file GoBook.h.
typedef std::multimap<SgHashCode,MapEntry> GoBook::Map [private] |
Add a book move to the current position.
SgException | if move cannot be added (illegal or move sequence to current position cannot be determined) |
Definition at line 81 of file GoBook.cpp.
References InsertEntry(), SgPointUtil::InvRotation(), GoBoard::IsLegal(), LookupEntry(), m_entries, GoBook::MapEntry::m_id, GoBook::MapEntry::m_rotation, GoBoard::Occupied(), SgPointUtil::Rotate(), SG_ASSERT, SG_PASS, and GoBoard::Size().
Referenced by GoBookCommands::CmdAdd().
void GoBook::Clear | ( | ) |
Definition at line 107 of file GoBook.cpp.
References m_entries, and m_map.
Referenced by GoBookCommands::CmdClear(), and Read().
Deletes a book move in the current position.
SgException | if the move is not a book move. |
Definition at line 113 of file GoBook.cpp.
References SgPointUtil::InvRotation(), LookupEntry(), m_entries, GoBook::MapEntry::m_id, GoBook::MapEntry::m_rotation, SgPointUtil::Rotate(), SG_ASSERT, and GoBoard::Size().
Referenced by GoBookCommands::CmdDelete().
const GoBook::Entry & GoBook::GetEntry | ( | std::size_t | index | ) | const |
Get an entry.
index | The index of the entry |
void GoBook::InsertEntry | ( | const std::vector< SgPoint > & | sequence, | |
const std::vector< SgPoint > & | moves, | |||
int | size, | |||
GoBoard & | tempBoard, | |||
int | line | |||
) | [private] |
Insert a new position entry and all its transformations.
sequence | A move sequence that leads to the position | |
moves | The moves to play in this position | |
size | ||
tempBoard | A local temporary work board, reused for efficiency (does not have to be initialized) | |
line | Line number of entry from the file (0 if unknown or entry is not from a file) |
Definition at line 135 of file GoBook.cpp.
References GoBoard::GetHashCodeInclToPlay(), GoBoard::Init(), GoBoard::IsLegal(), m_entries, GoBook::MapEntry::m_id, GoBook::Entry::m_line, m_map, GoBook::Entry::m_moves, GoBook::MapEntry::m_rotation, GoBook::Entry::m_sequence, GoBook::MapEntry::m_size, GoBook::Entry::m_size, GoBoard::Play(), SgPointUtil::Rotate(), GoBoard::Size(), ThrowError(), and GoBoardUtil::UndoAll().
Referenced by Add(), and ParseLine().
int GoBook::Line | ( | const GoBoard & | bd | ) | const |
Return line number of current position in file the book was loaded from.
Definition at line 197 of file GoBook.cpp.
References LookupEntry(), m_entries, GoBook::MapEntry::m_id, and SG_ASSERT.
Referenced by GoBookCommands::PositionInfo().
Definition at line 229 of file GoBook.cpp.
References GoBoard::IsLegal(), LookupEntry(), m_entries, GoBook::MapEntry::m_id, GoBook::MapEntry::m_rotation, GoBook::MapEntry::m_size, SgPointUtil::Rotate(), SG_ASSERT, and SgWarning().
Referenced by GoBookCommands::CmdDelete(), GoBookCommands::CmdMoves(), LookupMove(), and GoBookCommands::PositionInfo().
const GoBook::MapEntry * GoBook::LookupEntry | ( | const GoBoard & | bd | ) | const [private] |
Definition at line 207 of file GoBook.cpp.
References GoBoard::GetHashCodeInclToPlay(), m_map, and GoBoard::Size().
Referenced by Add(), Delete(), Line(), and LookupAllMoves().
Randomly select a move for the current position.
Returns SG_NULLMOVE if position is not in opening book.
Definition at line 219 of file GoBook.cpp.
References LookupAllMoves(), and SG_NULLMOVE.
Referenced by GoGtpEngine::GenBookMove().
std::size_t GoBook::NuEntries | ( | ) | const |
void GoBook::ParseLine | ( | const std::string & | line, | |
GoBoard & | tempBoard | |||
) | [private] |
Definition at line 256 of file GoBook.cpp.
References InsertEntry(), m_lineCount, m_warningMaxSizeShown, ReadPoints(), SG_MAX_SIZE, SgDebug(), and ThrowError().
Referenced by Read().
void GoBook::Read | ( | std::istream & | in, | |
const std::string & | streamName = "" | |||
) |
Read book from stream.
in | ||
streamName | Name used for error messages (e.g. file name) |
Definition at line 277 of file GoBook.cpp.
References Clear(), m_lineCount, m_streamName, m_warningMaxSizeShown, and ParseLine().
Referenced by GoBookCommands::CmdLoad(), and Read().
void GoBook::Read | ( | const std::string & | filename | ) |
vector< SgPoint > GoBook::ReadPoints | ( | std::istream & | in | ) | const [private] |
void GoBook::ThrowError | ( | const std::string & | message | ) | const [private] |
Definition at line 322 of file GoBook.cpp.
References m_lineCount, and m_streamName.
Referenced by InsertEntry(), ParseLine(), and ReadPoints().
void GoBook::Write | ( | std::ostream & | out | ) | const |
Definition at line 331 of file GoBook.cpp.
References m_entries, and SgDebug().
Referenced by GoBookCommands::CmdSave(), and GoBookCommands::CmdSaveAs().
void GoBook::WriteInfo | ( | std::ostream & | out | ) | const |
Definition at line 353 of file GoBook.cpp.
References m_entries, and m_map.
Referenced by GoBookCommands::CmdInfo().
std::vector<Entry> GoBook::m_entries [private] |
Definition at line 126 of file GoBook.h.
Referenced by Add(), Clear(), Delete(), GetEntry(), InsertEntry(), Line(), LookupAllMoves(), NuEntries(), Write(), and WriteInfo().
int GoBook::m_lineCount [private] |
Definition at line 122 of file GoBook.h.
Referenced by ParseLine(), Read(), and ThrowError().
Map GoBook::m_map [private] |
Mapping hash key to entries.
Definition at line 129 of file GoBook.h.
Referenced by Clear(), InsertEntry(), LookupEntry(), and WriteInfo().
std::string GoBook::m_streamName [private] |
Definition at line 124 of file GoBook.h.
Referenced by Read(), and ThrowError().
bool GoBook::m_warningMaxSizeShown [private] |
Definition at line 120 of file GoBook.h.
Referenced by ParseLine(), and Read().