diff options
author | ymherklotz <ymherklotz@gmail.com> | 2017-01-14 14:17:26 +0000 |
---|---|---|
committer | ymherklotz <ymherklotz@gmail.com> | 2017-01-14 14:17:26 +0000 |
commit | a5bc94a36fe37fb20eba61516da3b6b58208537b (patch) | |
tree | 30ba838ba6ece239c006dfae6db21d085df81832 | |
parent | 6fc3dfc10ce0e690b0de9c811e617dc76104db40 (diff) | |
download | ChessAI-a5bc94a36fe37fb20eba61516da3b6b58208537b.tar.gz ChessAI-a5bc94a36fe37fb20eba61516da3b6b58208537b.zip |
added colour to pieces and comments
-rw-r--r-- | include/chess_piece.hpp | 55 | ||||
-rw-r--r-- | src/bishop.cpp | 2 | ||||
-rw-r--r-- | src/chess_piece.cpp | 18 | ||||
-rw-r--r-- | src/king.cpp | 2 | ||||
-rw-r--r-- | src/knight.cpp | 2 | ||||
-rw-r--r-- | src/pawn.cpp | 2 | ||||
-rw-r--r-- | src/queen.cpp | 2 | ||||
-rw-r--r-- | src/rook.cpp | 2 |
8 files changed, 60 insertions, 25 deletions
diff --git a/include/chess_piece.hpp b/include/chess_piece.hpp index f03dad8..60b6fe5 100644 --- a/include/chess_piece.hpp +++ b/include/chess_piece.hpp @@ -19,27 +19,51 @@ // names namespace ymhChessAI { +// Colour enum class so that we can have the colours in the Chess Piece and not +// using normal enums because of undefined errors + +enum class Colour { + White, + Black +}; + + +// Base Chess Piece class that is inherited by all other chess pieces + class ChessPiece { public: + // constructor sets the initial position of the chess piece to 0, 0 ChessPiece(); + // using the default constructor for the copy constructor ChessPiece(const ChessPiece& other) = default; - ChessPiece(const int& x, const int& y); + // initialise piece at a specific location on the board to save code + ChessPiece(const int& x, const int& y, const Colour& colour); + // using default virtual d, const Colour &colourfault; virtual ~ChessPiece() = default; + // pure virtual function to move a piece as it depends completely on the + // implementation of the piece virtual void move(const int& x, const int& y) = 0; protected: + // current location of the piece which is protected as it can still be + // inherited by the piece classes int m_x, m_y; -private: + + // defines what colour the piece is + Colour m_colour; }; + +// King class that provides the class for the king + class King : public ChessPiece { public: King(); King(const King& other) = default; - King(const int& x, const int& y); + King(const int& x, const int& y, const Colour& colour); ~King() = default; - void move(const int& x, const int& y); + virtual void move(const int& x, const int& y); protected: private: }; @@ -48,10 +72,10 @@ class Queen : public ChessPiece { public: Queen(); Queen(const Queen& other) = default; - Queen(const int& x, const int& y); + Queen(const int& x, const int& y, const Colour& colour); ~Queen() = default; - void move(const int& x, const int& y); + virtual void move(const int& x, const int& y); protected: private: }; @@ -60,22 +84,23 @@ class Rook : public ChessPiece { public: Rook(); Rook(const Rook& other) = default; - Rook(const int& x, const int& y); + Rook(const int& x, const int& y, const Colour& colour); ~Rook() = default; - void move(const int& x, const int& y); + virtual void move(const int& x, const int& y); protected: private: }; + class Bishop : public ChessPiece { public: Bishop(); - Bishop(const Bishop& other) = default; - Bishop(const int& x, const int& y); + Bishop(const Bishop &other) = default; + Bishop(const int& x, const int& y, const Colour& colour); ~Bishop() = default; - void move(const int& x, const int& y); + virtual void move(const int& x, const int& y); protected: private: }; @@ -84,10 +109,10 @@ class Knight : public ChessPiece { public: Knight(); Knight(const Knight& other) = default; - Knight(const int& x, const int& y); + Knight(const int& x, const int& y, const Colour& colour); ~Knight() = default; - void move(const int& x, const int& y); + virtual void move(const int& x, const int& y); protected: private: }; @@ -96,10 +121,10 @@ class Pawn : public ChessPiece { public: Pawn(); Pawn(const Pawn& other) = default; - Pawn(const int& x, const int& y); + Pawn(const int& x, const int& y, const Colour& colour); ~Pawn() = default; - void move(const int& x, const int& y); + virtual void move(const int& x, const int& y); protected: private: }; diff --git a/src/bishop.cpp b/src/bishop.cpp index fc87db2..4894be5 100644 --- a/src/bishop.cpp +++ b/src/bishop.cpp @@ -18,7 +18,7 @@ using namespace ymhChessAI; Bishop::Bishop() : ChessPiece() { } -Bishop::Bishop(const int& x, const int& y) : ChessPiece(x, y) { +Bishop::Bishop(const int& x, const int& y, const Colour& colour) : ChessPiece(x, y, colour) { } void Bishop::move(const int& x, const int& y) { diff --git a/src/chess_piece.cpp b/src/chess_piece.cpp index 8d4cb94..ee307e2 100644 --- a/src/chess_piece.cpp +++ b/src/chess_piece.cpp @@ -1,12 +1,22 @@ +/* + * + * author: Yann Herklotz + * username: ymherklotz + * email: ymherklotz@gmail.com + * + * ----------------------------------------------------------------------------- + * + * Chess Piece class implementation + * + */ + #include "chess_piece.hpp" using namespace ymhChessAI; -// Chess Piece Base class that all the pieces inherit from - -ChessPiece::ChessPiece() : m_x(0), m_y(0) { +ChessPiece::ChessPiece() : m_x(0), m_y(0), m_colour(Colour::White) { } -ChessPiece::ChessPiece(const int& x, const int& y) : m_x(x), m_y(y) { +ChessPiece::ChessPiece(const int& x, const int& y, const Colour& colour) : m_x(x), m_y(y), m_colour(colour) { } diff --git a/src/king.cpp b/src/king.cpp index 0f332b7..8e8a6b9 100644 --- a/src/king.cpp +++ b/src/king.cpp @@ -18,7 +18,7 @@ using namespace ymhChessAI; King::King() : ChessPiece() { } -King::King(const int& x, const int& y) : ChessPiece(x, y) { +King::King(const int& x, const int& y, const Colour& colour) : ChessPiece(x, y, colour) { } void King::move(const int& x, const int& y) { diff --git a/src/knight.cpp b/src/knight.cpp index c40921f..5c2a946 100644 --- a/src/knight.cpp +++ b/src/knight.cpp @@ -18,7 +18,7 @@ using namespace ymhChessAI; Knight::Knight() : ChessPiece() { } -Knight::Knight(const int& x, const int& y) : ChessPiece(x, y) { +Knight::Knight(const int& x, const int& y, const Colour& colour) : ChessPiece(x, y, colour) { } void Knight::move(const int& x, const int& y) { diff --git a/src/pawn.cpp b/src/pawn.cpp index c1f172f..e81959f 100644 --- a/src/pawn.cpp +++ b/src/pawn.cpp @@ -18,7 +18,7 @@ using namespace ymhChessAI; Pawn::Pawn() : ChessPiece() { } -Pawn::Pawn(const int& x, const int& y) : ChessPiece(x, y) { +Pawn::Pawn(const int& x, const int& y, const Colour& colour) : ChessPiece(x, y, colour) { } void Pawn::move(const int& x, const int& y) { diff --git a/src/queen.cpp b/src/queen.cpp index d4e7ce0..d685548 100644 --- a/src/queen.cpp +++ b/src/queen.cpp @@ -18,7 +18,7 @@ using namespace ymhChessAI; Queen::Queen() : ChessPiece() { } -Queen::Queen(const int& x, const int& y) : ChessPiece(x, y) { +Queen::Queen(const int& x, const int& y, const Colour& colour) : ChessPiece(x, y, colour) { } void Queen::move(const int& x, const int& y) { diff --git a/src/rook.cpp b/src/rook.cpp index 166e114..cba38a9 100644 --- a/src/rook.cpp +++ b/src/rook.cpp @@ -18,7 +18,7 @@ using namespace ymhChessAI; Rook::Rook() : ChessPiece() { } -Rook::Rook(const int& x, const int& y) : ChessPiece(x, y) { +Rook::Rook(const int& x, const int& y, const Colour& colour) : ChessPiece(x, y, colour) { } void Rook::move(const int& x, const int& y) { |