Conquer Chess
Chess and Starcraft combined
Loading...
Searching...
No Matches
piece_action.h
Go to the documentation of this file.
1#ifndef PIECE_ACTION_H
2#define PIECE_ACTION_H
3
4#include "piece_action_type.h"
5#include "square.h"
6#include "piece_type.h"
7
8#include <iosfwd>
9#include <string>
10#include <vector>
11
18{
19public:
20
22 explicit piece_action(
23 const chess_color color,
24 const piece_type pt,
25 const piece_action_type at,
26 const square& from,
27 const square& to
28 );
29
31 explicit piece_action(
32 const chess_color color,
33 const piece_type pt,
34 const piece_action_type at,
35 const std::string& from_str,
36 const std::string& to_str
37 );
38
39 auto get_action_type() const noexcept { return m_action_type; }
40 const auto& get_from() const noexcept { return m_from; }
41 auto get_piece_type() const noexcept { return m_piece_type; }
42 auto get_color() const noexcept { return m_color; }
43 const auto& get_to() const noexcept { return m_to; }
44
45private:
46
47 piece_action_type m_action_type;
48 chess_color m_color;
49 square m_from;
50 piece_type m_piece_type;
51 square m_to;
52};
53
55std::string describe_action(const piece_action& p);
56
59
62 const std::vector<piece_action>& actions,
63 const piece_action_type t
64);
65
67bool is_double_move(const piece_action& a) noexcept;
68
72bool is_atomic(const piece_action& a) noexcept;
73
76
78std::vector<piece_action> to_atomic(const piece_action& a);
79
81std::string to_str(const piece_action& a) noexcept;
82
84std::string to_str(const std::vector<piece_action>& a) noexcept;
85
86bool operator==(const piece_action& lhs, const piece_action& rhs) noexcept;
87bool operator!=(const piece_action& lhs, const piece_action& rhs) noexcept;
88
89std::ostream& operator<<(std::ostream& os, const piece_action& p) noexcept;
90
91#endif // PIECE_ACTION_H
chess_color
A chess piece color.
Definition chess_color.h:10
An action to be done by a piece.
Definition piece_action.h:18
const auto & get_from() const noexcept
Definition piece_action.h:40
auto get_piece_type() const noexcept
Definition piece_action.h:41
const auto & get_to() const noexcept
Definition piece_action.h:43
auto get_action_type() const noexcept
Definition piece_action.h:39
auto get_color() const noexcept
Definition piece_action.h:42
A chess square.
Definition square.h:58
std::vector< piece_action > to_atomic(const piece_action &a)
Convert an action to one or more atomic actions.
Definition piece_action.cpp:335
bool is_atomic(const piece_action &a) noexcept
Is the action atomic, i.e.
Definition piece_action.cpp:73
bool is_double_move(const piece_action &a) noexcept
Is this a pawn moving two squares forward?
Definition piece_action.cpp:66
piece_action get_test_piece_action() noexcept
Get a piece_action to be used in testing.
Definition piece_action.cpp:43
bool has_action_of_type(const std::vector< piece_action > &actions, const piece_action_type t)
Is there at least one action of the specified type?
Definition piece_action.cpp:54
void test_piece_action()
Test the 'piece_action' class and its free functions.
Definition piece_action.cpp:86
std::string to_str(const piece_action &a) noexcept
Convert to string.
Definition piece_action.cpp:390
std::string describe_action(const piece_action &p)
Describe the 'piece_action' in words, e.g. 'move to (3, 4)'.
Definition piece_action.cpp:38
piece_action_type
The type of actions a piece can do.
Definition piece_action_type.h:9
piece_type
The type of chess piece.
Definition piece_type.h:9