Zobrist Hashing. More...
#include <ZobristHash.hpp>
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 GlobalData & | GetGlobalData () |
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. |
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.
ZobristHash::ZobristHash | ( | int | width, | |
int | height | |||
) |
Constructs a ZobristHash object for the given boardsize.
Definition at line 67 of file ZobristHash.cpp.
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.
hash_t ZobristHash::Hash | ( | ) | const [inline] |
Helper function: same as Hash(EMPTY).
Definition at line 87 of file ZobristHash.hpp.
References EMPTY.
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().
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().
hash_t ZobristHash::m_base [private] |
hash_t ZobristHash::m_hash [private] |