diff --git a/.gitignore b/.gitignore index 259148f..687f936 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ *.exe *.out *.app + +.vscode \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/UML/UML.png b/Flat+Polukhin_and_Liaskovskiy/UML/UML.png new file mode 100644 index 0000000..11e4d13 Binary files /dev/null and b/Flat+Polukhin_and_Liaskovskiy/UML/UML.png differ diff --git a/Flat+Polukhin_and_Liaskovskiy/UML/UML.puml b/Flat+Polukhin_and_Liaskovskiy/UML/UML.puml new file mode 100644 index 0000000..d492573 --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/UML/UML.puml @@ -0,0 +1,238 @@ +@startuml + + + + + +/' Objects '/ + +class Action { + +Action() + +Action(double distance, double angle) + +~Action() + +GetAngle() : double + +GetDistance() : double + -angle : double + -distance : double +} + + +class Apartment { + +Apartment() + +~Apartment() + +GetDoor(unsigned int i) : Door + +GetWall(unsigned int i) : Wall + +isCorrect() : bool + +GetDoors() : std::vector + -doors : std::vector + +GetWalls() : std::vector + -walls : std::vector + +GetDoorsCount() : unsigned int + +GetWallsCount() : unsigned int +} + + +class Door { + +Door() + +~Door() + +GetP1() : Point + +GetP2() : Point + -p1 : Point + -p2 : Point +} + + +class Flat { + +Flat() + +~Flat() + +GetApartment(unsigned int i) : Apartment + +isComplete() : bool + +GetApartments() : std::vector + -apartments : std::vector + +GetHallsCount() : unsigned int + +GetRoomsCount() : unsigned int + -hallsCount : unsigned int + -roomsCount : unsigned int +} + + +class Furniture { + +Furniture() + +~Furniture() + +GetPoints() : std::vector + -points : std::vector +} + + +class Hall { + +Hall() + +~Hall() +} + + +class Point { + +Point() + +Point(double x, double y) + +~Point() + +GetX() : double + +GetY() : double + -x : double + -y : double +} + + +class Robot { + +Robot() + +Robot(Point start, unsigned int max_stamina, Flat* flat, Target* target) + +~Robot() + -flat : Flat* + -CenterOfMass() : Point + -position : Point + -target : Target* + -way : Way + -DistancePP(Point p1, Point p2) : double + -DistancePP(double x1, double y1, double x2, double y2) : double + -GetCos(Point p) : double + -GetTan(Point p) : double + -angle : double + -sumOfMassX : double + -sumOfMassY : double + -SignedTriangleArea(Point p1, Point p2, Point p3) : int + -NextAction() : std::pair + -Cross() : std::pair > + +GetCurrentApartmentId() : unsigned int + -max_stamina : unsigned int + -stamina : unsigned int + +Start() : void +} + + +class Room { + +Room() + +~Room() + +GetFurniture(unsigned int i) : Furniture + +GetFurnitures() : std::vector + -furnitures : std::vector + +GetFurnitureCount() : unsigned int +} + + +class Target { + +Target() + +Target(Point point) + +Target(unsigned int apartment) + +~Target() + +GetPoint() : Point + -point : Point + +GetType() : TargetType + -targetType : TargetType + +GetApartmentID() : unsigned int + -apartment : unsigned int +} + + +class Task { + +Task() + +~Task() + -flat : Flat + -target : Target + -robots : std::vector + -results : std::vector + +GetAverageScore() : unsigned int + +DoTest() : void +} + + +class Wall { + +Wall() + +~Wall() + +GetP1() : Point + +GetP2() : Point + -p1 : Point + -p2 : Point +} + + +class Way { + +Way() + +~Way() + +GetAction(unsigned int i) : Action + +GetActions() : std::vector + -actions : std::vector + +AddAction(Action action) : void +} + + +enum TargetType { + APARTMENT + POINT +} + + + + + +/' Inheritance relationships '/ + +Apartment <|-- Hall + + +Apartment <|-- Room + + + + + +/' Aggregation relationships '/ + +Apartment o-- Door + + +Apartment o-- Wall + + +Door "2" o-- Point + + +Flat o-- Apartment + + +Furniture o-- Point + + +Robot o-- Flat + + +Robot o-- Point + + +Robot o-- Target + + +Robot o-- Way + + +Room o-- Furniture + + +Target o-- Point + + +Task o-- Flat + + +Task o-- Robot + + +Task o-- Target + + +Wall "2" o-- Point + + +Way o-- Action + + + + +@enduml diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Action.cpp b/Flat+Polukhin_and_Liaskovskiy/src/Action.cpp new file mode 100644 index 0000000..e094ac1 --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Action.cpp @@ -0,0 +1,24 @@ +#include "Action.hpp" + +Action::Action(){ + this->distance = 0; + this->angle = 0; +} + +Action::Action(double distance, double angle) +{ + this->distance = distance; + this->angle = angle; +} + +Action::~Action() +{ +} + +double Action::GetDistance(){ + return this->distance; +} + +double Action::GetAngle(){ + return this->angle; +} \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Action.hpp b/Flat+Polukhin_and_Liaskovskiy/src/Action.hpp new file mode 100644 index 0000000..221d191 --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Action.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "common.hpp" + +class Action +{ +private: + double distance, angle; + +public: + Action(); + Action(double distance, double angle); + ~Action(); + double GetDistance(); + double GetAngle(); +}; \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Apartment.cpp b/Flat+Polukhin_and_Liaskovskiy/src/Apartment.cpp new file mode 100644 index 0000000..6241ddd --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Apartment.cpp @@ -0,0 +1,63 @@ +#include "Apartment.hpp" + +#include + +Apartment::Apartment() +{ + uint wallsCount, doorsCount; + + std::cout << "Number of walls:\n"; + std::cin >> wallsCount; + + for (size_t i = 0; i < wallsCount; i++) + { + Wall wall = Wall(); + walls.push_back(wall); + } + + std::cout << "Number of doors:\n"; + std::cin >> doorsCount; + + for (size_t i = 0; i < doorsCount; i++) + { + Door door = Door(); + doors.push_back(door); + } +} + +Apartment::~Apartment() +{ +} + +Wall Apartment::GetWall(uint i) +{ + return this->walls[i]; +} + +Door Apartment::GetDoor(uint i) +{ + return this->doors[i]; +} + +uint Apartment::GetWallsCount(){ + return this->walls.size(); +} + +uint Apartment::GetDoorsCount(){ + return this->doors.size(); +} + +std::vector Apartment::GetWalls() +{ + return this->walls; +} + +std::vector Apartment::GetDoors() +{ + return this->doors; +} + +bool Apartment::isCorrect() +{ + return true; +} \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Apartment.hpp b/Flat+Polukhin_and_Liaskovskiy/src/Apartment.hpp new file mode 100644 index 0000000..626e4d6 --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Apartment.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +#include "common.hpp" +#include "Wall.hpp" +#include "Door.hpp" + +class Apartment +{ +private: + std::vector walls; + std::vector doors; + +public: + Apartment(); + ~Apartment(); + Wall GetWall(uint i); + Door GetDoor(uint i); + uint GetWallsCount(); + uint GetDoorsCount(); + std::vector GetWalls(); + std::vector GetDoors(); + virtual bool isCorrect(); +}; \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Door.cpp b/Flat+Polukhin_and_Liaskovskiy/src/Door.cpp new file mode 100644 index 0000000..7fb3d56 --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Door.cpp @@ -0,0 +1,30 @@ +#include "Door.hpp" +#include "Point.hpp" + +#include + +Door::Door() +{ + double x1, y1, x2, y2; + std::cout << "\nDoor:\n"; + std::cout << "Input x1 y1:\n"; + std::cin >> x1 >> y1; + std::cout << "Input x2 y2:\n"; + std::cin >> x2 >> y2; + this->p1 = Point(x1, y1); + this->p2 = Point(x2, y2); +} + +Door::~Door() +{ +} + +Point Door::GetP1() +{ + return this->p1; +} + +Point Door::GetP2() +{ + return this->p2; +} \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Door.hpp b/Flat+Polukhin_and_Liaskovskiy/src/Door.hpp new file mode 100644 index 0000000..07991bc --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Door.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "common.hpp" +#include "Point.hpp" + +class Door +{ +private: + Point p1, p2; + +public: + Door(); + ~Door(); + Point GetP1(); + Point GetP2(); +}; \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Flat.cpp b/Flat+Polukhin_and_Liaskovskiy/src/Flat.cpp new file mode 100644 index 0000000..0c806d4 --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Flat.cpp @@ -0,0 +1,49 @@ +#include "Flat.hpp" +#include "Room.hpp" +#include "Hall.hpp" + +Flat::Flat() +{ + std::cout << "Number of rooms:\n"; + std::cin >> roomsCount; + for (size_t i = 0; i < roomsCount; i++) + { + Room room = Room(); + this->apartments.push_back(room); + } + + std::cout << "Number of halls:\n"; + std::cin >> hallsCount; + for (size_t i = 0; i < hallsCount; i++) + { + Hall hall = Hall(); + this->apartments.push_back(hall); + } +} + +Flat::~Flat() +{ +} + +uint Flat::GetRoomsCount(){ + return this->roomsCount; +} + +uint Flat::GetHallsCount(){ + return this->hallsCount; +} + +Apartment Flat::GetApartment(uint i) +{ + return this->apartments[i]; +} + +std::vector Flat::GetApartments() +{ + return this->apartments; +} + +bool Flat::isComplete() +{ + return true; +} \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Flat.hpp b/Flat+Polukhin_and_Liaskovskiy/src/Flat.hpp new file mode 100644 index 0000000..d9382d4 --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Flat.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +#include "common.hpp" +#include "Apartment.hpp" + +class Flat +{ +private: + uint roomsCount, hallsCount; + std::vector apartments; + +public: + Flat(); + ~Flat(); + uint GetRoomsCount(); + uint GetHallsCount(); + Apartment GetApartment(uint i); + std::vector GetApartments(); + bool isComplete(); +}; \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Furniture.cpp b/Flat+Polukhin_and_Liaskovskiy/src/Furniture.cpp new file mode 100644 index 0000000..b02751e --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Furniture.cpp @@ -0,0 +1,28 @@ +#include "Furniture.hpp" + +#include + +Furniture::Furniture() +{ + uint pointsCount; + double x, y; + + std::cout << "\nFurniture:"; + for (size_t i = 0; i < pointsCount; i++) + { + std::cout << "\nPoint " << i << ":\n"; + std::cout << "Input x y:\n"; + std::cin >> x >> y; + Point point = Point(x, y); + this->points.push_back(point); + } +} + +Furniture::~Furniture() +{ +} + +std::vector Furniture::GetPoints() +{ + return this->points; +} \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Furniture.hpp b/Flat+Polukhin_and_Liaskovskiy/src/Furniture.hpp new file mode 100644 index 0000000..15f3d1e --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Furniture.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include "vector" + +#include "common.hpp" +#include "Point.hpp" + +class Furniture +{ +private: + std::vector points; + +public: + Furniture(); + ~Furniture(); + std::vector GetPoints(); +}; diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Hall.cpp b/Flat+Polukhin_and_Liaskovskiy/src/Hall.cpp new file mode 100644 index 0000000..9bf5f74 --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Hall.cpp @@ -0,0 +1,6 @@ +#include "Hall.hpp" +#include "Apartment.hpp" + +Hall::Hall() : Apartment::Apartment() {} + +Hall::~Hall() {} \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Hall.hpp b/Flat+Polukhin_and_Liaskovskiy/src/Hall.hpp new file mode 100644 index 0000000..15cd2af --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Hall.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "common.hpp" +#include "Apartment.hpp" + +class Hall : public Apartment +{ +public: + Hall(); + ~Hall(); +}; \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Point.cpp b/Flat+Polukhin_and_Liaskovskiy/src/Point.cpp new file mode 100644 index 0000000..c92d9df --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Point.cpp @@ -0,0 +1,18 @@ +#include "Point.hpp" + +Point::Point() +{ +} + +Point::Point(double x, double y) +{ + this->x = x; + this->y = y; +} + +Point::~Point() +{ +} + +double Point::GetX() { return this->x; } +double Point::GetY() { return this->y; } diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Point.hpp b/Flat+Polukhin_and_Liaskovskiy/src/Point.hpp new file mode 100644 index 0000000..a9cc748 --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Point.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "common.hpp" + +class Point +{ +private: + double x, y; + +public: + Point(); + Point(double x, double y); + ~Point(); + double GetX(); + double GetY(); +}; diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Robot.cpp b/Flat+Polukhin_and_Liaskovskiy/src/Robot.cpp new file mode 100644 index 0000000..b5ae7de --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Robot.cpp @@ -0,0 +1,214 @@ +#include +#include +#include + +#include "Robot.hpp" +#include "Point.hpp" + +Robot::Robot() +{ +} + +Robot::~Robot() +{ +} + +void Robot::Start() +{ + int process = 4; + std::cout << "Start!\n"; + while(process >= 0) + { + process = this->NextAction().first; + } + std::cout << this->max_stamina - this->stamina << std::endl; +} + +std::pair Robot::NextAction() +{ + std::cout << "NextAction!\n"; + std::cout << this->angle << ' ' << this->position.GetX() << ' ' << this->position.GetY() << std::endl; + this->sumOfMassX += this->position.GetX(); + this->sumOfMassY += this->position.GetY(); + this->stamina -= 1; + std::pair> rez = Cross(); + uint rN = rand() % rez.second.size(); + std::cout << rez.first << std::endl; + this->angle = atan(GetCos(rez.second[rN])); + this->position = rez.second[rN]; + std::cout << this->angle << ' ' << this->position.GetX() << ' ' << this->position.GetY() << std::endl; + if(!(this->angle >= -4)) + return std::make_pair(-3, Action(rez.first, this->angle)); + return std::make_pair(rez.first, Action(rez.first, this->angle)); +} + +double Robot::GetCos(Point p) +{ + double tangle = this->angle; + Point rP = this->position; + return ((p.GetX() - rP.GetX()) * cos(tangle) + (p.GetY() - rP.GetY()) * sin(tangle)) / DistancePP(p, rP); +} + +double Robot::GetTan(Point p) +{ + return (p.GetY() - this->position.GetY())/(p.GetX() - this->position.GetX()); +} + +int Robot::SignedTriangleArea(Point p1, Point p2, Point p3) +{ + return (p2.GetX() - p1.GetX()) * (p3.GetY() - p1.GetY()) - (p2.GetY() - p1.GetY()) * (p3.GetX() - p1.GetX()); +} + +uint Robot::GetCurrentApartmentId() +{ + for (int _r = 0; _r < this->flat->GetRoomsCount() + this->flat->GetHallsCount(); ++_r) + { + Apartment tempAp = this->flat->GetApartment(_r); + bool can_be_current_apartment = true; + + for (int _d = 0; _d < tempAp.GetDoorsCount(); ++_d) + { + Door door = tempAp.GetDoor(_d); + if (SignedTriangleArea(this->position, door.GetP1(), door.GetP2()) <= 0) + can_be_current_apartment = false; + } + + for (int _w = 0; _w < tempAp.GetWallsCount(); ++_w) + { + Wall wall = tempAp.GetWall(_w); + if (SignedTriangleArea(this->position, wall.GetP1(), wall.GetP2()) <= 0) + can_be_current_apartment = false; + } + + if (can_be_current_apartment) + return _r; + } + + throw std::runtime_error("Cant fing current apartment"); +} + +std::pair> Robot::Cross() +{ + double maxDist = -1; + double _xmax = 0; + double _ymax = 0; + for (double t = -M_PI; t < 0; t += d_eps * 0.005) + { + double K = tan(t); + //std::cerr << "Angle:" << t << '\n'; + //Перевірка на завершення + + //Перевірка на завершення + if (this->target->GetType() == APARTMENT) + { + std::cout << "APARTMENT!!!\n"; + if (this->GetCurrentApartmentId() == this->target->GetApartmentID()) + { + return std::make_pair(-4, std::vector()); + } + } + + + double posD = 10000, negD = 10000, posx=this->position.GetX(), posy=this->position.GetY(), negx=this->position.GetX(), negy=this->position.GetY(); + for (int _r = 0; _r < this->flat->GetRoomsCount() + this->flat->GetHallsCount(); ++_r) + { + //std::cerr << " Room #:" << _r << '\n'; + for (int _w = 0; _w < this->flat->GetApartment(_r).GetWallsCount(); ++_w) + { + //std::cerr << " Wall #:" << _w << '\n'; + Wall twall = this->flat->GetApartment(_r).GetWall(_w); + + double tWallX1 = twall.GetP1().GetX(); + double tWallY1 = twall.GetP1().GetY(); + double tWallX2 = twall.GetP2().GetX(); + double tWallY2 = twall.GetP2().GetY(); + + //std::cerr << "Room: " << _r << " Wall: " << _w << " " << tWallX1 << " " << tWallY1 << " " << tWallX2 << ' ' << tWallY2 << std::endl; + + for (double _x = MIN(tWallX1, tWallX2); _x <= MAX(tWallX1, tWallX2); _x += d_eps) + { + double _y = K * (_x - this->position.GetX()) + this->position.GetY(); + //std::cerr << "{ " << _x << " | " << _y << " }; "; + if (abs((_x - tWallX1) / (tWallX2 - tWallX1) * (tWallY2 - tWallY1) + tWallY1 - _y) <= d_eps * d_eps) + { + if(_y >= this->position.GetY()) + { + double _posD = DistancePP(this->position, Point(_x, _y)); + if(_posD < posD) + { + posD = _posD; + posx = _x; + posy = _y; + } + } + else + { + double _negD = DistancePP(this->position, Point(_x, _y)); + if(_negD < negD) + { + negD = _negD; + negx = _x; + negy = _y; + } + } + } + } + //std::cerr << "PosD: " << posD << " " << posx << " " << posy << std::endl; + //std::cerr << "NegD: " << negD << " " << negx << " " << negy << std::endl; + std::cerr << std::endl; + } + } + double _tDist = DistancePP(this->CenterOfMass(), Point(posx, posy)); + if (_tDist > maxDist) + { + maxDist = _tDist; + _xmax = posx; + _ymax = posy; + } + //std::cout << "Pos: " << _tDist << " " << posx << " " << posy << std::endl; + _tDist = DistancePP(this->CenterOfMass(), Point(negx, negy)); + if (_tDist > maxDist) + { + maxDist = _tDist; + _xmax = negx; + _ymax = negy; + } + //std::cout << "Neg: " << _tDist << " " << negx << " " << negx << std::endl; + } + + if(isnan(this->angle)) + return std::make_pair(-3, std::vector()); + + std::cout << isnan(this->angle); + std::vector rezVec; + std::cout << _xmax << " " << _ymax << std::endl; + rezVec.push_back(Point(_xmax, _ymax)); + return std::make_pair(maxDist, rezVec); +} + +Robot::Robot(Point start, uint max_stamina, Flat *flat, Target *target) +{ + this->position = start; + this->angle = 0; + this->max_stamina = max_stamina; + this->stamina = max_stamina; + this->flat = flat; + this->target = target; + this->sumOfMassX = 0; + this->sumOfMassY = 0; +} + +double Robot::DistancePP(Point p1, Point p2) +{ + return sqrt(pow(p1.GetX() - p2.GetX(), 2) + pow(p1.GetY() - p2.GetY(), 2)); +} + +double Robot::DistancePP(double x1, double y1, double x2, double y2) +{ + return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)); +} + +Point Robot::CenterOfMass() +{ + return Point(sumOfMassX / (max_stamina - stamina), sumOfMassY / (max_stamina - stamina)); +} \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Robot.hpp b/Flat+Polukhin_and_Liaskovskiy/src/Robot.hpp new file mode 100644 index 0000000..3dd698d --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Robot.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include + +#include "common.hpp" +#include "Point.hpp" +#include "Way.hpp" +#include "Apartment.hpp" +#include "Flat.hpp" +#include "Target.hpp" + + +class Robot +{ +private: + uint stamina, max_stamina; + Point position; + double angle, sumOfMassX, sumOfMassY; + Way way; + Flat *flat; + Target *target; + double DistancePP(Point p1, Point p2); + double DistancePP(double x1, double y1, double x2, double y2); + double GetCos(Point p); + double GetTan(Point p); + Point CenterOfMass(); + int SignedTriangleArea(Point p1, Point p2, Point p3); + std::pair > Cross(); + std::pair NextAction(); + +public: + Robot(); + Robot(Point start, uint max_stamina, Flat *flat, Target *target); + void Start(); + ~Robot(); + uint GetCurrentApartmentId(); +}; diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Room.cpp b/Flat+Polukhin_and_Liaskovskiy/src/Room.cpp new file mode 100644 index 0000000..503b07a --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Room.cpp @@ -0,0 +1,35 @@ +#include "Room.hpp" +#include "Apartment.hpp" +#include "Furniture.hpp" + +Room::Room() : Apartment::Apartment() +{ + uint furnitureCount; + + std::cout << "Number of furnitures:\n"; + std::cin >> furnitureCount; + + for (size_t i = 0; i < furnitureCount; i++) + { + Furniture furniture = Furniture(); + this->furnitures.push_back(furniture); + } +} + +Room::~Room() +{ +} + +Furniture Room::GetFurniture(uint i) +{ + return this->furnitures[i]; +} + +std::vector Room::GetFurnitures() +{ + return this->furnitures; +} + +uint Room::GetFurnitureCount(){ + return this->furnitures.size(); +} \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Room.hpp b/Flat+Polukhin_and_Liaskovskiy/src/Room.hpp new file mode 100644 index 0000000..c3da87a --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Room.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include + +#include "common.hpp" +#include "Apartment.hpp" +#include "Furniture.hpp" + +class Room : public Apartment +{ +private: + std::vector furnitures; + +public: + Room(); + ~Room(); + Furniture GetFurniture(uint i); + std::vector GetFurnitures(); + uint GetFurnitureCount(); +}; \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Target.cpp b/Flat+Polukhin_and_Liaskovskiy/src/Target.cpp new file mode 100644 index 0000000..aec03f5 --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Target.cpp @@ -0,0 +1,37 @@ +#include "Target.hpp" +#include "Point.hpp" + +Target::Target() +{ +} + +Target::Target(Point point) +{ + this->point = point; + this->targetType = POINT; +} + +Target::Target(uint apartment) +{ + this->apartment = apartment; + this->targetType = APARTMENT; +} + +Target::~Target() +{ +} + +TargetType Target::GetType() +{ + return this->targetType; +} + +uint Target::GetApartmentID() +{ + return this->apartment; +} + +Point Target::GetPoint() +{ + return this->point; +} \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Target.hpp b/Flat+Polukhin_and_Liaskovskiy/src/Target.hpp new file mode 100644 index 0000000..19354e3 --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Target.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include "common.hpp" +#include "Point.hpp" +#include "Apartment.hpp" + +#include + +class Target +{ +private: + Point point; + uint apartment; + TargetType targetType; + +public: + Target(); + Target(Point point); + Target(uint apartment); + ~Target(); + TargetType GetType(); + uint GetApartmentID(); + Point GetPoint(); +}; \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Task.cpp b/Flat+Polukhin_and_Liaskovskiy/src/Task.cpp new file mode 100644 index 0000000..82ca51b --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Task.cpp @@ -0,0 +1,50 @@ +#include "Task.hpp" +#include "Point.hpp" + +Task::~Task() +{ +} + +Task::Task() +{ + std::cout << "\nInput start position x y:\n"; + double x, y; + std::cin >> x >> y; + Point start = Point(x, y); + + std::cout << "\nInput stamina (how many times robot can do action):\n"; + uint stamina; + std::cin >> stamina; + + std::cout << "\nInput number of tests:\n"; + uint testsCount; + std::cin >> testsCount; + + for (size_t i = 0; i < testsCount; i++) + { + Robot robot = Robot(start, stamina, &(this->flat), &(this->target)); + this->robots.push_back(robot); + } +} + +uint Task::GetAverageScore() +{ + uint averageScore = 0; + + for (size_t i = 0; i < this->results.size(); i++) + { + averageScore += results[i]; + } + + averageScore /= results.size(); + + return averageScore; +} + +void Task::DoTest() +{ + for(uint _i = 0; _i < robots.size(); ++_i) + { + robots[_i].Start(); + } +} \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Task.hpp b/Flat+Polukhin_and_Liaskovskiy/src/Task.hpp new file mode 100644 index 0000000..b6129e2 --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Task.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +#include "common.hpp" +#include "Robot.hpp" +#include "Flat.hpp" +#include "Target.hpp" + +class Task +{ +private: + Flat flat; + Target target; + std::vector robots; + std::vector results; + +public: + Task(); + ~Task(); + void DoTest(); + uint GetAverageScore(); +}; \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Wall.cpp b/Flat+Polukhin_and_Liaskovskiy/src/Wall.cpp new file mode 100644 index 0000000..71070e5 --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Wall.cpp @@ -0,0 +1,29 @@ +#include "Wall.hpp" + +#include + +Wall::Wall() +{ + double x1, y1, x2, y2; + std::cout << "\nWall:\n"; + std::cout << "Input x1 y1:\n"; + std::cin >> x1 >> y1; + std::cout << "\nInput x2 y2:\n"; + std::cin >> x2 >> y2; + this->p1 = Point(x1, y1); + this->p2 = Point(x2, y2); +} + +Wall::~Wall() +{ +} + +Point Wall::GetP1() +{ + return this->p1; +} + +Point Wall::GetP2() +{ + return this->p2; +} \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Wall.hpp b/Flat+Polukhin_and_Liaskovskiy/src/Wall.hpp new file mode 100644 index 0000000..ce8dd07 --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Wall.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "common.hpp" +#include "Point.hpp" + +class Wall +{ +private: + Point p1, p2; + +public: + Wall(); + ~Wall(); + Point GetP1(); + Point GetP2(); +}; \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Way.cpp b/Flat+Polukhin_and_Liaskovskiy/src/Way.cpp new file mode 100644 index 0000000..2fc099e --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Way.cpp @@ -0,0 +1,26 @@ +#include "Way.hpp" + +#include + +Way::Way() +{ +} + +Way::~Way() +{ +} + +std::vector Way::GetActions() +{ + return this->actions; +} + +Action Way::GetAction(uint i) +{ + return this->actions[i]; +} + +void Way::AddAction(Action action) +{ + this->actions.push_back(action); +} \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/Way.hpp b/Flat+Polukhin_and_Liaskovskiy/src/Way.hpp new file mode 100644 index 0000000..b10e0f2 --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/Way.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +#include "common.hpp" +#include "Action.hpp" + +class Way +{ +private: + std::vector actions; + +public: + Way(); + ~Way(); + Action GetAction(uint i); + std::vector GetActions(); + void AddAction(Action action); +}; \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/src/common.hpp b/Flat+Polukhin_and_Liaskovskiy/src/common.hpp new file mode 100644 index 0000000..bae69be --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/src/common.hpp @@ -0,0 +1,11 @@ +#pragma once + +#define d_eps 0.001 +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) + +enum TargetType +{ + POINT, + APARTMENT +}; \ No newline at end of file diff --git a/Flat+Polukhin_and_Liaskovskiy/tests/Flat_output.txt b/Flat+Polukhin_and_Liaskovskiy/tests/Flat_output.txt new file mode 100644 index 0000000..e69de29 diff --git a/Flat+Polukhin_and_Liaskovskiy/tests/Flat_test.cpp b/Flat+Polukhin_and_Liaskovskiy/tests/Flat_test.cpp new file mode 100644 index 0000000..d720a8f --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/tests/Flat_test.cpp @@ -0,0 +1,10 @@ +#include +#include "../src/Task.hpp" + +using namespace std; + +int main() +{ + Task task = Task(); + task.DoTest(); +} diff --git a/Flat+Polukhin_and_Liaskovskiy/tests/Flat_test.dat b/Flat+Polukhin_and_Liaskovskiy/tests/Flat_test.dat new file mode 100644 index 0000000..e69de29 diff --git a/Flat+Polukhin_and_Liaskovskiy/tests/Flat_test.txt b/Flat+Polukhin_and_Liaskovskiy/tests/Flat_test.txt new file mode 100644 index 0000000..e69de29 diff --git a/Flat+Polukhin_and_Liaskovskiy/tests/Makefile b/Flat+Polukhin_and_Liaskovskiy/tests/Makefile new file mode 100644 index 0000000..4ba2bb3 --- /dev/null +++ b/Flat+Polukhin_and_Liaskovskiy/tests/Makefile @@ -0,0 +1,19 @@ +.PHONY: all clean +CC = g++ +CPPFLAGS = -c -Wall +OBJECTS = Action.o Apartment.o Door.o Flat.o Furniture.o Hall.o Point.o Robot.o Room.o Target.o Task.o Wall.o Way.o + +all: Flat_test + +clean: + rm -rf Flat_test *.o + +Flat_test: Flat_test.o $(OBJECTS) + $(CC) -o Flat_test Flat_test.o $(OBJECTS) + +Flat_test.o: Flat_test.cpp + $(CC) $(CPPFLAGS) -o Flat_test.o Flat_test.cpp + +$(OBJECTS): +%.o: ../src/%.cpp + $(CC) -c $(CFLAGS) $< -o $@ \ No newline at end of file