Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

BookBuilder< PLAYER > Class Template Reference

Expands a Book using the given player to evaluate game positions. More...

#include <BookBuilder.hpp>

Inheritance diagram for BookBuilder< PLAYER >:
SgBookBuilder

List of all members.

Classes

class  Worker
 Copyable worker. More...

Public Member Functions

 BookBuilder (PLAYER &player)
 Constructor.
 ~BookBuilder ()
 Destructor.
void SetState (Book &book, const HexState &state)
 Sets the state to start work from.
void SetWorkBoard (HexBoard &brd)
 Sets the board the book builder can use to perform work.
bool UseICE () const
 Whether to prune out inferior cells from the book or not.
void SetUseICE (bool flag)
 See UseICE().
std::size_t NumThreads () const
 Number of players to use during leaf expansion.
void SetNumThreads (std::size_t num)
 See NumThreads().

Protected Member Functions

std::string MoveString (SgMove move) const
void PrintMessage (std::string msg)
float InverseEval (float eval) const
bool IsLoss (float eval) const
void PlayMove (SgMove move)
void UndoMove (SgMove move)
bool GetNode (SgBookNode &node) const
float Value (const SgBookNode &node) const
void WriteNode (const SgBookNode &node)
void FlushBook ()
void EnsureRootExists ()
 Creates root node if necessary.
bool GenerateMoves (std::vector< SgMove > &moves, float &value)
 Computes an ordered set of moves to consider.
void GetAllLegalMoves (std::vector< SgMove > &moves)
void EvaluateChildren (const std::vector< SgMove > &childrenToDo, std::vector< std::pair< SgMove, float > > &scores)
void Init ()
void StartIteration (int iteration)
void EndIteration ()
void BeforeEvaluateChildren ()
void AfterEvaluateChildren ()
void Fini ()
void ClearAllVisited ()
void MarkAsVisited ()
bool HasBeenVisited ()

Private Member Functions

void CreateWorkers ()
 Copies the player and board and creates the threads.
void DestroyWorkers ()
 Destroys copied players, boards, and threads.

Private Attributes

Bookm_book
 Book this builder is expanding.
PLAYER & m_orig_player
 Player passed to constructor.
HexBoardm_brd
HexState m_state
std::set< hash_tm_visited
bool m_use_ice
 See UseICE().
std::size_t m_num_threads
 See NumberThreads().
std::size_t m_num_evals
std::size_t m_num_widenings
std::size_t m_value_updates
std::size_t m_priority_updates
std::size_t m_internal_nodes
std::size_t m_leaf_nodes
std::size_t m_terminal_nodes
std::vector< HexBoard * > m_boards
 Boards for each thread.
std::vector< BenzenePlayer * > m_players
 Players for each thread.
std::vector< Workerm_workers
SgThreadedWorker< SgMove,
float, Worker > * 
m_threadedWorker

Detailed Description

template<class PLAYER>
class BookBuilder< PLAYER >

Expands a Book using the given player to evaluate game positions.

Supports multithreaded evaluation of states.

We do not include the swap rule as a move, since this would lead to redundant evaluation computations (such as a2-f6 and a2-swap-f6). We do handle swap implicitly, however. States in which swap is a valid move are scored taking it into account.

Definition at line 38 of file BookBuilder.hpp.


Constructor & Destructor Documentation

template<class PLAYER>
BookBuilder< PLAYER >::BookBuilder ( PLAYER &  player  )  [inline]

Constructor.

Takes a reference to the player that will evaluate states, which must be a reference to a BenzenePlayer.

Definition at line 194 of file BookBuilder.hpp.

template<class PLAYER >
BookBuilder< PLAYER >::~BookBuilder (  )  [inline]

Destructor.

Definition at line 205 of file BookBuilder.hpp.


Member Function Documentation

template<class PLAYER >
void BookBuilder< PLAYER >::AfterEvaluateChildren (  )  [inline, protected]

Definition at line 493 of file BookBuilder.hpp.

template<class PLAYER >
void BookBuilder< PLAYER >::BeforeEvaluateChildren (  )  [inline, protected]
template<class PLAYER >
void BookBuilder< PLAYER >::ClearAllVisited (  )  [inline, protected]

Definition at line 510 of file BookBuilder.hpp.

References BookBuilder< PLAYER >::m_visited.

template<class PLAYER >
void BookBuilder< PLAYER >::CreateWorkers (  )  [inline, private]
template<class PLAYER >
void BookBuilder< PLAYER >::DestroyWorkers (  )  [inline, private]
template<class PLAYER >
void BookBuilder< PLAYER >::EndIteration (  )  [inline, protected]

