Xiangiqgame
AI engine for Xiangqi
Loading...
Searching...
No Matches
boardstate::ZobristCalculator< KeyType > Class Template Reference

Uses Zobrist hashing to calculate a "reasonably unique" integer value for each board configuration encountered during a game. More...

#include <zobrist.hpp>

Collaboration diagram for boardstate::ZobristCalculator< KeyType >:
Collaboration graph

Public Member Functions

 ZobristCalculator (uint32_t seed=std::random_device{}())
 Constructs a ZobristCalculator.
 
KeyType board_state () const
 
GameZarray_t zarray () const
 
KeyType turn_key () const
 
uint32_t seed () const
 
void FullBoardStateCalc (const gameboard::BoardMap_t &board_map)
 
void UpdateBoardState (const gameboard::ExecutedMove &executed_move)
 
KeyType GetHashValueAt (PieceColor color, PieceType piece_type, BoardSpace space)
 

Private Types

using PieceZarray_t = array< array< KeyType, gameboard::kNumFiles >, gameboard::kNumRanks >
 
using TeamZarray_t = array< PieceZarray_t, gameboard::kNumPieceTypeVals >
 
using GameZarray_t = array< TeamZarray_t, 2 >
 

Private Member Functions

void FullBoardStateCalInternal (const gameboard::BoardMap_t &board_map)
 
void UpdateBoardStateInternal (const gameboard::ExecutedMove &executed_move)
 

Static Private Member Functions

static const GameZarray_t CreateGameZarray (PseudoRandomKeyGenerator< KeyType > &key_generator)
 Static helper method for building 4-D array of Zobrist keys in constuctor.
 

Private Attributes

GameZarray_t zarray_
 
KeyType turn_key_
 
uint32_t seed_
 
KeyType board_state_
 

Detailed Description

template<typename KeyType>
class boardstate::ZobristCalculator< KeyType >

Uses Zobrist hashing to calculate a "reasonably unique" integer value for each board configuration encountered during a game.

KeyType can be any unsigned integer type with a size = (n * 32 bits) where n is an integer >= 1.

Definition at line 30 of file zobrist.hpp.

Member Typedef Documentation

◆ GameZarray_t

template<typename KeyType >
using boardstate::ZobristCalculator< KeyType >::GameZarray_t = array<TeamZarray_t, 2>
private

Definition at line 35 of file zobrist.hpp.

◆ PieceZarray_t

template<typename KeyType >
using boardstate::ZobristCalculator< KeyType >::PieceZarray_t = array<array<KeyType, gameboard::kNumFiles>, gameboard::kNumRanks>
private

Definition at line 32 of file zobrist.hpp.

◆ TeamZarray_t

template<typename KeyType >
using boardstate::ZobristCalculator< KeyType >::TeamZarray_t = array<PieceZarray_t, gameboard::kNumPieceTypeVals>
private

Definition at line 34 of file zobrist.hpp.

Constructor & Destructor Documentation

◆ ZobristCalculator()

template<typename KeyType >
boardstate::ZobristCalculator< KeyType >::ZobristCalculator ( uint32_t  seed = std::random_device{}())
inline

Constructs a ZobristCalculator.

Parameters
seedInteger used as a seed for a PRNG that generates Zobrist key values.

Definition at line 45 of file zobrist.hpp.

Member Function Documentation

◆ board_state()

template<typename KeyType >
KeyType boardstate::ZobristCalculator< KeyType >::board_state ( ) const
inline

Definition at line 56 of file zobrist.hpp.

◆ CreateGameZarray()

template<typename KeyType >
static const GameZarray_t boardstate::ZobristCalculator< KeyType >::CreateGameZarray ( PseudoRandomKeyGenerator< KeyType > &  key_generator)
inlinestaticprivate

Static helper method for building 4-D array of Zobrist keys in constuctor.

Definition at line 77 of file zobrist.hpp.

◆ FullBoardStateCalc()

template<typename KeyType >
void boardstate::ZobristCalculator< KeyType >::FullBoardStateCalc ( const gameboard::BoardMap_t board_map)
inline

Definition at line 63 of file zobrist.hpp.

◆ FullBoardStateCalInternal()

template<typename KeyType >
void boardstate::ZobristCalculator< KeyType >::FullBoardStateCalInternal ( const gameboard::BoardMap_t board_map)
inlineprivate

Definition at line 95 of file zobrist.hpp.

◆ GetHashValueAt()

template<typename KeyType >
KeyType boardstate::ZobristCalculator< KeyType >::GetHashValueAt ( PieceColor  color,
PieceType  piece_type,
BoardSpace  space 
)
inline

Definition at line 71 of file zobrist.hpp.

◆ seed()

template<typename KeyType >
uint32_t boardstate::ZobristCalculator< KeyType >::seed ( ) const
inline

Definition at line 59 of file zobrist.hpp.

◆ turn_key()

template<typename KeyType >
KeyType boardstate::ZobristCalculator< KeyType >::turn_key ( ) const
inline

Definition at line 58 of file zobrist.hpp.

◆ UpdateBoardState()

template<typename KeyType >
void boardstate::ZobristCalculator< KeyType >::UpdateBoardState ( const gameboard::ExecutedMove executed_move)
inline

Definition at line 67 of file zobrist.hpp.

◆ UpdateBoardStateInternal()

template<typename KeyType >
void boardstate::ZobristCalculator< KeyType >::UpdateBoardStateInternal ( const gameboard::ExecutedMove executed_move)
inlineprivate

Definition at line 110 of file zobrist.hpp.

◆ zarray()

template<typename KeyType >
GameZarray_t boardstate::ZobristCalculator< KeyType >::zarray ( ) const
inline

Definition at line 57 of file zobrist.hpp.

Member Data Documentation

◆ board_state_

template<typename KeyType >
KeyType boardstate::ZobristCalculator< KeyType >::board_state_
private

Definition at line 40 of file zobrist.hpp.

◆ seed_

template<typename KeyType >
uint32_t boardstate::ZobristCalculator< KeyType >::seed_
private

Definition at line 39 of file zobrist.hpp.

◆ turn_key_

template<typename KeyType >
KeyType boardstate::ZobristCalculator< KeyType >::turn_key_
private

Definition at line 38 of file zobrist.hpp.

◆ zarray_

template<typename KeyType >
GameZarray_t boardstate::ZobristCalculator< KeyType >::zarray_
private

Definition at line 37 of file zobrist.hpp.


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