Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes

GoBook Class Reference

#include <GoBook.h>

List of all members.

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

Detailed Description

Definition at line 39 of file GoBook.h.


Member Typedef Documentation

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

Definition at line 118 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 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().

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

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

Definition at line 144 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 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.

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

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 219 of file GoBook.cpp.

References LookupAllMoves(), and SG_NULLMOVE.

Referenced by GoGtpEngine::GenBookMove().

std::size_t GoBook::NuEntries (  )  const

Definition at line 150 of file GoBook.h.

References m_entries.

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.

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

Read book from file.

Definition at line 295 of file GoBook.cpp.

References Read().

vector< SgPoint > GoBook::ReadPoints ( std::istream &  in  )  const [private]

Definition at line 303 of file GoBook.cpp.

References ThrowError().

Referenced by ParseLine().

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


Member Data Documentation

std::vector<Entry> GoBook::m_entries [private]
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().

Definition at line 120 of file GoBook.h.

Referenced by ParseLine(), and Read().


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


Sun Mar 13 2011 Doxygen 1.7.1