Definition at line 504 of file BookBuilder.hpp.

template<class PLAYER >
void BookBuilder< PLAYER >::EnsureRootExists (  )  [inline, protected]
template<class PLAYER >
void BookBuilder< PLAYER >::EvaluateChildren ( const std::vector< SgMove > &  childrenToDo,
std::vector< std::pair< SgMove, float > > &  scores 
) [inline, protected]

Definition at line 486 of file BookBuilder.hpp.

template<class PLAYER >
void BookBuilder< PLAYER >::Fini (  )  [inline, protected]

Definition at line 283 of file BookBuilder.hpp.

References BookBuilder< PLAYER >::DestroyWorkers().

template<class PLAYER >
void BookBuilder< PLAYER >::FlushBook (  )  [inline, protected]

Definition at line 396 of file BookBuilder.hpp.

References StateDB< T >::Flush(), LogInfo(), and BookBuilder< PLAYER >::m_book.

template<class PLAYER >
bool BookBuilder< PLAYER >::GenerateMoves ( std::vector< SgMove > &  moves,
float &  value 
) [inline, protected]

Computes an ordered set of moves to consider.

Returns true if state is determined, with the value set in value and moves untouched. Returns false otherwise, in which case moves will contain the sorted moves and value will be untouched.

Definition at line 433 of file BookBuilder.hpp.

References benzene_bitset< _Nb >::any(), HexBoard::ComputeAll(), HexBoard::GetPosition(), HexAssert, HexEval, EndgameUtils::IsDeterminedState(), BookBuilder< PLAYER >::m_brd, BookBuilder< PLAYER >::m_state, BookBuilder< PLAYER >::m_use_ice, EndgameUtils::MovesToConsider(), HexState::Position(), StoneBoard::SetPosition(), HexBoard::SetUseICE(), HexState::ToPlay(), and HexBoard::UseICE().

template<class PLAYER >
void BookBuilder< PLAYER >::GetAllLegalMoves ( std::vector< SgMove > &  moves  )  [inline, protected]
template<class PLAYER >
bool BookBuilder< PLAYER >::GetNode ( SgBookNode &  node  )  const [inline, protected]
template<class PLAYER >
bool BookBuilder< PLAYER >::HasBeenVisited (  )  [inline, protected]
template<class PLAYER >
void BookBuilder< PLAYER >::Init (  )  [inline, protected]

Definition at line 277 of file BookBuilder.hpp.

References BookBuilder< PLAYER >::CreateWorkers().

template<class PLAYER >
float BookBuilder< PLAYER >::InverseEval ( float  eval  )  const [inline, protected]

Definition at line 353 of file BookBuilder.hpp.

template<class PLAYER >
bool BookBuilder< PLAYER >::IsLoss ( float  eval  )  const [inline, protected]

Definition at line 359 of file BookBuilder.hpp.

template<class PLAYER >
void BookBuilder< PLAYER >::MarkAsVisited (  )  [inline, protected]
template<class PLAYER >
std::string BookBuilder< PLAYER >::MoveString ( SgMove  move  )  const [inline, protected]

Definition at line 341 of file BookBuilder.hpp.

References HexPointUtil::ToString().

template<class PLAYER >
std::size_t BookBuilder< PLAYER >::NumThreads (  )  const [inline]

Number of players to use during leaf expansion.

Each player may use a multi-threaded search. Should speed up the expansion of leaf states by a factor of (very close to) NumThreads().

Definition at line 224 of file BookBuilder.hpp.

References BookBuilder< PLAYER >::m_num_threads.

template<class PLAYER >
void BookBuilder< PLAYER >::PlayMove ( SgMove  move  )  [inline, protected]

Definition at line 365 of file BookBuilder.hpp.

References BookBuilder< PLAYER >::m_state, and HexState::PlayMove().

template<class PLAYER >
void BookBuilder< PLAYER >::PrintMessage ( std::string  msg  )  [inline, protected]

Definition at line 347 of file BookBuilder.hpp.

References LogInfo().

template<class PLAYER >
void BookBuilder< PLAYER >::SetNumThreads ( std::size_t  num  )  [inline]

See NumThreads().

Definition at line 230 of file BookBuilder.hpp.

References BookBuilder< PLAYER >::m_num_threads.

template<class PLAYER >
void BookBuilder< PLAYER >::SetState ( Book book,
const HexState state 
) [inline]

Sets the state to start work from.

Definition at line 328 of file BookBuilder.hpp.

References BookBuilder< PLAYER >::m_book, and BookBuilder< PLAYER >::m_state.

