#include <GoBook.h>
Definition at line 41 of file GoBook.h.
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. | |
Classes | |
| class | Entry |
| class | MapEntry |
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 82 of file GoBook.cpp.
References Contains(), GetSequence(), 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 108 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 114 of file GoBook.cpp.
References Erase(), 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 137 of file GoBook.cpp.
References Contains(), GoBoard::Init(), 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, 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 199 of file GoBook.cpp.
References LookupEntry(), m_entries, GoBook::MapEntry::m_id, and SG_ASSERT.
Referenced by GoBookCommands::PositionInfo().
Definition at line 231 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 209 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 221 of file GoBook.cpp.
References LookupAllMoves(), and SG_NULLMOVE.
Referenced by GoGtpEngine::GenMove().
| std::size_t GoBook::NuEntries | ( | ) | const |
| void GoBook::ParseLine | ( | const std::string & | line, | |
| GoBoard & | tempBoard | |||
| ) | [private] |
Definition at line 258 of file GoBook.cpp.
References InsertEntry(), m_lineCount, m_warningMaxSizeShown, ReadPoints(), SG_MAX_SIZE, SgDebug(), and ThrowError().
Referenced by Read().
| void GoBook::Read | ( | const std::string & | filename | ) |
| 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 276 of file GoBook.cpp.
References Clear(), m_lineCount, m_streamName, m_warningMaxSizeShown, and ParseLine().
Referenced by GoBookCommands::CmdLoad(), and Read().
| vector< SgPoint > GoBook::ReadPoints | ( | std::istream & | in | ) | const [private] |
| void GoBook::ThrowError | ( | const std::string & | message | ) | const [private] |
Definition at line 321 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 330 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 352 of file GoBook.cpp.
References m_entries, and m_map.
Referenced by GoBookCommands::CmdInfo().
std::vector<Entry> GoBook::m_entries [private] |
Definition at line 135 of file GoBook.h.
Referenced by Add(), Clear(), Delete(), GetEntry(), InsertEntry(), Line(), LookupAllMoves(), NuEntries(), Write(), and WriteInfo().
int GoBook::m_lineCount [private] |
Map GoBook::m_map [private] |
Mapping hash key to entries.
Definition at line 138 of file GoBook.h.
Referenced by Clear(), InsertEntry(), LookupEntry(), and WriteInfo().
std::string GoBook::m_streamName [private] |
bool GoBook::m_warningMaxSizeShown [private] |