Conquer Chess
Chess and Starcraft combined
Loading...
Searching...
No Matches
chess_move.h
Go to the documentation of this file.
1#ifndef CHESS_MOVE_H
2#define CHESS_MOVE_H
3
4#include "castling_type.h"
5#include "piece_type.h"
6#include "square.h"
7#include "pgn_move_string.h"
8#include "fen_string.h"
9
10#include <string>
11#include <vector>
12#include <optional>
13#include <iosfwd>
14
22{
23public:
25 explicit chess_move(
26 const pgn_move_string& pgn_str,
28 );
29
31 const auto& get_action_type() const noexcept { return m_action_type; }
32
35 const auto& get_castling_type() const noexcept { return m_castling_type; };
36
38 const auto& get_color() const noexcept { return m_color; };
39
43 const auto& get_from() const noexcept { return m_from; }
44
46 const auto& get_pgn_str() const noexcept { return m_pgn_str; }
47
50 const auto& get_promotion_type() const noexcept { return m_promotion_type; };
51
56 const auto& get_to() const noexcept { return m_to; }
57
60 const auto& get_piece_type() const noexcept { return m_piece_type; }
61
66 const auto& get_winner() const noexcept { return m_winner; }
67
70 bool is_capture() const noexcept { return m_is_capture; }
71
72private:
73
77 std::optional<piece_action_type> m_action_type;
78
80 std::optional<castling_type> m_castling_type;
81
82 chess_color m_color;
83
84 std::optional<square> m_from;
85
86 bool m_is_capture;
87
89 pgn_move_string m_pgn_str;
90
93 std::optional<piece_type> m_promotion_type;
94
95 std::optional<square> m_to;
96
97 std::optional<piece_type> m_piece_type;
98
103 std::vector<chess_color> m_winner;
104
105};
106
111std::optional<square> get_from(const fen_string& s, const pgn_move_string& m);
112
115
120
123
126
129
132
134bool is_capture(const chess_move& move) noexcept;
135
137bool is_castling(const chess_move& move) noexcept;
138
140bool is_draw(const chess_move& move) noexcept;
141
145bool is_simple_move(const chess_move& move) noexcept;
146
148bool is_promotion(const chess_move& move) noexcept;
149
151bool is_win(const chess_move& move) noexcept;
152
154void test_chess_move();
155
156bool operator==(const chess_move& lhs, const chess_move& rhs) noexcept;
157
158std::ostream& operator<<(std::ostream& os, const chess_move& m) noexcept;
159
160#endif // CHESS_MOVE_H
chess_color
A chess piece color.
Definition chess_color.h:10
bool is_castling(const chess_move &move) noexcept
Get if the move is a castling.
Definition chess_move.cpp:233
bool is_promotion(const chess_move &move) noexcept
Get if the move is a promotion.
Definition chess_move.cpp:243
square get_from_for_king(const fen_string &s, const pgn_move_string &m)
Get the square the king doing the move came from.
Definition chess_move.cpp:105
bool is_capture(const chess_move &move) noexcept
Get if the move is a capture.
Definition chess_move.cpp:228
bool is_win(const chess_move &move) noexcept
Get if the move is a win.
Definition chess_move.cpp:258
square get_from_for_bishop(const fen_string &s, const pgn_move_string &m)
Get the square the bishop doing the move came from.
Definition chess_move.cpp:80
bool operator==(const chess_move &lhs, const chess_move &rhs) noexcept
Definition chess_move.cpp:476
bool is_simple_move(const chess_move &move) noexcept
Get if the move is a move, i.e.
Definition chess_move.cpp:248
std::optional< square > get_from(const fen_string &s, const pgn_move_string &m)
Get the square the piece doing the move came from, if any.
Definition chess_move.cpp:60
bool is_draw(const chess_move &move) noexcept
Get if the move is a win.
Definition chess_move.cpp:238
void test_chess_move()
Test this class and its free functions.
Definition chess_move.cpp:263
square get_from_for_knight(const fen_string &s, const pgn_move_string &m)
Get the square the knight doing the move came from.
Definition chess_move.cpp:118
square get_from_for_rook(const fen_string &s, const pgn_move_string &m)
Get the square the rook doing the move came from.
Definition chess_move.cpp:199
square get_from_for_queen(const fen_string &s, const pgn_move_string &m)
Get the square the queen doing the move came from.
Definition chess_move.cpp:165
square get_from_for_pawn(const fen_string &s, const pgn_move_string &m)
Get the square the pawn doing the move came from.
Definition chess_move.cpp:143
std::ostream & operator<<(std::ostream &os, const chess_move &m) noexcept
Definition chess_move.cpp:483
A chess move.
Definition chess_move.h:22
const auto & get_piece_type() const noexcept
The type of chess piece.
Definition chess_move.h:60
const auto & get_from() const noexcept
Get the source/from square, e.g.
Definition chess_move.h:43
const auto & get_action_type() const noexcept
The type of action this move is.
Definition chess_move.h:31
const auto & get_to() const noexcept
Get the target square, e.g.
Definition chess_move.h:56
const auto & get_pgn_str() const noexcept
Get the original PGN string back.
Definition chess_move.h:46
const auto & get_promotion_type() const noexcept
Get the promotion type.
Definition chess_move.h:50
const auto & get_winner() const noexcept
Get the winner.
Definition chess_move.h:66
const auto & get_castling_type() const noexcept
Get the castling type.
Definition chess_move.h:35
bool is_capture() const noexcept
Is this move a capture? E.g.
Definition chess_move.h:70
const auto & get_color() const noexcept
Get the color of the player that did this move.
Definition chess_move.h:38
Forsyth–Edwards Notation string.
Definition fen_string.h:20
A string that is a PGN notation string.
Definition pgn_move_string.h:16
A chess square.
Definition square.h:58
fen_string create_fen_string_of_standard_starting_position(const chess_color active_player=chess_color::white)
Create the FEN string of the standard starting position.
Definition fen_string.cpp:13