16#include <shared_mutex>
26template <SingleBoardStateProv
iderConcept C,
size_t N>
38 static std::shared_ptr<ZobristComponentForConcepts<C, N>>
Create(
39 uint32_t
prng_seed = std::random_device{}()
42 auto primary_calculator =
44 std::array<std::shared_ptr<C>, N> confirmation_calculators;
45 for (
auto idx = 0; idx < N; ++idx) {
46 confirmation_calculators[idx] =
50 return std::shared_ptr<ZobristComponentForConcepts<C, N>>(
51 new ZobristComponentForConcepts<C, N>(
53 confirmation_calculators,
59 static std::shared_ptr<ZobristComponentForConcepts<C, N>>
Create(
60 std::shared_ptr<C> primary_calculator,
61 std::array<std::shared_ptr<C>, N> confirmation_calculators,
64 return std::shared_ptr<ZobristComponentForConcepts<C, N>>(
67 confirmation_calculators,
91 std::shared_ptr<C> primary_calculator,
92 std::array<std::shared_ptr<C>, N> confirmation_calculators,
101 std::array<typename C::KeyType, N> confirmation_states;
102 for (
auto i = 0; i < N; ++i) {
105 return confirmation_states;
109 std::array<uint32_t, N> seeds;
110 for (
auto i = 0; i < N; ++i) {
120template <
typename KeyType,
size_t NumConfKeys>
148 for (
auto i = 0; i < NumConfKeys; ++i) {
165template <
typename KeyType,
size_t NumConfKeys>
167 std::unordered_map<KeyType, TranspositionTableEntryForConcepts<KeyType, NumConfKeys>>
175 KeyType primary_board_state,
177 std::array<KeyType, NumConfKeys> expected_keys
180 auto tr_table_entry_it =
data_.find(primary_board_state);
181 if (tr_table_entry_it !=
data_.end()) {
182 auto tr_table_entry = tr_table_entry_it->second;
183 if (tr_table_entry.remaining_search_depth() >= remaining_search_depth) {
185 result.set_found(
true);
186 result.set_minimax_calc_result(tr_table_entry.minimax_calc_result());
188 if (result.found() and
189 !tr_table_entry.ConfirmationKeysMatchExpected(expected_keys)) {
190 result.set_known_collision(
true);
197 KeyType primary_board_state,
201 const std::array<KeyType, NumConfKeys> &confirmation_keys
203 data_.insert_or_assign(
218 auto tr_table_entry_it =
data_.at(board_state);
249template <
typename KeyType,
size_t NumConfKeys>
289 std::cout <<
"Pruning!" << std::endl;
293 std::this_thread::sleep_for(std::chrono::microseconds(200));
305template <MultiBoardStateProv
iderConcept M>
319 static std::shared_ptr<ZobristCoordinatorForConcepts<M>>
Create(
320 std::shared_ptr<M> zobrist_component
322 return std::shared_ptr<ZobristCoordinatorForConcepts<M>>(
Constants, typedefs, and simple structs used by gameboard::GameBoard.
Data structure to hold calculation results that get entered into a boardstate::TranspositionTableForC...
TranspositionTableEntryForConcepts(moveselection::MinimaxCalcResult minimax_calc_result, std::array< KeyType, NumConfKeys > confirmation_keys, MoveCountType last_access_index)
MoveCountType last_access_index()
DepthType remaining_search_depth()
std::array< KeyType, NumConfKeys > confirmation_keys()
bool ConfirmationKeysMatchExpected(std::array< KeyType, NumConfKeys > expected_keys)
moveselection::MinimaxCalcResult minimax_calc_result_
void set_last_access_index(MoveCountType last_access_index)
std::array< KeyType, NumConfKeys > confirmation_keys_
moveselection::MinimaxCalcResult minimax_calc_result()
MoveCountType last_access_index_
Stores and manages key-value pairs consisting of a board_state (from a boardstate::ZobristComponent) ...
MoveCountType NumIdleMovesAt(KeyType board_state)
void RecordData(KeyType primary_board_state, DepthType search_depth, moveselection::MinimaxResultType result_type, moveselection::EqualScoreMoves &similar_moves, const std::array< KeyType, NumConfKeys > &confirmation_keys)
moveselection::TranspositionTableSearchResult GetDataAt(KeyType primary_board_state, DepthType remaining_search_depth, std::array< KeyType, NumConfKeys > expected_keys)
MoveCountType NumMovesSinceLastUseOf(const TranspositionTableEntryForConcepts< KeyType, NumConfKeys > &tr_table_entry)
std::unordered_map< KeyType, TranspositionTableEntryForConcepts< KeyType, NumConfKeys > > data_
TranspositionTableForConcepts()=default
MoveCountType move_counter_
void IncrementMoveCounter()
Contains std::mutex that other classes lock before accessing TranspositionTableForConcepts.
TranspositionTableGuardForConcepts()=default
TranspositionTableGuardForConcepts(const TranspositionTableGuardForConcepts &)=delete
TranspositionTableGuardForConcepts & operator=(const TranspositionTableGuardForConcepts &)=delete
std::mutex tr_table_mutex_
std::unique_lock< std::mutex > GetExclusiveLock()
Removes old entries from TranspositionTableForConcepts to prevent excessive memory use.
~TranspositionTablePrunerForConcepts()
TranspositionTableGuardForConcepts & tr_table_guard_
TranspositionTablePrunerForConcepts(const TranspositionTablePrunerForConcepts &)=delete
TranspositionTablePrunerForConcepts & operator=(const TranspositionTablePrunerForConcepts &)=delete
void ThreadSafePruneEntry()
TranspositionTablePrunerForConcepts(TranspositionTableForConcepts< KeyType, NumConfKeys > &tr_table, TranspositionTableGuardForConcepts &tr_table_guard)
TranspositionTableForConcepts< KeyType, NumConfKeys > & tr_table_
std::atomic< bool > keep_running_
std::thread pruning_thread_
static std::shared_ptr< ZobristCalculatorForConcepts< K > > Create(uint32_t seed=std::random_device{}())
Container for one or more boardstate::ZobristCalculatorForConcepts objects.
std::array< std::shared_ptr< C >, N > confirmation_calculators_
std::shared_ptr< C > primary_calculator_
std::string primary_board_state_hex_str() const
C::KeyType primary_board_state()
std::array< uint32_t, N > confirmation_calculator_seeds() const
C::KeyType primary_calculator_seed()
typename C::KeyType KeyType
std::array< uint32_t, N > confirmation_calculator_seeds_internal() const
std::array< typename C::KeyType, N > confirmation_board_states()
static size_t constexpr NumConfKeys
static std::shared_ptr< ZobristComponentForConcepts< C, N > > Create(uint32_t prng_seed=std::random_device{}())
std::array< typename C::KeyType, N > confirmation_board_states_internal()
ZobristComponentForConcepts(std::shared_ptr< C > primary_calculator, std::array< std::shared_ptr< C >, N > confirmation_calculators, uint32_t prng_seed=0)
Constructs ZobristComponentForConcepts from existing ZobristCalculatorForConcepts objects.
static std::shared_ptr< ZobristComponentForConcepts< C, N > > Create(std::shared_ptr< C > primary_calculator, std::array< std::shared_ptr< C >, N > confirmation_calculators, std::uint32_t prng_seed=0)
const std::string board_state_hex_str()
static size_t constexpr NumConfKeys
void RecordTrData(DepthType search_depth, moveselection::MinimaxResultType result_type, moveselection::EqualScoreMoves &similar_moves, MoveCountType access_index)
TranspositionTableGuardForConcepts tr_table_guard_
std::shared_ptr< M > zobrist_component_
moveselection::TranspositionTableSearchResult GetTrData(DepthType search_depth, MoveCountType access_index)
typename M::KeyType KeyType
ZobristCoordinatorForConcepts(std::shared_ptr< M > zobrist_component)
static std::shared_ptr< ZobristCoordinatorForConcepts< M > > Create(std::shared_ptr< M > zobrist_component)
TranspositionTablePrunerForConcepts< KeyType, M::NumConfKeys > tr_table_pruner_
TranspositionTableForConcepts< KeyType, M::NumConfKeys > tr_table_
Holds a gameboard::MoveCollection in which all gameboard::Move have the same value (as perceived by a...
Data structure that holds a moveselection::EqualScoreMoves and other search-related info obtained fro...
DepthType remaining_search_depth()
Container for storing a moveselection::MinimaxCalcResult retrieved by a call to boardstate::SingleZob...
Data structs used by moveselection::MinimaxEvaluator.
Declaration of boardstate::KeyGenerator and implementation of its template methods.
Definitions and implementations of gameboard::Move and other move-related structs.
Calculate / manage board state and associate Minimax results.
std::string IntToHexString(IntType num)