5#include <pybind11/chrono.h>
6#include <pybind11/pybind11.h>
7#include <pybind11/stl.h>
33namespace py = pybind11;
34using namespace py::literals;
39template <
typename KeyType,
size_t NumConfKeys>
46 py::init<PieceColor, int, GameBoard &>(),
47 "evaluating_player"_a,
52 py::init<PieceColor, int, GameBoard &, uint32_t>(),
53 "evaluating_player"_a,
66 .def_property_readonly(
81 "zobrist_key_size_bits",
87 .def_property_readonly(
94 .def_property_readonly(
95 "board_state_hex_str",
104 py::enum_<game::GameState>(m,
"GameState")
110 py::enum_<game::EvaluatorType>(m,
"EvaluatorType")
115 py::class_<game::PlayerSpec>(m,
"PlayerSpec")
117 py::init<PieceColor, game::EvaluatorType, size_t, size_t, DepthType, uint32_t>(
120 py::arg(
"evaluator_type"),
121 py::arg(
"zobrist_key_size_bits"),
122 py::arg(
"zobrist_calculator_count"),
123 py::arg(
"minimax_search_depth"),
124 py::arg(
"zkeys_seed")
130 "zobrist_calculator_count",
136 py::class_<game::GameSummary>(m,
"GameSummary")
143 py::class_<game::GameRunner>(m,
"GameRunner")
145 py::init<game::PlayerSpec, game::PlayerSpec>(),
147 "black_player_spec"_a
154 const std::tuple<std::string, size_t> key_types[] = {
155 {
"uint32_t",
sizeof(uint32_t)},
156 {
"uint64_t",
sizeof(uint64_t)},
157 {
"__uint128_t",
sizeof(__uint128_t)}
160 py::class_<PiecePositionPoints>(m,
"PiecePositionPoints").def(py::init<>());
162 py::class_<moveselection::PreSearchMoveSorter<GameBoard, PiecePositionPoints>>(
164 "PreSearchMoveSorter"
167 py::init<GameBoard &, PiecePositionPoints &>(),
169 "game_position_points"_a
172 py::class_<BoardSpace>(m,
"BoardSpace")
173 .def(py::init<int, int>(),
"rank"_a,
"file"_a)
177 py::class_<GamePiece>(m,
"GamePiece")
179 .def(py::init<int>(),
"int_piece"_a)
180 .def(py::init<PieceType, PieceColor>(),
"piece_type"_a,
"piece_color"_a)
184 py::class_<Move>(m,
"Move")
185 .def(py::init<BoardSpace, BoardSpace>(),
"start"_a,
"end"_a)
189 py::class_<MoveCollection>(m,
"MoveCollection")
194 py::class_<moveselection::EqualScoreMoves>(m,
"EqualScoreMoves")
196 .def_property_readonly(
201 py::class_<ExecutedMove>(m,
"ExecutedMove")
203 py::init<Move, int, int>(),
206 "destination_piece"_a
212 py::enum_<PieceColor>(m,
"PieceColor")
218 py::enum_<PieceType>(m,
"PieceType")
232 py::enum_<moveselection::MinimaxResultType>(m,
"MinimaxResultType")
246 py::class_<GameBoard>(m,
"GameBoard")
249 .def(
"ExecuteMove", &GameBoard::ExecuteMove,
"move"_a)
250 .def(
"UndoMove", &GameBoard::UndoMove,
"executed_move"_a)
251 .def(
"GetAllSpacesOccupiedBy", &GameBoard::GetAllSpacesOccupiedBy,
"color"_a)
252 .def(
"CalcFinalMovesOf", &GameBoard::CalcFinalMovesOf,
"color"_a)
254 .def(
"GetType", &GameBoard::GetType,
"space"_a)
256 .def_property_readonly(
"is_draw", &GameBoard::IsDraw)
257 .def(
"GetColor", &GameBoard::GetColor,
"space"_a);
261 py::class_<moveselection::RandomMoveEvaluator<GameBoard>>(m,
"RandomMoveEvaluator")
262 .def(py::init<PieceColor, GameBoard &>(),
"evaluating_player"_a,
"game_board"_a)
269 py::class_<moveselection::SearchSummary>(m,
"SearchSummary")
270 .def_property_readonly(
276 "get_result_depth_counts",
280 "get_transposition_table_hits",
283 .def_property_readonly(
287 .def_property_readonly(
291 .def_property_readonly(
292 "returned_illegal_move",
295 .def_property_readonly(
299 .def_property_readonly(
300 "tr_table_size_initial",
303 .def_property_readonly(
304 "tr_table_size_final",
308 py::class_<moveselection::SearchSummaries>(m,
"SearchSummaries")
316 py::class_<TranspositionTableGuard>(m,
"TranspositionTableGuard").def(py::init<>());
319 bind_minimax_move_evaluator<uint32_t, 0>(m,
"MinimaxMoveEvaluator32");
320 bind_minimax_move_evaluator<uint64_t, 0>(m,
"MinimaxMoveEvaluator64");
321 bind_minimax_move_evaluator<__uint128_t, 0>(m,
"MinimaxMoveEvaluator128");
322 bind_minimax_move_evaluator<uint32_t, 1>(m,
"MinimaxMoveEvaluator32Dual");
323 bind_minimax_move_evaluator<uint64_t, 1>(m,
"MinimaxMoveEvaluator64Dual");
324 bind_minimax_move_evaluator<__uint128_t, 1>(m,
"MinimaxMoveEvaluator128Dual");
Definitions of classes used for storing piece points in Base Points Offset form.
void bind_minimax_move_evaluator(py::module_ &m, const std::string &class_name)
PYBIND11_MODULE(xiangqi_bindings, m)
Constants, typedefs, and simple structs used by gameboard::GameBoard.
Implements the BoardStateCoordinator interface, providing a moveselection::MinimaxMoveEvaluator with ...
const game::PlayerSpec & red_player_spec()
const game::PlayerSpec & black_player_spec()
Implements SpaceInfoProvider interface; stores piece positions, and exposes methods for calculating,...
const std::map< PieceColor, vector< ExecutedMove > > & move_log() const
bool IsInCheck(PieceColor color)
const BoardMap_t & map() const
MoveCollection move_collection()
Implements MoveEvaluator interface, and selects move::Move using Minimax algorithm; uses SpaceInfoPro...
Implements gameboard::MoveEvaluator interface.
EqualScoreMoves equal_score_moves()
size_t tr_table_size_initial()
ResultDepthCountsData_t GetResultDepthCounts()
size_t tr_table_size_final()
ResultDepthCountsData_t GetTranspositionTableHits()
bool returned_illegal_move()
std::chrono::duration< double, std::nano > time()
Definition of gameboard::GameBoard class.
Definitions of concrete classes that implement the MoveEvaluator interface.
Calculate / manage board state and associate Minimax results.
Tracking piece positions and determining legal moves.
PieceColor opponent_of(PieceColor color)
Providing position-dependent values of pieces to objects in moveselection namespace.
size_t size_of_points_type()
bool is_signed_points_type()
Definition of piecepoints::PiecePositionPoints.
std::unordered_map< gameboard::PieceColor, moveselection::SearchSummaries > search_summaries
game::GameState game_state
std::vector< ExecutedMove > move_log
std::unordered_map< gameboard::PieceColor, PlayerSpec > player_specs
EvaluatorType evaluator_type
DepthType minimax_search_depth
gameboard::PieceColor color
size_t zobrist_key_size_bits
size_t zobrist_calculator_count
gameboard::GamePiece moving_piece
gameboard::GamePiece destination_piece
bool ContainsMove(const Move &move) const
gameboard::BoardSpace end
gameboard::BoardSpace start
std::map< MoveCountType, SearchSummary > extra_searches
std::vector< SearchSummary > first_searches
Holds a piecepoints::GamePointsArray_t of points values, and exposes a method for accessing element c...
Contains implementaion of BoardStateTracker interface as a boardstate::ZobristTracker and supporting ...