Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

GoBook Class Reference

#include <GoBook.h>

List of all members.


Detailed Description

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 EntryGetEntry (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< SgPointLookupAllMoves (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::MapEntryLookupEntry (const GoBoard &bd) const
void ParseLine (const std::string &line, GoBoard &tempBoard)
std::vector< SgPointReadPoints (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< Entrym_entries
Map m_map
 Mapping hash key to entries.

Classes

class  Entry
class  MapEntry


Member Typedef Documentation

typedef std::multimap<SgHashCode,MapEntry> GoBook::Map [private]

Definition at line 127 of file GoBook.h.


Member Function Documentation

void GoBook::Add ( const GoBoard bd,
SgPoint  move 
)

Add a book move to the current position.

Exceptions:
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().

void GoBook::Delete ( const GoBoard bd,
SgPoint  move 
)

Deletes a book move in the current position.

Exceptions:
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.

Parameters:
index The index of the entry
See also:
NuEntries()

Definition at line 153 of file GoBook.h.

References m_entries, and SG_ASSERT.

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.

Parameters:
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.

Returns:
Line number or 0, if current position is not in book or was not in book, when the book was loaded.

Definition at line 199 of file GoBook.cpp.

References LookupEntry(), m_entries, GoBook::MapEntry::m_id, and SG_ASSERT.

Referenced by GoBookCommands::PositionInfo().

vector< SgPoint > GoBook::LookupAllMoves ( const GoBoard bd  )  const

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().

SgPoint GoBook::LookupMove ( const GoBoard bd  )  const

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

Definition at line 159 of file GoBook.h.

References m_entries.

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  ) 

Read book from file.

Definition at line 294 of file GoBook.cpp.

References Read().

void GoBook::Read ( std::istream &  in,
const std::string &  streamName = "" 
)

Read book from stream.

Parameters:
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]

Definition at line 302 of file GoBook.cpp.

References ThrowError().

Referenced by ParseLine().

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().


Member Data Documentation

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]

Definition at line 131 of file GoBook.h.

Referenced by ParseLine(), Read(), and ThrowError().

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]

Definition at line 133 of file GoBook.h.

Referenced by Read(), and ThrowError().

bool GoBook::m_warningMaxSizeShown [private]

Definition at line 129 of file GoBook.h.

Referenced by ParseLine(), and Read().


The documentation for this class was generated from the following files:


17 Jun 2010 Doxygen 1.4.7