Referenced by BookBuilder< PLAYER >::BeforeEvaluateChildren().

template<class PLAYER >
void BookBuilder< PLAYER >::SetUseICE ( bool  flag  )  [inline]

See UseICE().

Definition at line 218 of file BookBuilder.hpp.

References BookBuilder< PLAYER >::m_use_ice.

template<class PLAYER >
void BookBuilder< PLAYER >::SetWorkBoard ( HexBoard brd  )  [inline]

Sets the board the book builder can use to perform work.

Definition at line 335 of file BookBuilder.hpp.

References BookBuilder< PLAYER >::m_brd.

template<class PLAYER >
void BookBuilder< PLAYER >::StartIteration ( int  iteration  )  [inline, protected]

Definition at line 498 of file BookBuilder.hpp.

References LogInfo().

template<class PLAYER >
void BookBuilder< PLAYER >::UndoMove ( SgMove  move  )  [inline, protected]

Definition at line 371 of file BookBuilder.hpp.

References BookBuilder< PLAYER >::m_state, and HexState::UndoMove().

template<class PLAYER >
bool BookBuilder< PLAYER >::UseICE (  )  const [inline]

Whether to prune out inferior cells from the book or not.

Definition at line 212 of file BookBuilder.hpp.

References BookBuilder< PLAYER >::m_use_ice.

template<class PLAYER >
float BookBuilder< PLAYER >::Value ( const SgBookNode &  node  )  const [inline, protected]

Definition at line 403 of file BookBuilder.hpp.

References BookBuilder< PLAYER >::m_state.

template<class PLAYER >
void BookBuilder< PLAYER >::WriteNode ( const SgBookNode &  node  )  [inline, protected]

Member Data Documentation

template<class PLAYER>
std::vector<HexBoard*> BookBuilder< PLAYER >::m_boards [private]

Boards for each thread.

Definition at line 177 of file BookBuilder.hpp.

Referenced by BookBuilder< PLAYER >::CreateWorkers(), and BookBuilder< PLAYER >::DestroyWorkers().

template<class PLAYER>
Book* BookBuilder< PLAYER >::m_book [private]
template<class PLAYER>
HexBoard* BookBuilder< PLAYER >::m_brd [private]
template<class PLAYER>
std::size_t BookBuilder< PLAYER >::m_internal_nodes [private]

Definition at line 170 of file BookBuilder.hpp.

template<class PLAYER>
std::size_t BookBuilder< PLAYER >::m_leaf_nodes [private]

Definition at line 172 of file BookBuilder.hpp.

template<class PLAYER>
std::size_t BookBuilder< PLAYER >::m_num_evals [private]

Definition at line 162 of file BookBuilder.hpp.

template<class PLAYER>
std::size_t BookBuilder< PLAYER >::m_num_threads [private]
template<class PLAYER>
std::size_t BookBuilder< PLAYER >::m_num_widenings [private]

Definition at line 164 of file BookBuilder.hpp.

template<class PLAYER>
PLAYER& BookBuilder< PLAYER >::m_orig_player [private]

Player passed to constructor.

Definition at line 148 of file BookBuilder.hpp.

Referenced by BookBuilder< PLAYER >::CreateWorkers().

template<class PLAYER>
std::vector<BenzenePlayer*> BookBuilder< PLAYER >::m_players [private]

Players for each thread.

Definition at line 180 of file BookBuilder.hpp.

Referenced by BookBuilder< PLAYER >::CreateWorkers(), and BookBuilder< PLAYER >::DestroyWorkers().

template<class PLAYER>
std::size_t BookBuilder< PLAYER >::m_priority_updates [private]

Definition at line 168 of file BookBuilder.hpp.

template<class PLAYER>
HexState BookBuilder< PLAYER >::m_state [private]
template<class PLAYER>
std::size_t BookBuilder< PLAYER >::m_terminal_nodes [private]

Definition at line 174 of file BookBuilder.hpp.

template<class PLAYER>
SgThreadedWorker<SgMove,float,Worker>* BookBuilder< PLAYER >::m_threadedWorker [private]
template<class PLAYER>
bool BookBuilder< PLAYER >::m_use_ice [private]
template<class PLAYER>
std::size_t BookBuilder< PLAYER >::m_value_updates [private]

Definition at line 166 of file BookBuilder.hpp.

template<class PLAYER>
std::set<hash_t> BookBuilder< PLAYER >::m_visited [private]
template<class PLAYER>
std::vector<Worker> BookBuilder< PLAYER >::m_workers [private]

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


6 Jan 2011 Doxygen 1.6.3