Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

ZobristHash Class Reference

Zobrist Hashing. More...

#include <ZobristHash.hpp>

List of all members.

Classes

struct  GlobalData
 Data shared amoungst all instances of ZobristHash. More...

Public Member Functions

 ZobristHash (int width, int height)
 Constructs a ZobristHash object for the given boardsize.
hash_t Hash (HexColor toPlay) const
 Returns the current hash value for the color to play.
hash_t Hash () const
 Helper function: same as Hash(EMPTY).
void Reset ()
 Reset hash to the base hash value.
void Compute (const bitset_t &black, const bitset_t &white)
 Sets the hash to base hash value updated with the played stones in black and white.
void Update (HexColor color, HexPoint cell)
 Incrementally updates the hash value with the given move.

Static Private Member Functions

static GlobalDataGetGlobalData ()
 Returns a reference to a static local variable so that it is initialized on first use if some global variable is initialized.

Private Attributes

hash_t m_hash
 Hash for the current state.
hash_t m_base
 Base hash.

Detailed Description

Zobrist Hashing.

Hash values are shared amoung all instances of ZobristHash.

Each unique boardsize has its own base hash, so hashes of positions on different boardsizes should never collide.

Definition at line 22 of file ZobristHash.hpp.


Constructor & Destructor Documentation

ZobristHash::ZobristHash ( int  width,
int  height 
)

Constructs a ZobristHash object for the given boardsize.

Definition at line 67 of file ZobristHash.cpp.

References HexAssert, and Reset().


Member Function Documentation

void ZobristHash::Compute ( const bitset_t black,
const bitset_t white 
)

Sets the hash to base hash value updated with the played stones in black and white.

Definition at line 80 of file ZobristHash.cpp.

References BITSETSIZE, GetGlobalData(), ZobristHash::GlobalData::m_black_hashes, m_hash, ZobristHash::GlobalData::m_white_hashes, Reset(), and benzene_bitset< _Nb >::test().

Referenced by StoneBoard::ComputeHash().

ZobristHash::GlobalData & ZobristHash::GetGlobalData (  )  [static, private]

Returns a reference to a static local variable so that it is initialized on first use if some global variable is initialized.

Definition at line 74 of file ZobristHash.cpp.

Referenced by Compute(), Hash(), and Update().

hash_t ZobristHash::Hash (  )  const [inline]

Helper function: same as Hash(EMPTY).

Definition at line 87 of file ZobristHash.hpp.

References EMPTY.

hash_t ZobristHash::Hash ( HexColor  toPlay  )  const [inline]

Returns the current hash value for the color to play.

Definition at line 82 of file ZobristHash.hpp.

References GetGlobalData(), m_hash, and ZobristHash::GlobalData::m_toPlay_hashes.

Referenced by StoneBoard::Hash().

void ZobristHash::Reset (  )  [inline]

Reset hash to the base hash value.

Definition at line 92 of file ZobristHash.hpp.

References m_base, and m_hash.

Referenced by Compute(), and ZobristHash().

void ZobristHash::Update ( HexColor  color,
HexPoint  cell 
) [inline]

Incrementally updates the hash value with the given move.

Definition at line 97 of file ZobristHash.hpp.

References BITSETSIZE, GetGlobalData(), HexAssert, HexColorUtil::isBlackWhite(), ZobristHash::GlobalData::m_color_hashes, and m_hash.

Referenced by StoneBoard::PlayMove(), and StoneBoard::UndoMove().


Member Data Documentation

Base hash.

Definition at line 50 of file ZobristHash.hpp.

Referenced by Reset().

Hash for the current state.

Definition at line 47 of file ZobristHash.hpp.

Referenced by Compute(), Hash(), Reset(), and Update().


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


6 Jan 2011 Doxygen 1.6.3