diff options
author | zedarider <ymherklotz@gmail.com> | 2016-11-09 15:16:31 +0000 |
---|---|---|
committer | zedarider <ymherklotz@gmail.com> | 2016-11-09 15:16:31 +0000 |
commit | 946993f12456d0ec6dc97534b57393565404ad79 (patch) | |
tree | 30863007554309bb9df2d14597e0bf394159a932 /include/chess_ai.hpp | |
parent | 51af69807a888e6eea2ee105bf6a2a4993aba7e8 (diff) | |
parent | 476e22dd7d91a8ad061e022f28f65507870ef72c (diff) | |
download | ChessAI-946993f12456d0ec6dc97534b57393565404ad79.tar.gz ChessAI-946993f12456d0ec6dc97534b57393565404ad79.zip |
Merge branch 'master' into edit
Diffstat (limited to 'include/chess_ai.hpp')
-rw-r--r-- | include/chess_ai.hpp | 72 |
1 files changed, 45 insertions, 27 deletions
diff --git a/include/chess_ai.hpp b/include/chess_ai.hpp index 090b4ee..a62ddf4 100644 --- a/include/chess_ai.hpp +++ b/include/chess_ai.hpp @@ -9,17 +9,29 @@ namespace chess_ai { + // Describes the different types of chess pieces there are on the board enum piece_type : unsigned; + + // Describes the colour of the pieces enum piece_colour : unsigned; + + // just describes if the board is full or empty enum board_state : unsigned; + + // defines the errors that can happen when moving a piece + enum movement_flag : unsigned; + + // The chess board that will be played on class chess_board; + + // Any chess piece in the game class chess_piece; + // typedefs for iterators to access elements easier typedef std::vector<std::vector<chess_ai::chess_piece>>:: iterator vector_iterator; typedef std::vector<chess_ai::chess_piece>::iterator square_iterator; - // Describes the different types of chess pieces there are on the board enum piece_type : unsigned { // A pawn can only move forward twice on the first move, otherwise only // once. It only take pieces that are on the diagonals in front of it, @@ -51,7 +63,6 @@ iterator vector_iterator; empty }; - // Describes the colour of the pieces enum piece_colour : unsigned { // Looking at the board white will be at the bottom white, @@ -61,7 +72,6 @@ iterator vector_iterator; none }; - // just describes if the board is full or empty enum board_state : unsigned { // The starting position of the board with all pieces in the right // position @@ -74,7 +84,24 @@ iterator vector_iterator; clear }; - // The chess board that will be played on + enum movement_flag : unsigned { + // when king is in check there are limited possibilities + move_error_KingInCheckAfterMove, + // when there is a friendly piece in the way + move_error_FriendlyPieceOnDestination, + // when there is an enemy piece blocking the way + move_error_EnemyPieceOnDestination, + // illegal move for chose piece + move_error_IllegalMove, + + // when the move is successful + move_Success, + // when a move leads to a check + move_Check, + // when a move leads to a checkmate + move_Checkmate, + }; + class chess_board { public: @@ -98,25 +125,27 @@ iterator vector_iterator; void remove_piece(unsigned x, unsigned y); // move a piece according to the chess rules - void move_piece(chess_piece piece); - - // move a piece from coordinates - void move_piece(unsigned x, unsigned y); - void move_piece(unsigned orig_x, unsigned orig_y, unsigned dest_x, - unsigned dest_y); - void move_piece(chess_piece piece, unsigned x, unsigned y); + movement_flag move_piece(chess_piece piece); + movement_flag move_piece(unsigned x, unsigned y); + movement_flag move_piece(unsigned orig_x, unsigned orig_y, unsigned dest_x, + unsigned dest_y); + movement_flag move_piece(unsigned orig_x, unsigned orig_y, unsigned dest_x, + unsigned dest_y, chess_piece& taken_piece); + movement_flag move_piece(chess_piece piece, unsigned x, unsigned y); // iterate through the list and return the pointer to change square_iterator& iterate_board(square_iterator& it, unsigned x, unsigned y); - - - protected: - - void init_board_vector(); private: + + // initialises vector + void init_board_vector(); + + // moves the pawn + movement_flag move_pawn(square_iterator it, square_iterator new_it, + chess_piece& taken_piece); // The size of the chess board is a constant and hence defined by a // preprocessed define statement. @@ -126,7 +155,6 @@ iterator vector_iterator; std::vector<std::vector<chess_piece>> grid; }; - // Any chess piece in the game class chess_piece { friend class chess_board; public: @@ -157,19 +185,9 @@ iterator vector_iterator; // set the different values void set(piece_type type, piece_colour colour, unsigned x, unsigned y); - // overloading operators - - // so that we can make two copies of a point - chess_piece& operator==(const chess_piece& piece); - - // overload ++ operator for pawns - chess_piece& operator++(); - chess_piece operator++(int); - // return a printable version of the square std::string str(); - protected: private: // Type of the chess piece, eg. bishop or queen |