Xiangiqgame
AI engine for Xiangqi
Loading...
Searching...
No Matches
zobrist_factories.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
8#include <functional>
11#include <memory>
14#include <random>
15#include <string>
16
17namespace boardstate {
18
19template <typename KeyType, BoardStateCalculatorRegistryConcept G>
21public:
25 std::shared_ptr<ZobristCalculatorType> CreateRegisteredCalculator(
26 std::shared_ptr<G> game_board,
27 uint32_t prng_seed = std::random_device{}()
28 ) {
29 auto new_calculator = ZobristCalculatorType::Create(prng_seed);
30 new_calculator->FullBoardStateCalc(game_board->map());
31 game_board->AttachMoveCallback(std::bind(
33 new_calculator,
34 std::placeholders::_1
35 ));
36
37 return new_calculator;
38 }
39
40 std::shared_ptr<ZobristCalculatorType> CreateUnregistereCalculator(
41 uint32_t prng_seed = std::random_device{}()
42 ) {
43 return ZobristCalculatorType::Create(prng_seed);
44 }
45};
46
47template <typename KeyType, size_t NumConfKeys, BoardStateCalculatorRegistryConcept G>
49public:
54 std::array<std::shared_ptr<ZobristCalculatorType>, NumConfKeys>;
55
56 std::shared_ptr<ZobristComponentType> CreateRegisteredComponent(
57 std::shared_ptr<G> game_board,
58 uint32_t prng_seed = std::random_device{}()
59 ) {
60 std::mt19937 prng{prng_seed};
61
62 auto primary_calculator =
63 zobrist_calculator_factory_.CreateRegisteredCalculator(game_board, prng());
64 std::array<std::shared_ptr<ZobristCalculatorType>, NumConfKeys>
65 confirmation_calculators;
66 for (auto idx = 0; idx < NumConfKeys; ++idx) {
67 confirmation_calculators[idx] =
68 zobrist_calculator_factory_.CreateRegisteredCalculator(game_board, prng());
69 }
71 primary_calculator,
72 confirmation_calculators,
73 prng_seed
74 );
75 }
76
77 std::shared_ptr<ZobristComponentType> CreateUnregisteredComponent(
78 std::shared_ptr<ZobristCalculatorType> primary_calculator,
79 ConfCalculatorsArrayType confirmation_calculators,
80 uint32_t prng_seed = 0
81 ) {
83 primary_calculator,
84 confirmation_calculators,
85 prng_seed
86 );
87 }
88
89 std::shared_ptr<ZobristComponentType> CreateUnregisteredComponent(
90 uint32_t prng_seed = std::random_device{}()
91 ) {
92 std::mt19937 prng{prng_seed};
93
94 auto primary_calculator =
95 zobrist_calculator_factory_.CreateUnregistereCalculator(prng());
96 std::array<std::shared_ptr<ZobristCalculatorType>, NumConfKeys>
97 confirmation_calculators;
98 for (auto idx = 0; idx < NumConfKeys; ++idx) {
99 confirmation_calculators[idx] =
100 zobrist_calculator_factory_.CreateUnregistereCalculator(prng());
101 }
103 primary_calculator,
104 confirmation_calculators,
105 prng_seed
106 );
107 }
108
109private:
111};
112
113template <typename KeyType, size_t NumConfKeys, BoardStateCalculatorRegistryConcept G>
115public:
121
122 std::shared_ptr<ZobristCoordinatorType> CreateRegisteredCoordinator(
123 std::shared_ptr<G> game_board,
124 uint32_t zobrist_component_seed = std::random_device{}()
125 ) {
126
127 auto zobrist_component = zobrist_component_factory_.CreateRegisteredComponent(
128 game_board,
129 zobrist_component_seed
130 );
131
132 return ZobristCoordinatorType::Create(zobrist_component);
133 }
134
135private:
137};
138} // namespace boardstate
std::shared_ptr< ZobristCalculatorType > CreateUnregistereCalculator(uint32_t prng_seed=std::random_device{}())
std::shared_ptr< ZobristCalculatorType > CreateRegisteredCalculator(std::shared_ptr< G > game_board, uint32_t prng_seed=std::random_device{}())
Creates a new ZobristCalculator, initializes its state using pre-existing GameBoard,...
Uses Zobrist hashing to calculate a "reasonably unique" integer value for each board configuration en...
static std::shared_ptr< ZobristCalculatorForConcepts< K > > Create(uint32_t seed=std::random_device{}())
void UpdateBoardState(const gameboard::ExecutedMove &executed_move)
std::shared_ptr< ZobristComponentType > CreateUnregisteredComponent(std::shared_ptr< ZobristCalculatorType > primary_calculator, ConfCalculatorsArrayType confirmation_calculators, uint32_t prng_seed=0)
std::array< std::shared_ptr< ZobristCalculatorType >, NumConfKeys > ConfCalculatorsArrayType
ZobristCalculatorFactory< KeyType, G > zobrist_calculator_factory_
std::shared_ptr< ZobristComponentType > CreateRegisteredComponent(std::shared_ptr< G > game_board, uint32_t prng_seed=std::random_device{}())
std::shared_ptr< ZobristComponentType > CreateUnregisteredComponent(uint32_t prng_seed=std::random_device{}())
Container for one or more boardstate::ZobristCalculatorForConcepts objects.
static std::shared_ptr< ZobristComponentForConcepts< C, N > > Create(uint32_t prng_seed=std::random_device{}())
std::shared_ptr< ZobristCoordinatorType > CreateRegisteredCoordinator(std::shared_ptr< G > game_board, uint32_t zobrist_component_seed=std::random_device{}())
ZobristComponentFactoryType zobrist_component_factory_
ZobristComponentFactory< KeyType, NumConfKeys, G > ZobristComponentFactoryType
static std::shared_ptr< ZobristCoordinatorForConcepts< M > > Create(std::shared_ptr< M > zobrist_component)
Calculate / manage board state and associate Minimax results.