From 9a86536fb579b244b29aa03fbefcce54746546dc Mon Sep 17 00:00:00 2001 From: angeld55 Date: Sat, 12 Jun 2021 19:02:26 +0300 Subject: fixes --- Exams/poll.txt | 1 + Exams/schedule.md | 8 +++ Sem. 15/Chess/ChessBoard/ChessBoard.cpp | 66 --------------------- Sem. 15/Chess/ChessBoard/ChessBoard.h | 43 -------------- Sem. 15/Chess/ConfigEnums/ConfigEnums.h | 11 ---- Sem. 15/Chess/FigureFactory/FigureFactory.cpp | 27 --------- Sem. 15/Chess/FigureFactory/FigureFactory.h | 9 --- Sem. 15/Chess/Figures/Bishop/Bishop.cpp | 16 ----- Sem. 15/Chess/Figures/Bishop/Bishop.h | 13 ---- Sem. 15/Chess/Figures/FigureBase/Figure.cpp | 0 Sem. 15/Chess/Figures/FigureBase/Figure.h | 20 ------- Sem. 15/Chess/Figures/King/King.cpp | 16 ----- Sem. 15/Chess/Figures/King/King.h | 11 ---- Sem. 15/Chess/Figures/Knight/Knight.cpp | 26 -------- Sem. 15/Chess/Figures/Knight/Knight.h | 11 ---- Sem. 15/Chess/Figures/Pawn/Pawn.cpp | 20 ------- Sem. 15/Chess/Figures/Pawn/Pawn.h | 11 ---- Sem. 15/Chess/Figures/Queen/Queen.cpp | 18 ------ Sem. 15/Chess/Figures/Queen/Queen.h | 11 ---- Sem. 15/Chess/Figures/Rook/Rook.cpp | 15 ----- Sem. 15/Chess/Figures/Rook/Rook.h | 11 ---- Sem. 15/Chess/main.cpp | 16 ----- .../ChessBoard/ChessBoard.cpp | 69 ++++++++++++++++++++++ .../Chess_basic_prototype/ChessBoard/ChessBoard.h | 43 ++++++++++++++ .../ConfigEnums/ConfigEnums.h | 11 ++++ .../FigureFactory/FigureFactory.cpp | 27 +++++++++ .../FigureFactory/FigureFactory.h | 9 +++ .../Figures/Bishop/Bishop.cpp | 16 +++++ .../Chess_basic_prototype/Figures/Bishop/Bishop.h | 13 ++++ .../Figures/FigureBase/Figure.cpp | 0 .../Figures/FigureBase/Figure.h | 21 +++++++ .../Chess_basic_prototype/Figures/King/King.cpp | 16 +++++ Sem. 15/Chess_basic_prototype/Figures/King/King.h | 11 ++++ .../Figures/Knight/Knight.cpp | 26 ++++++++ .../Chess_basic_prototype/Figures/Knight/Knight.h | 11 ++++ .../Chess_basic_prototype/Figures/Pawn/Pawn.cpp | 20 +++++++ Sem. 15/Chess_basic_prototype/Figures/Pawn/Pawn.h | 11 ++++ .../Chess_basic_prototype/Figures/Queen/Queen.cpp | 18 ++++++ .../Chess_basic_prototype/Figures/Queen/Queen.h | 11 ++++ .../Chess_basic_prototype/Figures/Rook/Rook.cpp | 15 +++++ Sem. 15/Chess_basic_prototype/Figures/Rook/Rook.h | 11 ++++ Sem. 15/Chess_basic_prototype/main.cpp | 16 +++++ Sem. 16/LogicExpressions/Source.cpp | 6 +- 43 files changed, 387 insertions(+), 374 deletions(-) create mode 100644 Exams/poll.txt create mode 100644 Exams/schedule.md delete mode 100644 Sem. 15/Chess/ChessBoard/ChessBoard.cpp delete mode 100644 Sem. 15/Chess/ChessBoard/ChessBoard.h delete mode 100644 Sem. 15/Chess/ConfigEnums/ConfigEnums.h delete mode 100644 Sem. 15/Chess/FigureFactory/FigureFactory.cpp delete mode 100644 Sem. 15/Chess/FigureFactory/FigureFactory.h delete mode 100644 Sem. 15/Chess/Figures/Bishop/Bishop.cpp delete mode 100644 Sem. 15/Chess/Figures/Bishop/Bishop.h delete mode 100644 Sem. 15/Chess/Figures/FigureBase/Figure.cpp delete mode 100644 Sem. 15/Chess/Figures/FigureBase/Figure.h delete mode 100644 Sem. 15/Chess/Figures/King/King.cpp delete mode 100644 Sem. 15/Chess/Figures/King/King.h delete mode 100644 Sem. 15/Chess/Figures/Knight/Knight.cpp delete mode 100644 Sem. 15/Chess/Figures/Knight/Knight.h delete mode 100644 Sem. 15/Chess/Figures/Pawn/Pawn.cpp delete mode 100644 Sem. 15/Chess/Figures/Pawn/Pawn.h delete mode 100644 Sem. 15/Chess/Figures/Queen/Queen.cpp delete mode 100644 Sem. 15/Chess/Figures/Queen/Queen.h delete mode 100644 Sem. 15/Chess/Figures/Rook/Rook.cpp delete mode 100644 Sem. 15/Chess/Figures/Rook/Rook.h delete mode 100644 Sem. 15/Chess/main.cpp create mode 100644 Sem. 15/Chess_basic_prototype/ChessBoard/ChessBoard.cpp create mode 100644 Sem. 15/Chess_basic_prototype/ChessBoard/ChessBoard.h create mode 100644 Sem. 15/Chess_basic_prototype/ConfigEnums/ConfigEnums.h create mode 100644 Sem. 15/Chess_basic_prototype/FigureFactory/FigureFactory.cpp create mode 100644 Sem. 15/Chess_basic_prototype/FigureFactory/FigureFactory.h create mode 100644 Sem. 15/Chess_basic_prototype/Figures/Bishop/Bishop.cpp create mode 100644 Sem. 15/Chess_basic_prototype/Figures/Bishop/Bishop.h create mode 100644 Sem. 15/Chess_basic_prototype/Figures/FigureBase/Figure.cpp create mode 100644 Sem. 15/Chess_basic_prototype/Figures/FigureBase/Figure.h create mode 100644 Sem. 15/Chess_basic_prototype/Figures/King/King.cpp create mode 100644 Sem. 15/Chess_basic_prototype/Figures/King/King.h create mode 100644 Sem. 15/Chess_basic_prototype/Figures/Knight/Knight.cpp create mode 100644 Sem. 15/Chess_basic_prototype/Figures/Knight/Knight.h create mode 100644 Sem. 15/Chess_basic_prototype/Figures/Pawn/Pawn.cpp create mode 100644 Sem. 15/Chess_basic_prototype/Figures/Pawn/Pawn.h create mode 100644 Sem. 15/Chess_basic_prototype/Figures/Queen/Queen.cpp create mode 100644 Sem. 15/Chess_basic_prototype/Figures/Queen/Queen.h create mode 100644 Sem. 15/Chess_basic_prototype/Figures/Rook/Rook.cpp create mode 100644 Sem. 15/Chess_basic_prototype/Figures/Rook/Rook.h create mode 100644 Sem. 15/Chess_basic_prototype/main.cpp diff --git a/Exams/poll.txt b/Exams/poll.txt new file mode 100644 index 0000000..4ffc75f --- /dev/null +++ b/Exams/poll.txt @@ -0,0 +1 @@ +https://forms.gle/2ciPStWkxz319C8k9 diff --git a/Exams/schedule.md b/Exams/schedule.md new file mode 100644 index 0000000..10f8757 --- /dev/null +++ b/Exams/schedule.md @@ -0,0 +1,8 @@ +Дати: + + - 29.06 + - 01.07 + - 02.07 + +[Анкета за ден за събеседване](https://forms.gle/2ciPStWkxz319C8k9) + diff --git a/Sem. 15/Chess/ChessBoard/ChessBoard.cpp b/Sem. 15/Chess/ChessBoard/ChessBoard.cpp deleted file mode 100644 index 2c618bd..0000000 --- a/Sem. 15/Chess/ChessBoard/ChessBoard.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "ChessBoard.h" -#include "../FigureFactory/FigureFactory.h" - -ChessBoard::ChessBoard() -{ - - for (int i = 0; i < BOARD_SIZE; i++) - { - board[1][i].f = FigureFactory::createFigure(false, PawnFigure); - board[6][i].f = FigureFactory::createFigure(true, PawnFigure); - } - - board[0][0].f = FigureFactory::createFigure(false, RookFigure); - board[0][7].f = FigureFactory::createFigure(false, RookFigure); - - board[7][0].f = FigureFactory::createFigure(true, RookFigure); - board[7][7].f = FigureFactory::createFigure(true, RookFigure); - - - board[0][1].f = FigureFactory::createFigure(false, KnightFigure); - board[0][6].f = FigureFactory::createFigure(false, KnightFigure); - board[7][1].f = FigureFactory::createFigure(true, KnightFigure);; - board[7][6].f = FigureFactory::createFigure(true, KnightFigure); - - board[0][2].f = FigureFactory::createFigure(false, BishopFigure); - board[0][5].f = FigureFactory::createFigure(false, BishopFigure);; - board[7][2].f = FigureFactory::createFigure(true, BishopFigure); - board[7][5].f = FigureFactory::createFigure(true, BishopFigure); - - board[0][3].f = FigureFactory::createFigure(false, KingFigure); - board[0][4].f = FigureFactory::createFigure(false, QueenFigure); - board[7][4].f = FigureFactory::createFigure(true, QueenFigure); - board[7][3].f = FigureFactory::createFigure(true, KingFigure); -} - -void ChessBoard::print() const -{ - for (int i = 0; i < BOARD_SIZE; i++) - { - for (int j = 0; j < BOARD_SIZE; j++) - { - board[i][j].print(); - } - std::cout << std::endl; - } -} - -void ChessBoard::move(size_t x, size_t y, size_t destX, size_t destY) -{ - - Figure* current = board[x][y].f; - - if (current->getType() == PawnFigure) - { - //Some logic..... - } - else - { - if (board[x][y].f && board[x][y].f->canBeMoved(x, y, destX, destY)) - { - board[destX][destY].f = board[x][y].f; - board[x][y].f = nullptr; - } - } - -} \ No newline at end of file diff --git a/Sem. 15/Chess/ChessBoard/ChessBoard.h b/Sem. 15/Chess/ChessBoard/ChessBoard.h deleted file mode 100644 index e38acd5..0000000 --- a/Sem. 15/Chess/ChessBoard/ChessBoard.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once -#include "../Figures/FigureBase/Figure.h" - -const size_t BOARD_SIZE = 8; -class ChessBoard -{ - struct Cell - { - Figure* f = nullptr; - Cell() = default; - - Cell(const Cell& other) = delete; - Cell& operator=(const Cell& other) = delete; - bool isEmpty() - { - return f == nullptr; - } - - void print() const - { - if (f != nullptr) - f->print(); - else - std::cout << ' '; - } - - ~Cell() - { - delete f; - } - }; - Cell board[BOARD_SIZE][BOARD_SIZE]; - -public: - ChessBoard(); - ChessBoard(const ChessBoard& other) = delete; - ChessBoard& operator=(const ChessBoard&) = delete; - - void print() const; - - void move(size_t x, size_t y, size_t destX, size_t destY); - -}; diff --git a/Sem. 15/Chess/ConfigEnums/ConfigEnums.h b/Sem. 15/Chess/ConfigEnums/ConfigEnums.h deleted file mode 100644 index c3448e8..0000000 --- a/Sem. 15/Chess/ConfigEnums/ConfigEnums.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -enum FigureType -{ - KingFigure, - QueenFigure, - KnightFigure, - BishopFigure, - PawnFigure, - RookFigure -}; \ No newline at end of file diff --git a/Sem. 15/Chess/FigureFactory/FigureFactory.cpp b/Sem. 15/Chess/FigureFactory/FigureFactory.cpp deleted file mode 100644 index e9db605..0000000 --- a/Sem. 15/Chess/FigureFactory/FigureFactory.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "FigureFactory.h" -#include "../Figures/Bishop/Bishop.h" -#include "../Figures/King/King.h" -#include "../Figures/Knight/Knight.h" -#include "../Figures/Rook/Rook.h" -#include "../Figures/Queen/Queen.h" -#include "../Figures/Pawn/Pawn.h" - -Figure* FigureFactory::createFigure(bool isWhite, FigureType type) -{ - - switch (type) - { - case KingFigure: - return new King(isWhite); - case QueenFigure: - return new Queen(isWhite); - case KnightFigure: - return new Knight(isWhite); - case BishopFigure: - return new Bishop(isWhite); - case PawnFigure: - return new Pawn(isWhite); - case RookFigure: - return new Rook(isWhite); - } -} \ No newline at end of file diff --git a/Sem. 15/Chess/FigureFactory/FigureFactory.h b/Sem. 15/Chess/FigureFactory/FigureFactory.h deleted file mode 100644 index 012a60c..0000000 --- a/Sem. 15/Chess/FigureFactory/FigureFactory.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include "../Figures/FigureBase/Figure.h" -#include "../ConfigEnums/ConfigEnums.h" - -class FigureFactory -{ -public: - static Figure* createFigure(bool isWhite, FigureType); //enum -}; \ No newline at end of file diff --git a/Sem. 15/Chess/Figures/Bishop/Bishop.cpp b/Sem. 15/Chess/Figures/Bishop/Bishop.cpp deleted file mode 100644 index 786c9eb..0000000 --- a/Sem. 15/Chess/Figures/Bishop/Bishop.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "Bishop.h" -#include - -Bishop::Bishop(bool isWhite) : Figure(isWhite, RookFigure) -{} -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 deleted file mode 100644 index 86949a7..0000000 --- a/Sem. 15/Chess/Figures/Bishop/Bishop.h +++ /dev/null @@ -1,13 +0,0 @@ -#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 deleted file mode 100644 index e69de29..0000000 diff --git a/Sem. 15/Chess/Figures/FigureBase/Figure.h b/Sem. 15/Chess/Figures/FigureBase/Figure.h deleted file mode 100644 index 3e0bc07..0000000 --- a/Sem. 15/Chess/Figures/FigureBase/Figure.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include -#include "../../ConfigEnums/ConfigEnums.h" - -class Figure -{ - bool isWhite; - FigureType type; - -public: - Figure(bool isWhite, FigureType type) :isWhite(isWhite), type(type) - {} - 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; }; - FigureType getType() const { return type; } - - 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 deleted file mode 100644 index 8ca67e8..0000000 --- a/Sem. 15/Chess/Figures/King/King.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "King.h" -#include - -King::King(bool isWhite) : Figure(isWhite, KingFigure) -{} -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 deleted file mode 100644 index 85a8e02..0000000 --- a/Sem. 15/Chess/Figures/King/King.h +++ /dev/null @@ -1,11 +0,0 @@ -#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 deleted file mode 100644 index 5713d7c..0000000 --- a/Sem. 15/Chess/Figures/Knight/Knight.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "Knight.h" -#include - -Knight::Knight(bool isWhite) : Figure(isWhite, KnightFigure) -{} -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 deleted file mode 100644 index 72acfea..0000000 --- a/Sem. 15/Chess/Figures/Knight/Knight.h +++ /dev/null @@ -1,11 +0,0 @@ -#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 deleted file mode 100644 index 347032b..0000000 --- a/Sem. 15/Chess/Figures/Pawn/Pawn.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "Pawn.h" -#include -Pawn::Pawn(bool isWhite) : Figure(isWhite, PawnFigure), isFirstMove(true) -{} - -bool Pawn::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const -{ - if (getIsWhite()) - return currentY - 1 == destY && abs((int)currentX - (int)destX) <= 1; - else - return currentY + 1 == destY && abs((int)currentX - (int)destX) <= 1; -} - -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 deleted file mode 100644 index 675bf0b..0000000 --- a/Sem. 15/Chess/Figures/Pawn/Pawn.h +++ /dev/null @@ -1,11 +0,0 @@ -#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 deleted file mode 100644 index 0e33198..0000000 --- a/Sem. 15/Chess/Figures/Queen/Queen.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "Queen.h" - -Queen::Queen(bool isWhite) : Bishop(isWhite), Rook(isWhite), Figure(isWhite, QueenFigure) -{} - -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 deleted file mode 100644 index c4fb1da..0000000 --- a/Sem. 15/Chess/Figures/Queen/Queen.h +++ /dev/null @@ -1,11 +0,0 @@ -#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 deleted file mode 100644 index 2cb96a3..0000000 --- a/Sem. 15/Chess/Figures/Rook/Rook.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "Rook.h" - -Rook::Rook(bool isWhite) : Figure(isWhite, RookFigure) -{} -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 deleted file mode 100644 index f6190a8..0000000 --- a/Sem. 15/Chess/Figures/Rook/Rook.h +++ /dev/null @@ -1,11 +0,0 @@ -#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 diff --git a/Sem. 15/Chess/main.cpp b/Sem. 15/Chess/main.cpp deleted file mode 100644 index 12ad76d..0000000 --- a/Sem. 15/Chess/main.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include "ChessBoard/ChessBoard.h" -using namespace std; - -//ШАХ - -int main() -{ - ChessBoard c; - - c.print(); - - c.move(0, 1, 2, 0); - - c.print(); -} \ No newline at end of file diff --git a/Sem. 15/Chess_basic_prototype/ChessBoard/ChessBoard.cpp b/Sem. 15/Chess_basic_prototype/ChessBoard/ChessBoard.cpp new file mode 100644 index 0000000..ed9823d --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/ChessBoard/ChessBoard.cpp @@ -0,0 +1,69 @@ +#include "ChessBoard.h" +#include "../FigureFactory/FigureFactory.h" + +ChessBoard::ChessBoard() +{ + + for (int i = 0; i < BOARD_SIZE; i++) + { + board[1][i].f = FigureFactory::createFigure(false, PawnFigure); + board[6][i].f = FigureFactory::createFigure(true, PawnFigure); + } + + board[0][0].f = FigureFactory::createFigure(false, RookFigure); + board[0][7].f = FigureFactory::createFigure(false, RookFigure); + + board[7][0].f = FigureFactory::createFigure(true, RookFigure); + board[7][7].f = FigureFactory::createFigure(true, RookFigure); + + + board[0][1].f = FigureFactory::createFigure(false, KnightFigure); + board[0][6].f = FigureFactory::createFigure(false, KnightFigure); + board[7][1].f = FigureFactory::createFigure(true, KnightFigure);; + board[7][6].f = FigureFactory::createFigure(true, KnightFigure); + + board[0][2].f = FigureFactory::createFigure(false, BishopFigure); + board[0][5].f = FigureFactory::createFigure(false, BishopFigure);; + board[7][2].f = FigureFactory::createFigure(true, BishopFigure); + board[7][5].f = FigureFactory::createFigure(true, BishopFigure); + + board[0][3].f = FigureFactory::createFigure(false, KingFigure); + board[0][4].f = FigureFactory::createFigure(false, QueenFigure); + board[7][4].f = FigureFactory::createFigure(true, QueenFigure); + board[7][3].f = FigureFactory::createFigure(true, KingFigure); +} + +void ChessBoard::print() const +{ + std::cout << "--------" << std::endl; + for (int i = 0; i < BOARD_SIZE; i++) + { + for (int j = 0; j < BOARD_SIZE; j++) + { + board[i][j].print(); + } + std::cout << std::endl; + } + std::cout << "--------" << std::endl << std::endl << std::endl; +} + +void ChessBoard::moveFigure(size_t x, size_t y, size_t destX, size_t destY) +{ + + Figure* current = board[x][y].f; + + if (current->getType() == PawnFigure) + { + //Some other logic..... El'passant and other + } + else + { + if (board[x][y].f && board[x][y].f->canBeMoved(x, y, destX, destY)) + { + delete board[destX][destY].f; + board[destX][destY].f = board[x][y].f; + board[x][y].f = nullptr; + } + } + +} \ No newline at end of file diff --git a/Sem. 15/Chess_basic_prototype/ChessBoard/ChessBoard.h b/Sem. 15/Chess_basic_prototype/ChessBoard/ChessBoard.h new file mode 100644 index 0000000..315e492 --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/ChessBoard/ChessBoard.h @@ -0,0 +1,43 @@ +#pragma once +#include "../Figures/FigureBase/Figure.h" + +const size_t BOARD_SIZE = 8; +class ChessBoard +{ + struct Cell + { + Figure* f = nullptr; + Cell() = default; + + Cell(const Cell& other) = delete; + Cell& operator=(const Cell& other) = delete; + bool isEmpty() + { + return f == nullptr; + } + + void print() const + { + if (f != nullptr) + f->print(); + else + std::cout << ' '; + } + + ~Cell() + { + delete f; + } + }; + Cell board[BOARD_SIZE][BOARD_SIZE]; + +public: + ChessBoard(); + ChessBoard(const ChessBoard& other) = delete; + ChessBoard& operator=(const ChessBoard&) = delete; + + void print() const; + + void moveFigure(size_t x, size_t y, size_t destX, size_t destY); + +}; diff --git a/Sem. 15/Chess_basic_prototype/ConfigEnums/ConfigEnums.h b/Sem. 15/Chess_basic_prototype/ConfigEnums/ConfigEnums.h new file mode 100644 index 0000000..c3448e8 --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/ConfigEnums/ConfigEnums.h @@ -0,0 +1,11 @@ +#pragma once + +enum FigureType +{ + KingFigure, + QueenFigure, + KnightFigure, + BishopFigure, + PawnFigure, + RookFigure +}; \ No newline at end of file diff --git a/Sem. 15/Chess_basic_prototype/FigureFactory/FigureFactory.cpp b/Sem. 15/Chess_basic_prototype/FigureFactory/FigureFactory.cpp new file mode 100644 index 0000000..e9db605 --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/FigureFactory/FigureFactory.cpp @@ -0,0 +1,27 @@ +#include "FigureFactory.h" +#include "../Figures/Bishop/Bishop.h" +#include "../Figures/King/King.h" +#include "../Figures/Knight/Knight.h" +#include "../Figures/Rook/Rook.h" +#include "../Figures/Queen/Queen.h" +#include "../Figures/Pawn/Pawn.h" + +Figure* FigureFactory::createFigure(bool isWhite, FigureType type) +{ + + switch (type) + { + case KingFigure: + return new King(isWhite); + case QueenFigure: + return new Queen(isWhite); + case KnightFigure: + return new Knight(isWhite); + case BishopFigure: + return new Bishop(isWhite); + case PawnFigure: + return new Pawn(isWhite); + case RookFigure: + return new Rook(isWhite); + } +} \ No newline at end of file diff --git a/Sem. 15/Chess_basic_prototype/FigureFactory/FigureFactory.h b/Sem. 15/Chess_basic_prototype/FigureFactory/FigureFactory.h new file mode 100644 index 0000000..012a60c --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/FigureFactory/FigureFactory.h @@ -0,0 +1,9 @@ +#pragma once +#include "../Figures/FigureBase/Figure.h" +#include "../ConfigEnums/ConfigEnums.h" + +class FigureFactory +{ +public: + static Figure* createFigure(bool isWhite, FigureType); //enum +}; \ No newline at end of file diff --git a/Sem. 15/Chess_basic_prototype/Figures/Bishop/Bishop.cpp b/Sem. 15/Chess_basic_prototype/Figures/Bishop/Bishop.cpp new file mode 100644 index 0000000..786c9eb --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/Figures/Bishop/Bishop.cpp @@ -0,0 +1,16 @@ +#include "Bishop.h" +#include + +Bishop::Bishop(bool isWhite) : Figure(isWhite, RookFigure) +{} +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_basic_prototype/Figures/Bishop/Bishop.h b/Sem. 15/Chess_basic_prototype/Figures/Bishop/Bishop.h new file mode 100644 index 0000000..86949a7 --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/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_basic_prototype/Figures/FigureBase/Figure.cpp b/Sem. 15/Chess_basic_prototype/Figures/FigureBase/Figure.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Sem. 15/Chess_basic_prototype/Figures/FigureBase/Figure.h b/Sem. 15/Chess_basic_prototype/Figures/FigureBase/Figure.h new file mode 100644 index 0000000..9e2300a --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/Figures/FigureBase/Figure.h @@ -0,0 +1,21 @@ +#pragma once +#include +#include "../../ConfigEnums/ConfigEnums.h" + +class Figure +{ + bool isWhite; + FigureType type; + +public: + Figure(bool isWhite, FigureType type) :isWhite(isWhite), type(type) + {} + + 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; }; + FigureType getType() const { return type; } + + virtual ~Figure(){}; +}; \ No newline at end of file diff --git a/Sem. 15/Chess_basic_prototype/Figures/King/King.cpp b/Sem. 15/Chess_basic_prototype/Figures/King/King.cpp new file mode 100644 index 0000000..8ca67e8 --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/Figures/King/King.cpp @@ -0,0 +1,16 @@ +#include "King.h" +#include + +King::King(bool isWhite) : Figure(isWhite, KingFigure) +{} +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_basic_prototype/Figures/King/King.h b/Sem. 15/Chess_basic_prototype/Figures/King/King.h new file mode 100644 index 0000000..85a8e02 --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/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_basic_prototype/Figures/Knight/Knight.cpp b/Sem. 15/Chess_basic_prototype/Figures/Knight/Knight.cpp new file mode 100644 index 0000000..5713d7c --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/Figures/Knight/Knight.cpp @@ -0,0 +1,26 @@ +#include "Knight.h" +#include + +Knight::Knight(bool isWhite) : Figure(isWhite, KnightFigure) +{} +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_basic_prototype/Figures/Knight/Knight.h b/Sem. 15/Chess_basic_prototype/Figures/Knight/Knight.h new file mode 100644 index 0000000..72acfea --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/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_basic_prototype/Figures/Pawn/Pawn.cpp b/Sem. 15/Chess_basic_prototype/Figures/Pawn/Pawn.cpp new file mode 100644 index 0000000..347032b --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/Figures/Pawn/Pawn.cpp @@ -0,0 +1,20 @@ +#include "Pawn.h" +#include +Pawn::Pawn(bool isWhite) : Figure(isWhite, PawnFigure), isFirstMove(true) +{} + +bool Pawn::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const +{ + if (getIsWhite()) + return currentY - 1 == destY && abs((int)currentX - (int)destX) <= 1; + else + return currentY + 1 == destY && abs((int)currentX - (int)destX) <= 1; +} + +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_basic_prototype/Figures/Pawn/Pawn.h b/Sem. 15/Chess_basic_prototype/Figures/Pawn/Pawn.h new file mode 100644 index 0000000..675bf0b --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/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_basic_prototype/Figures/Queen/Queen.cpp b/Sem. 15/Chess_basic_prototype/Figures/Queen/Queen.cpp new file mode 100644 index 0000000..0e33198 --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/Figures/Queen/Queen.cpp @@ -0,0 +1,18 @@ +#include "Queen.h" + +Queen::Queen(bool isWhite) : Bishop(isWhite), Rook(isWhite), Figure(isWhite, QueenFigure) +{} + +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_basic_prototype/Figures/Queen/Queen.h b/Sem. 15/Chess_basic_prototype/Figures/Queen/Queen.h new file mode 100644 index 0000000..c4fb1da --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/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_basic_prototype/Figures/Rook/Rook.cpp b/Sem. 15/Chess_basic_prototype/Figures/Rook/Rook.cpp new file mode 100644 index 0000000..2cb96a3 --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/Figures/Rook/Rook.cpp @@ -0,0 +1,15 @@ +#include "Rook.h" + +Rook::Rook(bool isWhite) : Figure(isWhite, RookFigure) +{} +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_basic_prototype/Figures/Rook/Rook.h b/Sem. 15/Chess_basic_prototype/Figures/Rook/Rook.h new file mode 100644 index 0000000..f6190a8 --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/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 diff --git a/Sem. 15/Chess_basic_prototype/main.cpp b/Sem. 15/Chess_basic_prototype/main.cpp new file mode 100644 index 0000000..6673ec8 --- /dev/null +++ b/Sem. 15/Chess_basic_prototype/main.cpp @@ -0,0 +1,16 @@ +#include +#include "ChessBoard/ChessBoard.h" +using namespace std; + +//ШАХ + +int main() +{ + ChessBoard c; + + c.print(); + + c.moveFigure(0, 1, 2, 0); + + c.print(); +} \ No newline at end of file diff --git a/Sem. 16/LogicExpressions/Source.cpp b/Sem. 16/LogicExpressions/Source.cpp index 2b810b8..af86b62 100644 --- a/Sem. 16/LogicExpressions/Source.cpp +++ b/Sem. 16/LogicExpressions/Source.cpp @@ -2,14 +2,14 @@ using namespace LogicExpressions; - +// or |, and ^, negation !, implies >, iff - int main() { - LogicExpr* expr = new Operation(new Var('p'), '|', new Negation(new Var('p'))); // p & !p + LogicExpr* expr = new Operation(new Var('p'), '|', new Negation(new Var('p'))); // p | !p expr->print(); cout << " " << isTautology(expr, { 'p' }) << endl; LogicExpr* expr2 = new Operation(new Var('q'),'^',new Operation(new Var('p'), '^', new Negation(new Var('p')))); // q ^ (p ^ !p) expr2->print(); - cout << " " << isContradiction(expr2, { 'p', 'q' }); + cout << " " << isContradiction(expr2, { 'p', 'q' }) << endl; } \ No newline at end of file -- cgit v1.3.1-23-gd82d