Chess
piece.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include <SDL2/SDL.h>
9 #include <SDL_image.h>
10 
11 #include <optional>
12 #include <string>
13 #include <vector>
14 
15 class Chessboard;
16 class Piece;
17 
19 using FuncPtr = void (*)(const Piece &piece, std::vector<int> &possible_moves, const Chessboard &chessboard);
20 
21 enum Type {
22  PAWN,
23  KNIGHT,
24  BISHOP,
25  ROOK,
26  KING,
27  QUEEN
28 };
29 
31 class Piece {
32  public:
33  Piece(int pos, Type type, bool team_white);
34  Piece(const Piece &other);
35  Piece &operator=(const Piece &other);
36  Piece(Piece &&other) noexcept;
37  Piece &operator=(Piece &&other) noexcept;
39  std::vector<int> get_possible_moves(const Chessboard &chessboard);
40  bool is_opposing_team(std::optional<Piece> other) const;
41 
42  int pos;
43  Type type;
44  bool team_white;
45 
46  private:
48  std::vector<FuncPtr> find_move_functions;
49 };
50 void test_pawn(const Piece &piece, std::vector<int> &possible_moves, const Chessboard &chessboard);
51 void test_white_pawn(const Piece &piece, std::vector<int> &possible_moves, const Chessboard &chessboard);
52 void test_black_pawn(const Piece &piece, std::vector<int> &possible_moves, const Chessboard &chessboard);
53 void test_rook(const Piece &piece, std::vector<int> &possible_moves, const Chessboard &chessboard);
54 void test_bishop(const Piece &piece, std::vector<int> &possible_moves, const Chessboard &chessboard);
55 void test_knight(const Piece &piece, std::vector<int> &possible_moves, const Chessboard &chessboard);
56 void test_queen(const Piece &piece, std::vector<int> &possible_moves, const Chessboard &chessboard);
57 void test_king(const Piece &piece, std::vector<int> &possible_moves, const Chessboard &chessboard);
Class structure for the pieces that fill a game state&#39;s board.
Definition: piece.h:31
Used to create, store, and make changes to a game state.
Definition: chessboard.h:24
void(*)(const Piece &piece, std::vector< int > &possible_moves, const Chessboard &chessboard) FuncPtr
Simplifies function pointer syntax for functions filling a vector possible_moves. ...
Definition: piece.h:19
std::vector< int > get_possible_moves(const Chessboard &chessboard)
Returns possible moves for one piece.
Definition: piece.cpp:48