Conquer Chess
Chess and Starcraft combined
Loading...
Searching...
No Matches
pieces.h
Go to the documentation of this file.
1#ifndef PIECES_H
2#define PIECES_H
3
5
6#include "ccfwd.h"
8#include "piece.h"
10
37std::vector<std::string> add_coordinats(
38 const std::vector<std::string>& strs
39);
40
51std::vector<std::string> add_legend(
52 const std::vector<std::string>& strs
53);
54
56std::vector<double> calc_distances(
57 const std::vector<piece>& pieces,
58 const game_coordinate& coordinat
59);
60
67bool can_move(
68 const std::vector<piece>& pieces,
69 const chess_color placer_color,
70 const piece_type selected_piece_type,
71 const square& selected_piece_square,
72 const square& destination_square
73);
74
77action_history collect_action_history(const std::vector<piece>& pieces);
78
81 const std::vector<piece>& pieces
82);
83
86 const std::vector<piece>& pieces,
87 const chess_color player
88);
89
90std::vector<piece> create_pieces_from_fen_string(const fen_string& s);
91
94 const std::vector<piece>& pieces,
95 const chess_color c
96);
97
99std::vector<piece> get_pieces_kings_only(
100 const race white_race = race::classic,
101 const race black_race = race::classic
102) noexcept;
103
105int get_max_pieces_value() noexcept;
106
116std::vector<square> get_unique_occupied_squares(const std::vector<piece>& pieces);
117
127std::vector<square> get_occupied_squares(const std::vector<piece>& pieces);
128
131const piece& get_piece_at(
132 const std::vector<piece>& pieces,
133 const square& coordinat
134);
135
139 std::vector<piece>& pieces,
140 const square& coordinat
141);
142
146 const std::vector<piece>& pieces,
147 const piece& focal_piece
148);
149
153 const std::vector<piece>& pieces,
154 const piece& focal_piece
155);
156
160 const std::vector<piece>& pieces,
161 const piece& focal_piece
162);
163
166std::vector<square> get_possible_moves(
167 const std::vector<piece>& pieces,
168 const piece& focal_piece
169);
170
174 const std::vector<piece>& pieces,
175 const piece& focal_piece
176);
177
181 const std::vector<piece>& pieces,
182 const piece& focal_piece
183);
184
188 const std::vector<piece>& pieces,
189 const piece& focal_piece
190);
191
192
193
196 const race white_race = race::classic,
197 const race black_race = race::classic
198) noexcept;
199
203 const race white_race = race::classic,
204 const race black_race = race::classic
205) noexcept;
206
213 const race white_race = race::classic,
214 const race black_race = race::classic
215) noexcept;
216
224 const race white_race = race::classic,
225 const race black_race = race::classic
226) noexcept;
227
231 const race white_race = race::classic,
232 const race black_race = race::classic
233) noexcept;
234
238 const race white_race = race::classic,
239 const race black_race = race::classic
240) noexcept;
241
248 const race white_race = race::classic,
249 const race black_race = race::classic
250) noexcept;
251
258 const race white_race = race::classic,
259 const race black_race = race::classic
260) noexcept;
261
268 const race white_race = race::classic,
269 const race black_race = race::classic
270) noexcept;
271
276 const race white_race = race::classic,
277 const race black_race = race::classic
278) noexcept;
279
282 const race white_race = race::classic,
283 const race black_race = race::classic
284) noexcept;
285
289 const race white_race = race::classic,
290 const race black_race = race::classic
291) noexcept;
292
294std::vector<piece> get_starting_pieces(
296 const race white_race = race::classic,
297 const race black_race = race::classic
298) noexcept;
299
304 const std::vector<piece>& pieces,
305 const chess_color c
306);
307
309bool has_king(
310 const std::vector<piece>& pieces,
311 const chess_color c
312);
313
315bool is_checkmate(
316 const std::vector<piece>& pieces,
317 const chess_color player_in_checkmate
318);
319
321bool is_draw(const std::vector<piece>& pieces);
322
325 const std::vector<piece>& pieces,
326 const chess_color player_color
327);
328
330bool is_piece_at(
331 const std::vector<piece>& pieces,
332 const game_coordinate& coordinat,
333 const double distance = 0.5
334);
335
337bool is_piece_at(
338 const std::vector<piece>& pieces,
339 const square& coordinat
340);
341
344 const std::vector<piece>& pieces,
345 const square& piece_square,
346 const square& target_square
347);
348
358 const std::vector<piece>& pieces,
359 const square& s,
360 const chess_color attacker_color
361);
362
372 const std::vector<piece>& pieces,
373 const square& s,
374 const chess_color c
375);
376
378void test_pieces();
379
419std::string to_board_str(
420 const std::vector<piece>& pieces,
422) noexcept;
423
425std::vector<std::string> to_board_strs(
426 const std::vector<piece>& pieces,
428) noexcept;
429
435std::string to_fen_str(
436 const std::vector<piece>& pieces,
437 const chess_color active_color = chess_color::white,
438 const std::string castling_availability = "KQkq",
439 const std::string en_passant_target_square = "-",
440 const int halfmove_clock = 0,
441 const int fullmove_number = 1
442);
443
446std::string to_pgn(const std::vector<piece>& pieces);
447
448/*
450void unselect_all_pieces(
451 std::vector<piece>& pieces,
452 const chess_color color
453);
454*/
455
456#endif // PIECES_H
chess_color
A chess piece color.
Definition chess_color.h:10
The collected in-game times of actions, in chrononical order.
Definition action_history.h:17
Options on how to convert a chessboard to text.
Definition board_to_text_options.h:10
Forsyth–Edwards Notation string.
Definition fen_string.h:20
An exact coordinate anywhere on the board.
Definition game_coordinate.h:32
A chess piece.
Definition piece.h:24
A chess square.
Definition square.h:58
piece_type
The type of chess piece.
Definition piece_type.h:9
std::vector< square > get_possible_king_moves(const std::vector< piece > &pieces, const piece &focal_piece)
Get the possible moves for a focal piece that is a king.
Definition pieces.cpp:388
bool is_king_under_attack(const std::vector< piece > &pieces, const chess_color player_color)
Determine if the king of the player is under attack.
Definition pieces.cpp:1060
std::vector< piece > get_pieces_pawns_nearly_near_promotion(const race white_race=race::classic, const race black_race=race::classic) noexcept
Get the pieces where pawns are nealy near promotion.
Definition pieces.cpp:761
std::vector< piece > get_pieces_pawns_at_promotion(const race white_race=race::classic, const race black_race=race::classic) noexcept
Get the pieces where pawns are at promotion.
Definition pieces.cpp:733
std::vector< piece > get_pieces_queen_endgame(const race white_race=race::classic, const race black_race=race::classic) noexcept
Get the pieces for a queen endgame, which are having only the kings and queens left from a default se...
Definition pieces.cpp:831
std::vector< std::string > add_coordinats(const std::vector< std::string > &strs)
Surround the 8x8 strings of a chessboard by coordinats Without coordinats:
Definition pieces.cpp:35
std::string to_board_str(const std::vector< piece > &pieces, const board_to_text_options &options=board_to_text_options()) noexcept
Show the pieces as if on a chessboard, such as:
Definition pieces.cpp:1703
bool can_move(const std::vector< piece > &pieces, const chess_color placer_color, const piece_type selected_piece_type, const square &selected_piece_square, const square &destination_square)
Can a piece move from 'from' to 'to'?
Definition pieces.cpp:106
std::vector< piece > get_pieces_before_scholars_mate(const race white_race=race::classic, const race black_race=race::classic) noexcept
Get the pieces before a scholar's mate.
Definition pieces.cpp:775
std::vector< square > get_possible_rook_moves(const std::vector< piece > &pieces, const piece &focal_piece)
Get the possible moves for a focal piece that is a rook.
Definition pieces.cpp:583
std::vector< piece > get_pieces_ready_to_not_castle(const race white_race=race::classic, const race black_race=race::classic) noexcept
Get the pieces for a kings that are ready to castle, but cannot, as the king would go through check.
Definition pieces.cpp:879
bool is_piece_looking_at_square(const std::vector< piece > &pieces, const square &piece_square, const square &target_square)
Determine if a piece (at piece_square) is looking at a target square.
Definition pieces.cpp:1101
std::vector< piece > get_pieces_bishop_and_knight_end_game(const race white_race=race::classic, const race black_race=race::classic) noexcept
Get the pieces from a bishop and knight end game.
Definition pieces.cpp:817
void test_pieces()
Test all these free functions.
Definition pieces.cpp:1200
std::vector< square > get_possible_knight_moves(const std::vector< piece > &pieces, const piece &focal_piece)
Get the possible moves for a focal piece that is a knight.
Definition pieces.cpp:425
std::vector< square > get_possible_moves(const std::vector< piece > &pieces, const piece &focal_piece)
Get the possible moves for a focal piece.
Definition pieces.cpp:466
int count_dead_pieces(const std::vector< piece > &pieces)
Count the total number of dead pieces.
Definition pieces.cpp:166
std::vector< std::string > to_board_strs(const std::vector< piece > &pieces, const board_to_text_options &options=board_to_text_options()) noexcept
Show the pieces as if on a chessboard.
Definition pieces.cpp:1716
int get_total_pieces_value(const std::vector< piece > &pieces, const chess_color c)
Get the total value of all (non-king) chess pieces.
Definition pieces.cpp:1012
std::vector< square > get_occupied_squares(const std::vector< piece > &pieces)
Get all the squares that are occupied, allowing duplicates.
Definition pieces.cpp:293
int get_max_pieces_value() noexcept
Get the maximum piece value a color can have on a standard chessboard.
Definition pieces.cpp:288
int count_piece_actions(const std::vector< piece > &pieces, const chess_color player)
Count the total number of actions to be done by pieces of a player.
Definition pieces.cpp:180
action_history collect_action_history(const std::vector< piece > &pieces)
Collect the history of a game, i.e.
Definition pieces.cpp:149
std::vector< piece > get_pieces_pawn_all_out_assault(const race white_race=race::classic, const race black_race=race::classic) noexcept
Get the pieces from a standard game, with all pawns moved two squares forward.
Definition pieces.cpp:691
bool is_draw(const std::vector< piece > &pieces)
Determine if the game is a draw.
Definition pieces.cpp:1055
std::vector< piece > get_pieces_pawns_near_promotion(const race white_race=race::classic, const race black_race=race::classic) noexcept
Get the pieces where pawns are near promotion.
Definition pieces.cpp:747
std::vector< piece > get_starting_pieces(const starting_position_type t=starting_position_type::standard, const race white_race=race::classic, const race black_race=race::classic) noexcept
Get all the pieces in the starting position type.
Definition pieces.cpp:971
std::vector< piece > get_pieces_kings_only(const race white_race=race::classic, const race black_race=race::classic) noexcept
Get a king-versus-king starting position.
Definition pieces.cpp:269
std::vector< piece > create_pieces_from_fen_string(const fen_string &s)
Definition pieces.cpp:200
bool is_square_attacked(const std::vector< piece > &pieces, const square &s, const chess_color attacker_color)
Determine if the square is attacked by (another) piece of a certain color.
Definition pieces.cpp:1153
std::string to_pgn(const std::vector< piece > &pieces)
Convert the played game (i.e.
Definition pieces.cpp:1794
bool is_checkmate(const std::vector< piece > &pieces, const chess_color player_in_checkmate)
Determine if the player is mated.
Definition pieces.cpp:1044
std::vector< std::string > add_legend(const std::vector< std::string > &strs)
Add a legend to the 8x8 or 12x12 strings of a chessboard.
Definition pieces.cpp:68
std::vector< square > get_possible_queen_moves(const std::vector< piece > &pieces, const piece &focal_piece)
Get the possible moves for a focal piece that is a queen.
Definition pieces.cpp:540
bool has_king(const std::vector< piece > &pieces, const chess_color c)
Does this color still have a king?
Definition pieces.cpp:1027
const piece & get_piece_at(const std::vector< piece > &pieces, const square &coordinat)
Get the piece that at that square, will throw if there is no piece.
Definition pieces.cpp:311
bool is_square_protected(const std::vector< piece > &pieces, const square &s, const chess_color c)
Determine if the square is protected by (another) piece of a certain color.
Definition pieces.cpp:1176
std::vector< square > get_possible_bishop_moves(const std::vector< piece > &pieces, const piece &focal_piece)
Get the possible moves for a focal piece that is a bishop.
Definition pieces.cpp:350
std::string to_fen_str(const std::vector< piece > &pieces, const chess_color active_color=chess_color::white, const std::string castling_availability="KQkq", const std::string en_passant_target_square="-", const int halfmove_clock=0, const int fullmove_number=1)
Convert pieces to a FEN string.
Definition pieces.cpp:1739
std::vector< double > calc_distances(const std::vector< piece > &pieces, const game_coordinate &coordinat)
Calculate the distances that each piece has to a coordinat.
Definition pieces.cpp:85
std::vector< piece > get_standard_starting_pieces(const race white_race=race::classic, const race black_race=race::classic) noexcept
Get all the pieces in the starting position.
Definition pieces.cpp:916
square get_current_king_square(const std::vector< piece > &pieces, const chess_color c)
Get the square where the king of that color is.
Definition pieces.cpp:250
std::vector< square > get_unique_occupied_squares(const std::vector< piece > &pieces)
Get all the squares that are occupied, disallowing duplicates.
Definition pieces.cpp:304
std::vector< piece > get_pieces_ready_to_castle(const race white_race=race::classic, const race black_race=race::classic) noexcept
Get the pieces for a kings that are ready to castle.
Definition pieces.cpp:845
bool is_piece_at(const std::vector< piece > &pieces, const game_coordinate &coordinat, const double distance=0.5)
Determine if there is a piece at the coordinat.
Definition pieces.cpp:1070
std::vector< piece > get_pieces_kasparov_vs_topalov(const race white_race=race::classic, const race black_race=race::classic) noexcept
Get the pieces for a Kasparov vs Topalov game, discovered at https://www.reddit.com/r/chess/comments/...
Definition pieces.cpp:662
std::vector< square > get_possible_pawn_moves(const std::vector< piece > &pieces, const piece &focal_piece)
Get the possible moves for a focal piece that is a pawn.
Definition pieces.cpp:487
std::vector< piece > get_pieces_before_en_passant(const race white_race=race::classic, const race black_race=race::classic) noexcept
Create a setup of pieces in which en passant becomes possible in the next move.
Definition pieces.cpp:644
race
The chess race.
Definition race.h:10
@ classic
starting_position_type
The starting position type.
Definition starting_position_type.h:10