Xiangiqgame
AI engine for Xiangqi
Loading...
Searching...
No Matches
evaluator_data_structs.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
7// #include <interfaces/board_state_summarizer_interface.hpp>
8#include <chrono>
10#include <map>
13
14using namespace gameboard;
15using namespace piecepoints;
16
17namespace moveselection {
18
19
23public:
26
28};
29
31struct ScoredMove {
34};
35
36enum MinimaxResultType : uint16_t {
41 kDraw = 6,
48};
49const uint16_t kNumResultTypes{7};
50
54public:
57 , result_type_{}
59
62 , result_type_{type}
63 , equal_score_moves_{std::move(moves)} {}
64
70
71private:
75};
76
80public:
82
83 bool IsConsistentWith(const MoveCollection &allowed_moves) {
84 if (allowed_moves.IsEmpty() and moves().IsEmpty()) {
85 return false;
86 }
87 if (allowed_moves.IsEmpty() and moves().IsEmpty()) {
88 return true;
89 }
90 if (moves().ContainsAnyMoveNotIn(allowed_moves)) {
91 return false;
92 }
93 return true;
94 }
95
96 bool found() { return found_; }
97 void set_found(bool status) { found_ = status; }
98
100 void set_known_collision(bool status) { known_collision_ = status; }
101
104 minimax_calc_result_ = result;
105 }
106
108
110
111private:
113 bool found_;
115};
116
117// struct TranspositionTableSize {
118// uint64_t num_entries;
119// uint64_t num_states;
120// };
121
126typedef std::array<std::vector<int>, MinimaxResultType::kMax + 1>
128
132public:
133 ResultDepthCounts(DepthType max_search_depth) {
134 for (auto &vec : data_) {
135 vec.resize(max_search_depth + 1);
136 }
137 }
138
139 void IncrementDataAt(MinimaxResultType result_type, DepthType search_depth) {
140 data_[result_type][search_depth]++;
141 }
142
144
145private:
147};
148
149// struct CollisionInfo {
150// TranspositionTableSize tr_table_size;
151// std::string board_state;
152// };
153
160public:
162 : num_nodes_{}
163 , result_depth_counts_{ResultDepthCounts(max_search_depth)}
166 , num_collisions_{0}
169
171 MinimaxResultType result_type,
172 DepthType search_depth,
174 ) {
175 result_depth_counts_.IncrementDataAt(result_type, search_depth);
176 num_nodes_++;
178 }
179
181 transposition_table_hits_.IncrementDataAt(result_type, search_depth);
182 }
183
185 TranspositionTableSearchResult &tr_table_search_result,
186 DepthType remaining_search_depth
187 ) {
190 remaining_search_depth,
191 tr_table_search_result.score_and_moves()
192 );
194 tr_table_search_result.result_type(),
195 remaining_search_depth
196 );
197 if (tr_table_search_result.known_collision()) {
199 }
200 }
201
202 size_t num_nodes() { return num_nodes_; }
203 std::chrono::duration<double, std::nano> time() { return time_; }
204
205 void set_time(std::chrono::duration<double, std::nano> search_time) {
206 time_ = search_time;
207 }
211 }
212
218 }
223 }
224 void set_returned_illegal_move(bool status) { returned_illegal_move_ = status; }
226 size_t num_collisions() { return num_collisions_; }
227
228private:
230 std::chrono::duration<double, std::nano> time_;
239};
240
249 std::vector<SearchSummary> first_searches;
250 std::map<MoveCountType, SearchSummary> extra_searches;
251
252 SearchSummary &NewFirstSearch(DepthType search_depth, size_t tr_table_size_initial) {
253 first_searches.emplace_back(SearchSummary(search_depth, tr_table_size_initial));
254 return first_searches.back();
255 }
256
258 DepthType search_depth,
259 MoveCountType search_number,
260 size_t tr_table_size_current
261 ) {
262 auto new_search_entry = extra_searches.emplace(
263 search_number,
264 SearchSummary(search_depth, tr_table_size_current)
265 );
266 return new_search_entry.first->second;
267 }
268};
269
270
271} // namespace moveselection
Definitions of classes used for storing piece points in Base Points Offset form.
Constants, typedefs, and simple structs used by gameboard::GameBoard.
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...
MinimaxCalcResult(DepthType depth, MinimaxResultType type, EqualScoreMoves moves)
Container for storing and updating data in a moveselection::ResultDepthCountsData_t array of vectors.
void IncrementDataAt(MinimaxResultType result_type, DepthType search_depth)
ResultDepthCounts(DepthType max_search_depth)
Stores data collected during a single call to moveselection::MinimaxMoveEvaluator....
void set_time(std::chrono::duration< double, std::nano > search_time)
void RecordNodeInfo(MinimaxResultType result_type, DepthType search_depth, const EqualScoreMoves &equal_score_moves)
void set_equal_score_moves(EqualScoreMoves equal_score_moves)
void RecordTrTableHit(TranspositionTableSearchResult &tr_table_search_result, DepthType remaining_search_depth)
void set_tr_table_size_final(size_t tr_table_size_final)
ResultDepthCountsData_t GetResultDepthCounts()
SearchSummary(DepthType max_search_depth, size_t tr_table_size_initial)
ResultDepthCountsData_t GetTranspositionTableHits()
void UpdateTranspositionTableHits(MinimaxResultType result_type, DepthType search_depth)
std::chrono::duration< double, std::nano > time_
void SetSelectedMove(Move selected_move)
std::chrono::duration< double, std::nano > time()
Container for storing a moveselection::MinimaxCalcResult retrieved by a call to boardstate::SingleZob...
bool IsConsistentWith(const MoveCollection &allowed_moves)
uint16_t DepthType
uint16_t MoveCountType
int Points_t
Definitions and implementations of gameboard::Move and other move-related structs.
Tracking piece positions and determining legal moves.
Selecting a move to execute.
const uint16_t kNumResultTypes
std::array< std::vector< int >, MinimaxResultType::kMax+1 > ResultDepthCountsData_t
Array of vectors for storing counts of moveselection::MinimaxResultType for each posible remaining se...
Providing position-dependent values of pieces to objects in moveselection namespace.
A container for multiple gameboard::Move objects.
A gameboard::BoardSpace pair (start and end).
A gameboard::Move, and an associated score calculated by a MoveEvaluator.
Stores a moveselection::SearchSummary for each moveselection::MinimaxMoveEvaluator....
SearchSummary & NewFirstSearch(DepthType search_depth, size_t tr_table_size_initial)
std::map< MoveCountType, SearchSummary > extra_searches
std::vector< SearchSummary > first_searches
SearchSummary & NewExtraSearch(DepthType search_depth, MoveCountType search_number, size_t tr_table_size_current)