tartan 1.2.2.1
Chess API
Loading...
Searching...
No Matches
exceptions.hpp
1#ifndef _TARTAN_BOARD_EXCEPTIONS_HPP_
2#define _TARTAN_BOARD_EXCEPTIONS_HPP_
3
4#include <tartan/board.hpp>
5#include <stdexcept>
6#include <string>
7
9namespace tt::ex {
10
18class tartan : public std::logic_error {
19public:
20 using logic_error::logic_error;
21 virtual ~tartan() = default;
22};
23
30class bad_set : public tartan {
31public:
32 bad_set(
33 const std::string& what_arg = "Can not produce piece set"
34 ) : tartan(what_arg) {};
35};
36
38class bad_piece : public tartan {
39public:
45 const Piece* p,
46 const std::string& what_arg = "Invalid piece"
47 ) : tartan(what_arg) { e_piece = p; }
53 const Piece* piece() const { return e_piece; };
54private:
55 const Piece* e_piece;
56};
57
62class null_piece : public bad_piece {
63public:
68 const std::string what_arg = "Piece does not exists"
69 ) : bad_piece(nullptr, what_arg) {};
70 const Piece* piece() const = delete;
71};
72
77class foreign_piece : public bad_piece {
78public:
86 const Piece* p,
87 const Board* b,
88 const std::string& what_arg = "Piece does not belong to this board"
89 ) : bad_piece(p, what_arg) { e_board = b; };
96 const Board* board() const { return e_board; };
97private:
98 const Board* e_board;
99};
100
105class bad_piece_spec : public bad_piece {
106public:
112 const std::string& spec,
113 const std::string what_arg = "Invalid piece specification"
114 ) : bad_piece(nullptr, what_arg) { e_spec = spec; };
120 const std::string& spec() const { return e_spec; };
121private:
122 std::string e_spec;
123};
124
130public:
132 const Piece* p,
133 const std::string& what_arg = "Piece position is taken"
134 ) : bad_piece(p, what_arg) {};
135};
136
141class illegal_move : public tartan {
142public:
150 const std::string& what_arg = "Illegal move") :
151 tartan(what_arg), e_piece(p), e_to(to) {
152 };
159 const Piece* piece() const { return e_piece; };
166 const Piece::Position& to() const { return e_to; };
167 virtual ~illegal_move() = default;
168private:
169 const Piece* e_piece;
170 const Piece::Position& e_to;
171};
172
178public:
185 const Piece::Position& from,
186 const Piece::Position& to,
187 const std::string& what_arg = "Selected tile is empty")
188 : illegal_move(nullptr, to, what_arg), e_from(from) {};
189 const Piece* piece() = delete;
195 const Piece::Position& from() const { return e_from; };
196private:
197 const Piece::Position& e_from;
198};
199
205public:
212 const Piece* p,
213 const Piece::Position& to,
214 const std::string& what_arg = "Moved piece is in wrong color")
215 : illegal_move(p, to, what_arg) {};
216};
217
223public:
230 const Piece* p,
231 const Piece::Position& to,
232 const std::string& what_arg = "Selected piece can't move")
233 : illegal_move(p, to, what_arg) {};
234};
235
241public:
249 const Piece* p,
250 const Piece::Position& to,
251 const std::string& what_arg = "Selected piece can't perform such move")
252 : illegal_move(p, to, what_arg) {};
253};
254
259class illegal_turn : public tartan {
260public:
264 illegal_turn(const std::string& what_arg) :
265 tartan(what_arg) {};
266 illegal_turn(const char* what_arg) :
267 tartan(what_arg) {};
268};
269
274class bad_piece_type : public tartan {
275public:
276 bad_piece_type(const std::string what_arg = "Piece type is illegal") :
277 tartan(what_arg) {};
278};
279
280}
281
282#endif // !_TARTAN_BOARD_EXCEPTIONS_HPP_
8x8 game board
Definition board.hpp:690
Piece position at the Board.
Definition board.hpp:36
Generic board memeber API.
Definition board.hpp:23
Thrown when Board::piece() can not recognize Piece specification.
Definition exceptions.hpp:105
const std::string & spec() const
Get the malformed spec string.
Definition exceptions.hpp:120
bad_piece_spec(const std::string &spec, const std::string what_arg="Invalid piece specification")
Definition exceptions.hpp:111
Thrown when tt::Board::getPieceType() returns std::type_info that is not mentioned in its argument.
Definition exceptions.hpp:274
Base class for exceptions about pieces.
Definition exceptions.hpp:38
bad_piece(const Piece *p, const std::string &what_arg="Invalid piece")
Definition exceptions.hpp:44
const Piece * piece() const
Get the reported tt::Piece object.
Definition exceptions.hpp:53
Exception when Board::set() functions fail.
Definition exceptions.hpp:30
Thrown when Board::makeMove() is performed on Piece that can not make any moves.
Definition exceptions.hpp:222
can_not_move(const Piece *p, const Piece::Position &to, const std::string &what_arg="Selected piece can't move")
Definition exceptions.hpp:229
Thrown when piece does not belong to Board object in which it is being processed.
Definition exceptions.hpp:77
foreign_piece(const Piece *p, const Board *b, const std::string &what_arg="Piece does not belong to this board")
Definition exceptions.hpp:85
const Board * board() const
Get the Board object.
Definition exceptions.hpp:96
Base class for Board::makeMove() function errors.
Definition exceptions.hpp:141
const Piece * piece() const
Get Piece object.
Definition exceptions.hpp:159
const Piece::Position & to() const
Get move target location.
Definition exceptions.hpp:166
illegal_move(const Piece *p, const Piece::Position &to, const std::string &what_arg="Illegal move")
Definition exceptions.hpp:149
Thrown when constructed Piece::Turn object is malformed.
Definition exceptions.hpp:259
illegal_turn(const std::string &what_arg)
Definition exceptions.hpp:264
Thrown when piece moved with Board::makeMove() can not have such move.
Definition exceptions.hpp:240
no_such_move(const Piece *p, const Piece::Position &to, const std::string &what_arg="Selected piece can't perform such move")
Definition exceptions.hpp:248
Thrown when Piece pointer is nullptr when it should not be.
Definition exceptions.hpp:62
null_piece(const std::string what_arg="Piece does not exists")
Definition exceptions.hpp:67
Thrown when trying to Board::makeMove() on Piece that has wrong Piece::Color.
Definition exceptions.hpp:204
piece_in_wrong_color(const Piece *p, const Piece::Position &to, const std::string &what_arg="Moved piece is in wrong color")
Definition exceptions.hpp:211
Thrown when Piece Position on Board is occupied when it should not to.
Definition exceptions.hpp:129
Base class for all tartan exceptions.
Definition exceptions.hpp:18
Thrown when selected Piece location is empty of the Board.
Definition exceptions.hpp:177
tile_is_empty(const Piece::Position &from, const Piece::Position &to, const std::string &what_arg="Selected tile is empty")
Definition exceptions.hpp:184
const Piece::Position & from() const
Get empli tile Position.
Definition exceptions.hpp:195
Tartan tt::Board exceptions set.
Definition exceptions.hpp:9