Xiangiqgame
AI engine for Xiangqi
Loading...
Searching...
No Matches
move_data_structs.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
9
10using namespace gameboard;
11
12namespace gameboard {
13
18struct Move {
21
22 bool operator==(const Move &other) const {
23 return (start == other.start) && (end == other.end);
24 }
25};
26
32 vector<Move> moves;
34 : moves{} {};
35 MoveCollection(vector<Move> my_moves)
36 : moves{my_moves} {};
37 MoveCollection(size_t reserve_size)
38 : moves{} {
39 moves.reserve(reserve_size);
40 }
41
42 size_t Size() const { return moves.size(); }
43
44 bool IsEmpty() const { return moves.empty(); }
45
46 bool ContainsMove(const Move &move) const {
47 for (auto entry : moves) {
48 if ((move.start == entry.start) && (move.end == entry.end)) {
49 return true;
50 }
51 }
52 return false;
53 }
54
55 bool ContainsAnyMoveNotIn(const MoveCollection &other) const {
56 for (auto &entry : moves) {
57 if (!other.ContainsMove(entry)) {
58 return true;
59 }
60 }
61 return false;
62 }
63
65 auto selected_move_index = utility_functs::random((size_t)0, moves.size() - 1);
66 return moves[selected_move_index];
67 }
68
70 for (auto move : moves) {
71 if (move.end == space) {
72 return true;
73 }
74 }
75 return false;
76 }
77
78 void Append(Move move) { moves.emplace_back(move); }
79 void Concat(vector<Move> other_moves) {
80 moves.insert(moves.end(), other_moves.begin(), other_moves.end());
81 }
82 void Concat(MoveCollection other) {
83 moves.insert(moves.end(), other.moves.begin(), other.moves.end());
84 }
85};
86
98
101 bool operator==(const ExecutedMove other) {
102 return (other.spaces == spaces) && (other.moving_piece == moving_piece) &&
104 }
105};
106
107} // namespace gameboard
Constants, typedefs, and simple structs used by gameboard::GameBoard.
Defines GamePiece and supporting constants and free functions.
uint16_t MoveCountType
Tracking piece positions and determining legal moves.
T random(T range_from, T range_to)
A pair of coordinate (rank, and file) with properties determined by comparison with values of gameboa...
A change in the state of a gameboard::GameBoard represented by a gameboard::Move, and each of the gam...
gameboard::GamePiece moving_piece
MoveCountType moves_since_last_capture
gameboard::GamePiece destination_piece
bool operator==(const ExecutedMove other)
== operator overload; requires equality of pieces and space, but not moves_since_last capture.
A Xiangqi game piece described by its gameboard::PieceType and its gameboard::PieceColor.
Definition: game_piece.hpp:42
A container for multiple gameboard::Move objects.
void Concat(vector< Move > other_moves)
void Concat(MoveCollection other)
bool ContainsMove(const Move &move) const
bool ContainsAnyMoveNotIn(const MoveCollection &other) const
MoveCollection(size_t reserve_size)
bool ContainsDestination(const gameboard::BoardSpace &space)
MoveCollection(vector< Move > my_moves)
A gameboard::BoardSpace pair (start and end).
gameboard::BoardSpace end
bool operator==(const Move &other) const
gameboard::BoardSpace start
Defiition of miscellaneous free functions (and implementation of those that are templates).