Website Summary Files Commits Branches @commit @diff @stats
path: root / Diamond_problem_and_polymorphism
diff options
context:
space:
mode:
Commit0218c678e13e1cb94a352c91733cea68467dc566 (patch)
Author
 Angeld55 <angel_dimitriev@abv.bg>
2021-02-14 23:06:35 +0200
Committer
 Angeld55 <angel_dimitriev@abv.bg>
2021-02-14 23:06:35 +0200
Files16fb3114cb560242458d10411765e50f5d6183db /Diamond_problem_and_polymorphism
Object-oriented_programming_FMI-0218c678e13e1cb94a352c91733cea68467dc566.tar
Object-oriented_programming_FMI-0218c678e13e1cb94a352c91733cea68467dc566.tar.gz
Object-oriented_programming_FMI-0218c678e13e1cb94a352c91733cea68467dc566.zip
Parentd4ae0ef9ec1b54420176c4a88e09f2fd44ae31b0 (diff)
start from scratch
diff --git a/Diamond_problem_and_polymorphism/Chess/Bishop.hpp b/Diamond_problem_and_polymorphism/Chess/Bishop.hpp
deleted file mode 100644
index 014eb48..0000000
--- a/Diamond_problem_and_polymorphism/Chess/Bishop.hpp
+++ /dev/null
@@ -1,34 +0,0 @@
-#pragma once
-#include "Figure.hpp"
-
-class Bishop : virtual public Figure
-{
-public:
- Bishop(int xCoordinate, int yCoordinate, bool isWhite) :Figure(xCoordinate, yCoordinate, isWhite)
- {}
-
- bool Move(int xNew, int yNew);
-
- void Print();
-};
-bool Bishop::Move(int xNew, int yNew)
-{
- if (!isValidCoord(xNew, yNew))
- return false;
- int dx = abs(xCoord - xNew);
- int dy = abs(yCoord - yNew);
- if (dx == dy)
- {
- xCoord = xNew;
- yCoord = yNew;
- return true;
- }
- return false;
-
-
-
-}
-void Bishop::Print()
-{
- cout << 'B';
-} \ No newline at end of file
diff --git a/Diamond_problem_and_polymorphism/Chess/Board.hpp b/Diamond_problem_and_polymorphism/Chess/Board.hpp
deleted file mode 100644
index 95c0f41..0000000
--- a/Diamond_problem_and_polymorphism/Chess/Board.hpp
+++ /dev/null
@@ -1,127 +0,0 @@
-#pragma once
-#include "Figure.hpp"
-#include "Knight.hpp"
-#include "Queen.hpp"
-
-class Board
-{
- Figure*** board;
-
-public:
- Board();
- Board(const Board& other) = delete;
- Board& operator=(const Board& other) = delete;
- ~Board();
- bool isEmptySquare(int x, int y) const;
- bool AddKnight(int x, int y, bool isWhite);
- bool AddQueen(int x, int y, bool isWhite);
- bool AddBishop(int x, int y, bool isWhite);
- bool AddRook(int x, int y, bool isWhite);
-
- void Print();
-
- bool MoveFigure(int xOld, int yOld, int xNew, int yNew);
-
-};
-Board::Board()
-{
- board = new Figure**[8];
- for (int i = 0; i < 8; ++i)
- board[i] = new Figure*[8];
-
- for (int i = 0; i < 8; ++i)
- {
- for (int j = 0; j < 8; j++)
- board[i][j] = nullptr;
- }
-
-}
-
-Board::~Board()
-{
- for (int i = 0; i < 8; ++i)
- {
- for (int j = 0; j < 8; ++j)
- {
- delete board[i][j];
- }
- delete[] board[i];
- }
- delete[] board;
-
-}
-bool Board::isEmptySquare(int x, int y) const
-{
- return board[x][y] == nullptr;
-}
-
-bool Board::AddKnight(int x, int y, bool isWhite)
-{
- if (!isValidCoord(x, y) || !isEmptySquare(x, y))
- return false;
- board[x][y] = new Knight(x, y, isWhite);
- return true;
-}
-bool Board::AddQueen(int x, int y, bool isWhite)
-{
- if (!isValidCoord(x, y) || !isEmptySquare(x, y))
- return false;
- board[x][y] = new Queen(x, y, isWhite);
- return true;
-}
-bool Board::AddBishop(int x, int y, bool isWhite)
-{
- if (!isValidCoord(x, y) || !isEmptySquare(x, y))
- return false;
- board[x][y] = new Bishop(x, y, isWhite);
- return true;
-}
-bool Board::AddRook(int x, int y, bool isWhite)
-{
- if (!isValidCoord(x, y) || !isEmptySquare(x, y))
- return false;
- board[x][y] = new Rook(x, y, isWhite);
- return true;
-}
-
-void Board::Print()
-{
- for (int i = 0; i < 8; ++i)
- {
- for (int j = 0; j < 8; ++j)
- {
- if (!board[i][j])
- cout << '_';
- else
- board[i][j]->Print();
-
- }
- cout << endl;
- }
- cout << endl;
- cout << endl;
-}
-
-bool Board::MoveFigure(int xOld, int yOld, int xNew, int yNew)
-{
- if (isEmptySquare(xOld, yOld)) //Ако няма фигура, там от където искаме да преместим
- return false;
-
- bool res = board[xOld][yOld]->Move(xNew, yNew); //провери дали фигурата може да се премести на съответната прозиция.
- if (!res)// ако не -> лъжа(ходът е невъзможен)
- return false;
-
- if (!isEmptySquare(xNew, yNew))
- {
- if (board[xOld][yOld]->isWhite ^ board[xNew][yNew]->isWhite)// ако там седи фигура от различен цвят
- delete board[xNew][yNew]; //взимаме я(трием обекта)
- else //ако фигурата която седи на новата позиция е от СЪЩИЯ цвят
- {
- board[xOld][yOld]->Move(xOld, yOld); //връщаме обратно кординатите новата фигура. Тук би възникнал проблем, ако имаме фигурата пешка.
- //Това е така, понеже тя няма да може да се върне назад, ако вече е преместена.
- return false; //За това примерно решение е, да се направи функция goBackwards.
- }
- }
- board[xNew][yNew] = board[xOld][yOld];
- board[xOld][yOld] = nullptr;
-} \ No newline at end of file
diff --git a/Diamond_problem_and_polymorphism/Chess/Figure.hpp b/Diamond_problem_and_polymorphism/Chess/Figure.hpp
deleted file mode 100644
index e3fa89d..0000000
--- a/Diamond_problem_and_polymorphism/Chess/Figure.hpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#pragma once
-#include <iostream>
-
-using namespace std;
-
-bool isValidCoord(int xCoord, int yCoord)
-{
- return xCoord >= 0 && xCoord <= 7
- && yCoord >= 0 && yCoord <= 7;
-}
-
-class Figure
-{
-public:
- Figure(int xCoord, int yCoord, bool isWhite);
-
- int xCoord;
- int yCoord;
- bool isWhite;
- virtual bool Move(int xCoord, int yCoord) = 0;
- virtual void Print() = 0;
- virtual ~Figure(){};
-};
-
-Figure::Figure(int xCoord, int yCoord, bool isWhite)
-{
- if (isValidCoord(xCoord, yCoord))
- {
- this->xCoord = xCoord;
- this->yCoord = yCoord;
- this->isWhite = isWhite;
- }
- else
- throw "Ivalid coordinates";
-} \ No newline at end of file
diff --git a/Diamond_problem_and_polymorphism/Chess/Knight.hpp b/Diamond_problem_and_polymorphism/Chess/Knight.hpp
deleted file mode 100644
index 01b9c34..0000000
--- a/Diamond_problem_and_polymorphism/Chess/Knight.hpp
+++ /dev/null
@@ -1,38 +0,0 @@
-#pragma once
-#include "Figure.hpp"
-
-class Knight : public Figure
-{
-public:
- Knight(int xCoordinate, int yCoordinate, bool isWhite) :Figure(xCoordinate, yCoordinate, isWhite)
- {}
-
- bool Move(int xNew, int yNew);
-
- void Print();
-};
-bool Knight::Move(int xNew, int yNew)
-{
- if (!isValidCoord(xNew, yNew))
- return false;
- int possibleX[] = { 1, 1, -1, -1, 2, 2, -2, -2 };
- int possibleY[] = { 2, -2, 2, -2, 1, -1, 1, -1 };
- for (int i = 0; i < 8; ++i)
- {
- if (xNew == xCoord + possibleX[i]
- && yNew == yCoord + possibleY[i])
- {
- xCoord = xNew;
- yCoord = yNew;
- return true;
- }
-
- }
- return false;
-
-}
-
-void Knight::Print()
-{
- cout << 'K';
-} \ No newline at end of file
diff --git a/Diamond_problem_and_polymorphism/Chess/Queen.hpp b/Diamond_problem_and_polymorphism/Chess/Queen.hpp
deleted file mode 100644
index 2f89029..0000000
--- a/Diamond_problem_and_polymorphism/Chess/Queen.hpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#pragma once
-#include "Figure.hpp"
-#include "Bishop.hpp"
-#include "Rook.hpp"
-
-class Queen : public Bishop, public Rook //Формално това НЕ Е ок. Понеже царицата НЕ Е топ и царицата НЕ Е офицер.
-{
-public:
- Queen(int xCoordinate, int yCoordinate, bool isWhite) :Figure(xCoordinate, yCoordinate, isWhite), Bishop(xCoordinate, yCoordinate, isWhite), Rook(xCoordinate, yCoordinate, isWhite)
- {}
- bool Move(int xNew, int yNew);
- void Print();
-};
-
-void Queen::Print()
-{
- cout << 'Q';
-}
-bool Queen::Move(int xNew, int yNew) // Тук сме наследили 2 функционалности. Имаме конфликт, трябва да дефинираме наша(използвайки предишните, ако искаме)
-{
- bool res = Rook::Move(xNew, yNew);//Пробвай да се движиш като топ(по права линия)
- if (res) //Ако е успял - вс е ок
- return true;
- return Bishop::Move(xNew, yNew); //Ако не си успял като топ, пробвай като офицер.
-}
diff --git a/Diamond_problem_and_polymorphism/Chess/README.md b/Diamond_problem_and_polymorphism/Chess/README.md
deleted file mode 100644
index 97ee907..0000000
--- a/Diamond_problem_and_polymorphism/Chess/README.md
+++ /dev/null
@@ -1,4 +0,0 @@
-# Chess
-
-Not a full chess project! Just a prototype.
-
diff --git a/Diamond_problem_and_polymorphism/Chess/Rook.hpp b/Diamond_problem_and_polymorphism/Chess/Rook.hpp
deleted file mode 100644
index 5ad81c8..0000000
--- a/Diamond_problem_and_polymorphism/Chess/Rook.hpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#pragma once
-#include "Figure.hpp"
-
-class Rook : virtual public Figure
-{
-
-public:
- Rook(int xCoordinate, int yCoordinate, bool isWhite) :Figure(xCoordinate, yCoordinate, isWhite)
- {}
-
- bool Move(int xNew, int yNew);
-
- void Print();
-
-};
-
-bool Rook::Move(int xNew, int yNew)
-{
- if (!isValidCoord(xNew, yNew))
- return false;
- if (!(xCoord == xNew ^ yCoord == yNew))
- return false;
- xCoord = xNew;
- yCoord = yNew;
- return true;
-}
-
-void Rook::Print()
-{
- cout << 'R';
-} \ No newline at end of file
diff --git a/Diamond_problem_and_polymorphism/Chess/main.cpp b/Diamond_problem_and_polymorphism/Chess/main.cpp
deleted file mode 100644
index 2caaee8..0000000
--- a/Diamond_problem_and_polymorphism/Chess/main.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <iostream>
-#include "Board.hpp"
-using namespace std;
-
-int main()
-{
- while (1)
- {
- Board b;
- b.AddBishop(3, 4, true);
- b.AddKnight(2, 3, false);
- b.Print();
- b.MoveFigure(3, 4, 2, 3);
- b.Print();
- }
-}
diff --git a/Diamond_problem_and_polymorphism/sd b/Diamond_problem_and_polymorphism/sd
deleted file mode 100644
index 6e9f0da..0000000
--- a/Diamond_problem_and_polymorphism/sd
+++ /dev/null
@@ -1 +0,0 @@
-h