diff options
sem 15
14 files changed, 206 insertions, 0 deletions
| -rw-r--r-- | Sem. 15/Chess/Figures/Bishop/Bishop.cpp | 16 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/Bishop/Bishop.h | 13 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/FigureBase/Figure.cpp | 0 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/FigureBase/Figure.h | 16 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/King/King.cpp | 16 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/King/King.h | 11 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/Knight/Knight.cpp | 26 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/Knight/Knight.h | 11 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/Pawn/Pawn.cpp | 31 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/Pawn/Pawn.h | 11 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/Queen/Queen.cpp | 18 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/Queen/Queen.h | 11 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/Rook/Rook.cpp | 15 | ||||
| -rw-r--r-- | Sem. 15/Chess/Figures/Rook/Rook.h | 11 |
diff --git a/Sem. 15/Chess/Figures/Bishop/Bishop.cpp b/Sem. 15/Chess/Figures/Bishop/Bishop.cpp new file mode 100644 index 0000000..80121e2 --- /dev/null +++ b/Sem. 15/Chess/Figures/Bishop/Bishop.cpp @@ -0,0 +1,16 @@ +#include "Bishop.h" +#include <cmath> + +Bishop::Bishop(bool isWhite) : Figure(isWhite) +{} +bool Bishop::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const +{ + return abs((int)currentX - (int)destX) == abs((int)currentY - (int)destY); +} +void Bishop::print() const +{ + if (getIsWhite()) + std::cout << 'B'; + else + std::cout << 'b'; +} diff --git a/Sem. 15/Chess/Figures/Bishop/Bishop.h b/Sem. 15/Chess/Figures/Bishop/Bishop.h new file mode 100644 index 0000000..86949a7 --- /dev/null +++ b/Sem. 15/Chess/Figures/Bishop/Bishop.h @@ -0,0 +1,13 @@ +#pragma once +#include "../FigureBase/Figure.h" + +class Bishop : virtual public Figure +{ + +public: + Bishop(bool isWhite); + bool canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const override; + + void print() const override; + +};
\ No newline at end of file diff --git a/Sem. 15/Chess/Figures/FigureBase/Figure.cpp b/Sem. 15/Chess/Figures/FigureBase/Figure.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Sem. 15/Chess/Figures/FigureBase/Figure.cpp diff --git a/Sem. 15/Chess/Figures/FigureBase/Figure.h b/Sem. 15/Chess/Figures/FigureBase/Figure.h new file mode 100644 index 0000000..c0a84a5 --- /dev/null +++ b/Sem. 15/Chess/Figures/FigureBase/Figure.h @@ -0,0 +1,16 @@ +#pragma once +#include <iostream> + +class Figure +{ + bool isWhite; +public: + Figure(bool isWhite) :isWhite(isWhite) + {} + virtual bool canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const = 0; + virtual void print() const = 0; + + bool getIsWhite() const { return isWhite; }; + + virtual ~Figure(){}; +};
\ No newline at end of file diff --git a/Sem. 15/Chess/Figures/King/King.cpp b/Sem. 15/Chess/Figures/King/King.cpp new file mode 100644 index 0000000..9d323f3 --- /dev/null +++ b/Sem. 15/Chess/Figures/King/King.cpp @@ -0,0 +1,16 @@ +#include "King.h" +#include <cmath> + +King::King(bool isWhite) : Figure(isWhite) +{} +bool King::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const +{ + return abs((int)currentX - (int)destX) <= 1 && abs((int)currentY - (int)destY) <= 1; +} +void King::print() const +{ + if (getIsWhite()) + std::cout << '%'; + else + std::cout << '$'; +}
\ No newline at end of file diff --git a/Sem. 15/Chess/Figures/King/King.h b/Sem. 15/Chess/Figures/King/King.h new file mode 100644 index 0000000..85a8e02 --- /dev/null +++ b/Sem. 15/Chess/Figures/King/King.h @@ -0,0 +1,11 @@ +#pragma once +#include "../FigureBase/Figure.h" + +class King : public Figure +{ + +public: + King(bool isWhite); + bool canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const override; + void print() const override; +};
\ No newline at end of file diff --git a/Sem. 15/Chess/Figures/Knight/Knight.cpp b/Sem. 15/Chess/Figures/Knight/Knight.cpp new file mode 100644 index 0000000..e6db119 --- /dev/null +++ b/Sem. 15/Chess/Figures/Knight/Knight.cpp @@ -0,0 +1,26 @@ +#include "Knight.h" +#include <cmath> + +Knight::Knight(bool isWhite) : Figure(isWhite) +{} +bool Knight::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const +{ + int xMovеment[] = { 1, 1, -1, -1, 2, -2, 2, -2 }; + int yMovеment[] = { 2, -2, 2, -2, 1, 1, -1, -1 }; + + for (int i = 0; i < 8; i++) + { + if (currentX + xMovеment[i] == destX && + currentY + yMovеment[i] == destY) + return true; + } + return false; +} + +void Knight::print() const +{ + if (getIsWhite()) + std::cout << 'K'; + else + std::cout << 'k'; +}
\ No newline at end of file diff --git a/Sem. 15/Chess/Figures/Knight/Knight.h b/Sem. 15/Chess/Figures/Knight/Knight.h new file mode 100644 index 0000000..72acfea --- /dev/null +++ b/Sem. 15/Chess/Figures/Knight/Knight.h @@ -0,0 +1,11 @@ +#pragma once +#include "../FigureBase/Figure.h" + +class Knight : public Figure +{ + +public: + Knight(bool isWhite); + bool canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const override; + void print() const override; +};
\ No newline at end of file diff --git a/Sem. 15/Chess/Figures/Pawn/Pawn.cpp b/Sem. 15/Chess/Figures/Pawn/Pawn.cpp new file mode 100644 index 0000000..fd04dad --- /dev/null +++ b/Sem. 15/Chess/Figures/Pawn/Pawn.cpp @@ -0,0 +1,31 @@ +#include "Pawn.h" +#include <cmath> +Pawn::Pawn(bool isWhite) : Figure(isWhite), isFirstMove(true) +{} +bool Pawn::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const +{ + /*if (currentX != destX) + return false; + + int diff = destY - currentY; + + if (abs(diff) > 2) + return false; + + if (diff < 0 && getIsWhite() || diff > 0 && !getIsWhite()) + return false; + + if (!abs(diff) == 2 || isFirstMove) + { + return true; + } + return false;*/ + return false; +} +void Pawn::print() const +{ + if (getIsWhite()) + std::cout << 'P'; + else + std::cout << 'p'; +}
\ No newline at end of file diff --git a/Sem. 15/Chess/Figures/Pawn/Pawn.h b/Sem. 15/Chess/Figures/Pawn/Pawn.h new file mode 100644 index 0000000..675bf0b --- /dev/null +++ b/Sem. 15/Chess/Figures/Pawn/Pawn.h @@ -0,0 +1,11 @@ +#pragma once +#include "../FigureBase/Figure.h" + +class Pawn : virtual public Figure +{ + bool isFirstMove; +public: + Pawn(bool isWhite); + bool canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const override; + void print() const override; +};
\ No newline at end of file diff --git a/Sem. 15/Chess/Figures/Queen/Queen.cpp b/Sem. 15/Chess/Figures/Queen/Queen.cpp new file mode 100644 index 0000000..da49c1c --- /dev/null +++ b/Sem. 15/Chess/Figures/Queen/Queen.cpp @@ -0,0 +1,18 @@ +#include "Queen.h" + +Queen::Queen(bool isWhite) : Bishop(isWhite), Rook(isWhite), Figure(isWhite) +{} + +bool Queen::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const +{ + return Bishop::canBeMoved(currentX, currentY, destX, destY) + || Rook::canBeMoved(currentX, currentY, destX, destY); +} + +void Queen::print() const +{ + if (getIsWhite()) + std::cout << 'Q'; + else + std::cout << 'q'; +}
\ No newline at end of file diff --git a/Sem. 15/Chess/Figures/Queen/Queen.h b/Sem. 15/Chess/Figures/Queen/Queen.h new file mode 100644 index 0000000..c4fb1da --- /dev/null +++ b/Sem. 15/Chess/Figures/Queen/Queen.h @@ -0,0 +1,11 @@ +#pragma once +#include "../Bishop/Bishop.h" +#include "../Rook/Rook.h" + +class Queen : public Bishop, public Rook +{ +public: + Queen(bool isWhite); + bool canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const; + void print() const; +};
\ No newline at end of file diff --git a/Sem. 15/Chess/Figures/Rook/Rook.cpp b/Sem. 15/Chess/Figures/Rook/Rook.cpp new file mode 100644 index 0000000..19e84a6 --- /dev/null +++ b/Sem. 15/Chess/Figures/Rook/Rook.cpp @@ -0,0 +1,15 @@ +#include "Rook.h" + +Rook::Rook(bool isWhite) : Figure(isWhite) +{} +bool Rook::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const +{ + return currentX == destX || currentY == destY; +} +void Rook::print() const +{ + if (getIsWhite()) + std::cout << 'R'; + else + std::cout << 'r'; +} diff --git a/Sem. 15/Chess/Figures/Rook/Rook.h b/Sem. 15/Chess/Figures/Rook/Rook.h new file mode 100644 index 0000000..f6190a8 --- /dev/null +++ b/Sem. 15/Chess/Figures/Rook/Rook.h @@ -0,0 +1,11 @@ +#pragma once +#include "../FigureBase/Figure.h" + +class Rook : virtual public Figure +{ + +public: + Rook(bool isWhite); + bool canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const override; + void print() const override; +};
\ No newline at end of file |
