From e8b8810e9f2fbc1e374158661219052e9b34faac Mon Sep 17 00:00:00 2001 From: jo-anne Date: Wed, 4 Nov 2020 11:26:15 +0200 Subject: [PATCH 01/13] feat: destructor perfected and racingDep made to work for current stage --- src/log/Colleague.cpp | 4 +- src/log/Colleague.h | 2 +- src/log/Logistics.cpp | 68 ++++++++++++++++++--- src/log/Logistics.h | 4 +- src/log/Mediator.h | 2 +- src/log/transportation/Fly.cpp | 4 ++ src/log/transportation/Fly.h | 1 + src/log/transportation/Road.cpp | 4 ++ src/log/transportation/Road.h | 1 + src/log/transportation/Ship.cpp | 4 ++ src/log/transportation/Ship.h | 1 + src/log/transportation/TransportHandler.cpp | 7 +++ src/log/transportation/TransportHandler.h | 2 + src/main.cpp | 12 +++- src/rce/RacingDep.cpp | 17 ++++-- src/rce/RacingDep.h | 2 +- src/rce/strategy/AggressiveStrategy.cpp | 2 +- src/rce/strategy/CreateStrategy.cpp | 3 +- src/rce/strategy/CreateStrategy.h | 2 +- src/rce/strategy/ModerateStrategy.cpp | 2 +- src/rce/strategy/SafeStrategy.cpp | 2 +- 21 files changed, 120 insertions(+), 26 deletions(-) diff --git a/src/log/Colleague.cpp b/src/log/Colleague.cpp index 26861ca..c8f6bc1 100644 --- a/src/log/Colleague.cpp +++ b/src/log/Colleague.cpp @@ -12,8 +12,8 @@ void Colleague::addObserver(Mediator *obs) { logisticsDept = obs; } -void Colleague::notify(eng::Car *car, Race* r) { - logisticsDept->sendCarToFactory(car, r); +void Colleague::notify(std::vectorcars, Race* r) { + logisticsDept->sendCarToFactory(cars, r); } void Colleague::notify(Container *container) { diff --git a/src/log/Colleague.h b/src/log/Colleague.h index dbf245f..cf61a4c 100644 --- a/src/log/Colleague.h +++ b/src/log/Colleague.h @@ -18,7 +18,7 @@ namespace lg { void addObserver(Mediator *obs); - void notify(eng::Car *car, Race*); + void notify(std::vectorcars, Race*); void notify(Container *container); diff --git a/src/log/Logistics.cpp b/src/log/Logistics.cpp index 8fd6ad9..4cd358b 100644 --- a/src/log/Logistics.cpp +++ b/src/log/Logistics.cpp @@ -62,7 +62,7 @@ void Logistics::registerNotifier(Colleague *colleague) { */ void Logistics::doYearPlanning() { //1. getBudget from "Sponsors" - budget = abs(rand() % 100 + 1); + sponsoredBudget(); //2. Hire emplpoyees: each department for (auto const&[key, val] : departments) { @@ -102,7 +102,7 @@ void Logistics::doYearPlanning() { */ void Logistics::preSeasonPreparation() { // 1. Get strategy - currentTeamStrategy = callRacingDept()->PlanSeasonStrategy(budget /*+ something else? */ ); + currentTeamStrategy = callRacingDept()->PlanSeasonStrategy(budget); //TODO : change to doc cout << "The Strategists of the " << callRacingDept()->getTeamName() << " team have decided on a strategy: " << currentTeamStrategy->getStratName() << std::endl; @@ -184,7 +184,7 @@ void Logistics::simulateEvent(Race *r) { // TODO : add fly functionality for drivers //3. get correct container, transport and fly and fly - // TODO : test transporter + transportManager->transport(r->prevRace(), r); if (r->isRaceEuropean()) { callRacingDept()->preRaceArrival(carClipboard, drivers, r, getEuropeanContainer(), tyreSpecs); @@ -265,11 +265,31 @@ void Logistics::postSeasonDebrief() { //Decorator here? //3. let transportManager take a holiday - //Implement destructors + delete transportManager; //4. Let driver take a holiday + int sumPositions = 0; + for (int i = 0; i < numPairs; ++i) { + ppl::Driver *d = drivers.back(); + drivers.pop_back(); + if (tumTumTum[2*i+1] >= 3) { + pr::Doc::detail(d->getName() + " takes a well-earned holiday near Malibu\n"); + } else { + pr::Doc::detail(d->getName() + " is tactfully offered a retirement package\n"); + } + sumPositions += tumTumTum[2*i+1]; + + } + + //5. Get some sponsors again. + sponsoredBudget(sumPositions); //5. start building a new car? + pr::Doc::summary("Start working on a new car"); + for (int i = 0; i < numPairs; ++i) { + carsInSeasonIDs.push_back(callEngDept()->buildCar(budget)); + } + } @@ -325,15 +345,43 @@ void Logistics::driverBootCamp() { } } +void Logistics::sponsoredBudget(int sumPositions) { + + pr::Doc::summary("Approaching sponsors to negotiate a new budget"); + + if (budget == 0) { //default argument + budget = abs(rand() % 100 + 1); + } + else { + if (sumPositions >= 3) { + pr::Doc::detail("Rolex is the team's next sponsor! Budget increases wildly"); + budget = max((int) ((double) budget * 1.5),(100- (int) ((double) budget * 0.5))) ; + } else if (sumPositions <= 6) { + pr::Doc::detail("Emirates is the team's next sponsor! Budget increases wildly"); + budget = max((int) ((double) budget * 0.2),(80- (int) ((double) budget * 0.2))); + } else if (sumPositions <= 10) { + pr::Doc::detail("The sponsor is satisfied with the performance"); + } else { + pr::Doc::detail("This team performed horribly. Sponsor is dissatisfied. \nBudget decreases"); + budget -= (int) ((double) budget * 0.1); + } + if (budget > 100) budget = 100; + if (budget < 0) budget = 10; + } + pr::Doc::summary("The team has been allocated a budget of " + to_string(budget) + "\n"); +} + // =========================== MEDIATOR =========================== //TODO : Strategy for using windTunnel; -void Logistics::sendCarToFactory(eng::Car *car, Race *r) { - transportManager->transport(r, nullptr, car); - callEngDept()->carArrivesAtFactory(car); - callEngDept()->improveCar(car->getId(), true); +void Logistics::sendCarToFactory(std::vector cars, Race *r) { + for (eng::Car *c: cars) { + transportManager->transport(r, nullptr, c); + callEngDept()->carArrivesAtFactory(c); + callEngDept()->improveCar(c->getId(), true); + } } //NOT STARTED - should transport container here @@ -345,7 +393,7 @@ void Logistics::containerHasBeenPacked(Container *) { * @status Should be done * @param tyreOrder */ -void Logistics::orderTyres(int* tyreOrder) { +void Logistics::orderTyres(int *tyreOrder) { pr::Doc::summary("Ordering tyres as informed by Racing Departement\n"); pr::Doc::detail("Tedious paperwork to complete tyre order\n"); @@ -376,3 +424,5 @@ void Logistics::orderTyres(int* tyreOrder) { + + diff --git a/src/log/Logistics.h b/src/log/Logistics.h index 971cabd..5de9120 100644 --- a/src/log/Logistics.h +++ b/src/log/Logistics.h @@ -34,7 +34,7 @@ namespace lg { void postSeasonDebrief(); protected: - void sendCarToFactory(eng::Car *, Race*) override; + void sendCarToFactory(std::vector, Race*) override; void containerHasBeenPacked(Container *) override; @@ -54,6 +54,8 @@ namespace lg { void driverBootCamp(); + void sponsoredBudget(int sumPositions = 0); + private: rce::RacingDep *callRacingDept(); eng::EngTeam *callEngDept(); diff --git a/src/log/Mediator.h b/src/log/Mediator.h index 9f00dc2..7a0ade6 100644 --- a/src/log/Mediator.h +++ b/src/log/Mediator.h @@ -15,7 +15,7 @@ namespace lg { protected: // virtual ~Mediator(); - virtual void sendCarToFactory(eng::Car *, Race*) = 0; + virtual void sendCarToFactory(std::vector, Race*) = 0; virtual void containerHasBeenPacked(Container *) = 0; diff --git a/src/log/transportation/Fly.cpp b/src/log/transportation/Fly.cpp index 586c294..5bb8a50 100644 --- a/src/log/transportation/Fly.cpp +++ b/src/log/transportation/Fly.cpp @@ -26,3 +26,7 @@ void Fly::transport(Race *fromLocation, Race *destination, eng::Car *car) { } } +Fly::~Fly() { + +} + diff --git a/src/log/transportation/Fly.h b/src/log/transportation/Fly.h index 0dce101..3b2976e 100644 --- a/src/log/transportation/Fly.h +++ b/src/log/transportation/Fly.h @@ -12,6 +12,7 @@ namespace lg { class Fly : public TransportHandler { public: void transport(Race *fromLocation, Race *destination, eng::Car *car = nullptr) override; + ~Fly(); }; } diff --git a/src/log/transportation/Road.cpp b/src/log/transportation/Road.cpp index 54aeeaf..7d05f99 100644 --- a/src/log/transportation/Road.cpp +++ b/src/log/transportation/Road.cpp @@ -29,3 +29,7 @@ void Road::transport(Race *fromLocation, Race *destination, eng::Car *car) { } } + +Road::~Road() { + +} diff --git a/src/log/transportation/Road.h b/src/log/transportation/Road.h index fc1209a..876c91e 100644 --- a/src/log/transportation/Road.h +++ b/src/log/transportation/Road.h @@ -12,6 +12,7 @@ namespace lg { class Road : public TransportHandler { public: void transport(Race *fromLocation, Race *destination, eng::Car *car = nullptr) override; + ~Road(); }; } diff --git a/src/log/transportation/Ship.cpp b/src/log/transportation/Ship.cpp index 4b9c57c..457080a 100644 --- a/src/log/transportation/Ship.cpp +++ b/src/log/transportation/Ship.cpp @@ -28,3 +28,7 @@ void Ship::transport(Race *fromLocation, Race *destination, eng::Car *car) { } } +Ship::~Ship() { + +} + diff --git a/src/log/transportation/Ship.h b/src/log/transportation/Ship.h index a5fac73..fab0f15 100644 --- a/src/log/transportation/Ship.h +++ b/src/log/transportation/Ship.h @@ -12,6 +12,7 @@ namespace lg{ class Ship : public TransportHandler { public: void transport(Race *fromLocation, Race *destination, eng::Car *car = nullptr) override; + ~Ship(); }; } diff --git a/src/log/transportation/TransportHandler.cpp b/src/log/transportation/TransportHandler.cpp index b7a7ca2..4c30dab 100644 --- a/src/log/transportation/TransportHandler.cpp +++ b/src/log/transportation/TransportHandler.cpp @@ -19,6 +19,13 @@ void TransportHandler::addAMethod(TransportHandler *transport) { } } +TransportHandler::~TransportHandler() { + if (nextTransportationMethod) { + delete nextTransportationMethod; + } + +} + void TransportHandler::transport(Race *fromLocation, Race *destination, eng::Car *car) { if (nextTransportationMethod) { nextTransportationMethod->transport(fromLocation, destination, car); diff --git a/src/log/transportation/TransportHandler.h b/src/log/transportation/TransportHandler.h index ed9a76b..9ff2229 100644 --- a/src/log/transportation/TransportHandler.h +++ b/src/log/transportation/TransportHandler.h @@ -17,6 +17,8 @@ namespace lg { private: TransportHandler *nextTransportationMethod = nullptr; public: + ~TransportHandler(); + void hireEmployees(int budget) override; void addAMethod(TransportHandler *transport); diff --git a/src/main.cpp b/src/main.cpp index 96821ab..df10aeb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,8 +23,8 @@ void seasonRun(); int main() { //logDeptTesting(); - engTeamTesting(); - //seasonRun(); + //engTeamTesting(); + seasonRun(); } @@ -65,6 +65,14 @@ void seasonRun() { delete racingDept; delete engDept; delete a; + /*engDept->hireEmployees(50); + engDept->resetTickets(); + engDept->setRiskLevel(lg::Aggressive); + int id = engDept->buildCar(50); + eng::Car* car = engDept->checkCarOutOfFactory(id); + car->print();*/ + + } void engTeamTesting() { diff --git a/src/rce/RacingDep.cpp b/src/rce/RacingDep.cpp index 3231863..1c654c3 100644 --- a/src/rce/RacingDep.cpp +++ b/src/rce/RacingDep.cpp @@ -138,8 +138,11 @@ ppl::Driver *RacingDep::trainDriver(ppl::Driver *driver, int time, lg::WeatherCo { }*/ -void RacingDep::preRaceArrival(std::vector, std::vector, lg::Race *, lg::Container *, Tyres *) { +void RacingDep::preRaceArrival(std::vector cars, std::vector, lg::Race *r, lg::Container *cont, Tyres *) { // TODO - implement RacingDep::preRaceArrival + this->CarContainer = cont; + this->race = r; + this->cars = cars; //throw "Not yet implemented"; } @@ -227,11 +230,14 @@ void RacingDep::SetCarAfterRace() } int *RacingDep::RacingWeekend() { - return nullptr; + int *results = new int[2]; + results[0] = 5; results[1] = 6; + return results; } lg::Container *RacingDep::postRacePackUp() { - return nullptr; + notify(cars, race); + return this->CarContainer; } RacingDep::~RacingDep() { @@ -245,7 +251,10 @@ RacingDep::RacingDep() { int *RacingDep::getFinalResults() { //return array {score1,postition1,score2, postion2} - throw "Not yet implemented"; + //throw "Not yet implemented"; + int* results = new int[4]; + results[0] = 512; results[1] = 1; results[2] = 213; results[3] = 5; + return results; } diff --git a/src/rce/RacingDep.h b/src/rce/RacingDep.h index 6ae8c73..010272f 100644 --- a/src/rce/RacingDep.h +++ b/src/rce/RacingDep.h @@ -21,7 +21,7 @@ namespace rce { std::string TeamName; //std::list Stategist; std::list pitcrew; - eng::Car *car; + std::vector cars; // / ppl::Driver array of size 2? // / car array of size 2? diff --git a/src/rce/strategy/AggressiveStrategy.cpp b/src/rce/strategy/AggressiveStrategy.cpp index a77fa3e..f21ea53 100644 --- a/src/rce/strategy/AggressiveStrategy.cpp +++ b/src/rce/strategy/AggressiveStrategy.cpp @@ -10,6 +10,6 @@ AggressiveStrategy::AggressiveStrategy(int p,int* t,int risk) std::cout<<"The startegists have decided to implement an aggressive strategy"< Date: Wed, 4 Nov 2020 13:10:02 +0200 Subject: [PATCH 02/13] fix: hardcoded file path to relative file path --- src/log/Logistics.cpp | 13 ++++++------- src/main.cpp | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/log/Logistics.cpp b/src/log/Logistics.cpp index 4cd358b..6edf347 100644 --- a/src/log/Logistics.cpp +++ b/src/log/Logistics.cpp @@ -210,16 +210,14 @@ void Logistics::simulateEvent(Race *r) { /** * @author Jo * @status nearly there - * @ERROR hard-coded file path */ -// TODO : Fix hard-coded file-path void Logistics::putRacesIntoCalender() { racingCalendar = new RacesList; - try { - std::ifstream infile; - infile.open("/home/jo-anne/Documents/VierEenTwee/src/log/races/raceData.txt"); - //infile.open("src/lg/races/raceData.txt"); + std::ifstream infile; + infile.open("../src/log/races/raceData.txt"); + + if (infile.is_open()) { int numRaces; infile >> numRaces; @@ -238,8 +236,9 @@ void Logistics::putRacesIntoCalender() { getline(infile, name); //to remove first random /n } infile.close(); - } catch (std::ifstream::failure e) { //exception e + } else { //exception e std::cout << "There was a file-reading error !\n"; + throw "Error"; } racingCalendar->printList(); diff --git a/src/main.cpp b/src/main.cpp index df10aeb..9a98248 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,7 +14,7 @@ #include "pr/Doc.h" #include "log/Logistics.h" -int pr::Doc::transparency = 1; +int pr::Doc::transparency = 0; void logDeptTesting(); void engTeamTesting(); From 2ba1e427485265daabb677a1dc1fbfe36d4e0463 Mon Sep 17 00:00:00 2001 From: ArdentiaCM Date: Wed, 4 Nov 2020 13:27:43 +0200 Subject: [PATCH 03/13] Getting raceData.txt to work --- cmake-build-debug/raceData.txt | 85 +++++++++++++++++++++++++++++++ src/log/Logistics.cpp | 5 +- src/log/races/GarageEquipment.cpp | 10 +++- src/main.cpp | 54 ++++++++++++++++++-- src/rce/RacingDep.cpp | 1 - 5 files changed, 148 insertions(+), 7 deletions(-) create mode 100644 cmake-build-debug/raceData.txt diff --git a/cmake-build-debug/raceData.txt b/cmake-build-debug/raceData.txt new file mode 100644 index 0000000..00fea88 --- /dev/null +++ b/cmake-build-debug/raceData.txt @@ -0,0 +1,85 @@ +21 +Australia +2 +0 +58 +Bahrain +2 +0 +57 +China +3 +0 +56 +Azerbaijan +1 +0 +51 +Spain +3 +1 +66 +Monaco +3 +1 +78 +Canada +1 +0 +70 +France +2 +1 +53 +Austria +1 +1 +71 +Great Britain +2 +1 +52 +Germany +2 +1 +67 +Hungary +2 +1 +70 +Belgium +3 +1 +44 +Italy +1 +1 +53 +Singapore +3 +0 +61 +Russia +1 +0 +53 +Japan +3 +0 +53 +Mexico +2 +0 +71 +United States +3 +0 +56 +Brazil +1 +0 +71 +Abu Dhabi +3 +0 +55 \ No newline at end of file diff --git a/src/log/Logistics.cpp b/src/log/Logistics.cpp index 4cd358b..5139f86 100644 --- a/src/log/Logistics.cpp +++ b/src/log/Logistics.cpp @@ -218,8 +218,9 @@ void Logistics::putRacesIntoCalender() { try { std::ifstream infile; - infile.open("/home/jo-anne/Documents/VierEenTwee/src/log/races/raceData.txt"); - //infile.open("src/lg/races/raceData.txt"); +// fstream infile("C:/Users/User/CLionProjects/COS214/VierEenTwee/src/log/races/raceData.txt"); +// fstream file1("C:/Users/MR_Salman/Desktop/exper.txt"); + infile.open("../src/log/races/raceData.txt"); int numRaces; infile >> numRaces; diff --git a/src/log/races/GarageEquipment.cpp b/src/log/races/GarageEquipment.cpp index dbff269..1bb3fae 100644 --- a/src/log/races/GarageEquipment.cpp +++ b/src/log/races/GarageEquipment.cpp @@ -2,6 +2,7 @@ // Created by jo-anne on 2020/10/26. // +#include #include "GarageEquipment.h" using namespace lg; @@ -26,4 +27,11 @@ void GarageEquipment::unpack() { GarageEquipment::~GarageEquipment() = default; -void GarageEquipment::print() {} \ No newline at end of file +void GarageEquipment::print() { + pr::Doc::detail("Garage equipment:\n"); + pr::Doc::detail(" "); + for (std::list::iterator it = contents.begin(); it != contents.end(); ++it) { + pr::Doc::detail(*it); + } + pr::Doc::detail("\n"); +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index df10aeb..8e3202e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,17 +14,20 @@ #include "pr/Doc.h" #include "log/Logistics.h" -int pr::Doc::transparency = 1; +int pr::Doc::transparency = 0; void logDeptTesting(); void engTeamTesting(); void seasonRun(); +void testTyres(); +void testContainers(); int main() { //logDeptTesting(); //engTeamTesting(); - seasonRun(); +// seasonRun(); + testTyres(); } @@ -109,4 +112,49 @@ void engTeamTesting() { delete fixedCar; delete e; -} \ No newline at end of file +} + +void testTyres() { + int arr1[3] = {2,1,2}; + int arr2[3] = {0,1,4}; + int arr3[3] = {0,0,5}; + + + auto* tyres1 = new rce::Tyres(arr1); + auto* tyres2 = new rce::Tyres(arr2); + auto* tyres3 = new rce::Tyres(arr3); + + tyres1->printStats(); +// tyres2->printStats(); +// tyres3->printStats(); + + SetOfTyres* tyreSet1 = tyres1->getTyres(0); + SetOfTyres* tyreSet2 = tyres1->getTyres(0); + SetOfTyres* tyreSet3 = tyres1->getTyres(0); + + + if (tyreSet1 != nullptr) { + tyreSet1->printStats(); + + tyreSet1->reduceThread(49); + tyreSet1->printStats(); + + for (int x = 0; x < 20; x++) { + tyreSet1->reduceThread(2); + } + + tyreSet1->printStats(); + + } + + if(tyreSet3 == nullptr) { + std::cout << "No more tyres of that type" << std::endl; + } + + tyres1->printStats(); + delete tyres1; + delete tyres2; + delete tyres3; + + } + diff --git a/src/rce/RacingDep.cpp b/src/rce/RacingDep.cpp index 1c654c3..78c5fd7 100644 --- a/src/rce/RacingDep.cpp +++ b/src/rce/RacingDep.cpp @@ -245,7 +245,6 @@ RacingDep::~RacingDep() { } RacingDep::RacingDep() { - strategy = nullptr; std::cout << "Constructor" << std::endl; } From bdcb98baee788b1d6a7b10f784d89cba0d94dca1 Mon Sep 17 00:00:00 2001 From: jo-anne Date: Wed, 4 Nov 2020 13:34:28 +0200 Subject: [PATCH 04/13] Chasing down the small foxes --- src/log/Colleague.cpp | 5 ++--- src/log/Logistics.cpp | 19 +++++++++++-------- src/log/races/RacesList.cpp | 30 ++++++++++++++++++++---------- src/main.cpp | 2 +- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/log/Colleague.cpp b/src/log/Colleague.cpp index c8f6bc1..fe1ad1a 100644 --- a/src/log/Colleague.cpp +++ b/src/log/Colleague.cpp @@ -22,11 +22,10 @@ void Colleague::notify(Container *container) { void Colleague::notify(bool isEuropeanRace) { //logisticsDept->requestContainerStateChange(isEuropeanRace); - //TODO : change to pr::DOC if (isEuropeanRace) { - std::cout << "Transportation in Europe\n"; + pr::Doc::summary("Transportation in Europe\n"); } else { - std::cout << "Transportation outside of Europe\n"; + pr::Doc::summary("Transportation outside of Europe\n"); } } diff --git a/src/log/Logistics.cpp b/src/log/Logistics.cpp index 6edf347..1b62b09 100644 --- a/src/log/Logistics.cpp +++ b/src/log/Logistics.cpp @@ -103,17 +103,15 @@ void Logistics::doYearPlanning() { void Logistics::preSeasonPreparation() { // 1. Get strategy currentTeamStrategy = callRacingDept()->PlanSeasonStrategy(budget); - //TODO : change to doc - cout << "The Strategists of the " << callRacingDept()->getTeamName() << " team have decided on a strategy: " - << currentTeamStrategy->getStratName() << std::endl; + pr::Doc::detail("The Strategists of the " + callRacingDept()->getTeamName() + " team have decided on a strategy: " + currentTeamStrategy->getStratName()); // 1.1 Notified about tyres (in the meanwhile) // 1.2 Receive Order - std::cout << "Tyre Order has arrived" << endl; + pr::Doc::summary("Tyre Order has arrived"); //tyreSpecs->printStats(); //not always //2. Pack containers - cout << "Ordering the necessary tooleries and garage equipment thingamabobs\n"; + pr::Doc::detail("Ordering the necessary tooleries and garage equipment thingamabobs\n"); packContainers(); //3. Train drivers @@ -164,8 +162,6 @@ Container *Logistics::packSingleContainer() { } - -// TODO : Check again void Logistics::simulateEvent(Race *r) { //1. Transport car (from factory to race location) //1.1 Fill up clipboard @@ -200,10 +196,17 @@ void Logistics::simulateEvent(Race *r) { //5. finish the packup Container *tCont = callRacingDept()->postRacePackUp(); + //6. Transport drivers on and container back + if (r->nextRace()== nullptr) { + pr::Doc::detail ("The drivers are transported in a luxury mode of transport back to HQ"); + transportManager->transport(r, nullptr); + if (r->isRaceEuropean()) { + delete tCont; //we need to get rid of it. + } + } if (!r->isRaceEuropean()) { delete tCont; //nonEuropeanContainer won't be used again } //else stay with the container - //6. Transport drivers on and container back } diff --git a/src/log/races/RacesList.cpp b/src/log/races/RacesList.cpp index 3b1ad55..2c7df0c 100644 --- a/src/log/races/RacesList.cpp +++ b/src/log/races/RacesList.cpp @@ -6,11 +6,22 @@ #include "RacesList.h" #include "Doc.h" -using namespace lg; +namespace lg { + std::string convertComplexityToString(TrackComplexity t) { + switch (t) { + case Easy: + return "Easy"; + case Average: + return "Average"; + case Difficult: + return "Difficult"; + case Extreme: + return "Extreme"; + } + } +} -/*RaceIterator RacesList::createIterator() { - return RaceIterator(*this, headRace); -}*/ +using namespace lg; RacesList::RacesList() { headRace = nullptr; @@ -64,14 +75,13 @@ void RacesList::printList() { } else { while (temp != nullptr) { pr::Doc::detail(temp->getLocation()); - pr::Doc::detail("\nNumLaps: "); + pr::Doc::detail("\nNumber of Laps: "); pr::Doc::detail(std::to_string(temp->getNumLaps())); - pr::Doc::detail("\nWeather:"); - // TODO : add back in race day weather -// pr::Doc::detail(temp->getRaceDayWeather()); + pr::Doc::detail("\nTrack Complexity: "); + pr::Doc::detail(convertComplexityToString(temp->getTrackComplexity())); pr::Doc::detail("\n"); - std::cout << temp->getLocation() << "\nNumLaps: " << temp->getNumLaps() << "\nWeather:" - << temp->getRaceDayWeather() << std::endl; + /*std::cout << temp->getLocation() << "\nNumLaps: " << temp->getNumLaps() << "\nWeather:" + << temp->getRaceDayWeather() << std::endl;*/ temp = temp->nextRace(); } } diff --git a/src/main.cpp b/src/main.cpp index 9a98248..df10aeb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,7 +14,7 @@ #include "pr/Doc.h" #include "log/Logistics.h" -int pr::Doc::transparency = 0; +int pr::Doc::transparency = 1; void logDeptTesting(); void engTeamTesting(); From 8c97245211456999b4a1de822ec8d5e00f344c5f Mon Sep 17 00:00:00 2001 From: ArdentiaCM Date: Wed, 4 Nov 2020 16:46:36 +0200 Subject: [PATCH 05/13] Added detail to container class (rough) and did it in the doc format --- src/log/Logistics.cpp | 8 ++++++-- src/log/races/Box.cpp | 12 ------------ src/log/races/Box.h | 4 ---- src/log/races/CateringEquipment.cpp | 23 ++++++++++++++++++----- src/log/races/CateringEquipment.h | 8 +++++++- src/log/races/Container.cpp | 23 ----------------------- src/log/races/Container.h | 4 ---- src/log/races/GarageEquipment.cpp | 25 +++++++++++++++---------- src/log/races/GarageEquipment.h | 2 -- src/main.cpp | 12 +++++++----- 10 files changed, 53 insertions(+), 68 deletions(-) diff --git a/src/log/Logistics.cpp b/src/log/Logistics.cpp index 6edf347..16cfa77 100644 --- a/src/log/Logistics.cpp +++ b/src/log/Logistics.cpp @@ -110,7 +110,7 @@ void Logistics::preSeasonPreparation() { // 1.1 Notified about tyres (in the meanwhile) // 1.2 Receive Order std::cout << "Tyre Order has arrived" << endl; - //tyreSpecs->printStats(); //not always + //tyreSpecs->printStats(); //moet ons dit so maak dat dit print op verskillende levels? //2. Pack containers cout << "Ordering the necessary tooleries and garage equipment thingamabobs\n"; @@ -158,7 +158,11 @@ Container *Logistics::packSingleContainer() { box->addElement(garageEquip); box->addElement(cateringEquip); - cout << "Packed a container" << endl; + + + pr::Doc::summary("Packed a container\n"); + box->print(); + pr::Doc::detail("\n"); return box; diff --git a/src/log/races/Box.cpp b/src/log/races/Box.cpp index 71c0301..e40717c 100644 --- a/src/log/races/Box.cpp +++ b/src/log/races/Box.cpp @@ -11,18 +11,6 @@ void Box::addElement(Container *c) { elements.push_back(c); } -void Box::pack() {} - - -void Box::unpack() { - Container::unpack(); - std::cout << "\nBox contains: " << std::endl; - for (std::list::iterator it = elements.begin(); it != elements.end(); ++it) { - (*it)->unpack(); - } - //Moet verander word en reg-geimplementeer word -} - Box::~Box() { for (std::list::iterator it = elements.begin(); it != elements.end(); ++it) { delete *it; diff --git a/src/log/races/Box.h b/src/log/races/Box.h index 56c69b6..c3e1b51 100644 --- a/src/log/races/Box.h +++ b/src/log/races/Box.h @@ -17,10 +17,6 @@ namespace lg { void addElement(Container *) override; - void unpack() override; - - void pack() override; - ~Box() override; void print() override; diff --git a/src/log/races/CateringEquipment.cpp b/src/log/races/CateringEquipment.cpp index c2b6bcb..9c7763a 100644 --- a/src/log/races/CateringEquipment.cpp +++ b/src/log/races/CateringEquipment.cpp @@ -2,14 +2,21 @@ // Created by jo-anne on 2020/10/26. // +#include #include "CateringEquipment.h" using namespace lg; -CateringEquipment::CateringEquipment() {} - -void CateringEquipment::unpack() { - //Print net unpack uit +/** + * @author Marike + * TODO: create constructor with int parameter + */ +CateringEquipment::CateringEquipment() { + contents.emplace_back("Water Bottles"); + contents.emplace_back("Salty cracks"); + contents.emplace_back("Towels"); + contents.emplace_back("Batteries"); + contents.emplace_back("A torch"); } CateringEquipment::CateringEquipment(std::list insides) { @@ -25,5 +32,11 @@ CateringEquipment::CateringEquipment(std::list insides) { CateringEquipment::~CateringEquipment() = default; void CateringEquipment::print() { - + pr::Doc::detail("Catering Equipment:\n"); + for (std::list::iterator it = contents.begin(); it != contents.end(); ++it) { + pr::Doc::detail(" "); + pr::Doc::detail(*it); + pr::Doc::detail("\n"); + } + pr::Doc::detail("\n"); } \ No newline at end of file diff --git a/src/log/races/CateringEquipment.h b/src/log/races/CateringEquipment.h index ef76153..41a9772 100644 --- a/src/log/races/CateringEquipment.h +++ b/src/log/races/CateringEquipment.h @@ -9,13 +9,19 @@ namespace lg { class CateringEquipment : public Container { + private: + std::list contents; + public: + CateringEquipment(); + CateringEquipment(std::list insides); - void unpack() override; + ~CateringEquipment() override; + void print() override; }; } diff --git a/src/log/races/Container.cpp b/src/log/races/Container.cpp index e589a82..cd73b17 100644 --- a/src/log/races/Container.cpp +++ b/src/log/races/Container.cpp @@ -13,29 +13,6 @@ Container::~Container() { } -void Container::unpack() { - //Unpack gaan net werk in die hoof container. Dit moenie geroep word later nie. - - //Print alles uit - - //Gaan soek die container wat 'n tyreBox is om dit te return . . . tyre variable to return? Ja. Okay. - - std::cout << "CONTAINER UNPACK BY printing out contents and returning the tyres in the container" << std::endl; - -} - -/** - *@author Marike - * @param usedTyres - */ -void Container::pack() { - - //Should we pack up the container? Ek dink ons hoef net 'n print funksie te hĂȘ - - std::cout << "print out contents" << std::endl; - -} - void Container::addElement(Container * newContainer) { std::cout << "Pack box into main container" << std::endl; } diff --git a/src/log/races/Container.h b/src/log/races/Container.h index 4276673..f5f8292 100644 --- a/src/log/races/Container.h +++ b/src/log/races/Container.h @@ -23,10 +23,6 @@ namespace lg { virtual ~Container(); - virtual void unpack(); - - virtual void pack(); - virtual void print(); protected: diff --git a/src/log/races/GarageEquipment.cpp b/src/log/races/GarageEquipment.cpp index 1bb3fae..1986ed4 100644 --- a/src/log/races/GarageEquipment.cpp +++ b/src/log/races/GarageEquipment.cpp @@ -7,11 +7,21 @@ using namespace lg; -GarageEquipment::GarageEquipment() {} +/** + * @author Marike + * //TODO: create int parameter constructor + */ +GarageEquipment::GarageEquipment() { + contents.emplace_back("Spare Tyres"); + contents.emplace_back("Oil can"); + contents.emplace_back("Elbow Grease"); + contents.emplace_back("Nuts and bolts"); + contents.emplace_back("A spanner"); +} GarageEquipment::GarageEquipment(std::list insides) { - if (insides.size() == 0) { - contents.push_back("Lots and lots of stuff"); + if (insides.empty()) { + contents.emplace_back("Lots and lots of stuff"); return; } for (std::list::iterator it = insides.begin(); it != insides.end(); ++it) { @@ -19,19 +29,14 @@ GarageEquipment::GarageEquipment(std::list insides) { } } -void GarageEquipment::unpack() { - for (std::list::iterator it = contents.begin(); it != contents.end(); ++it) { - std::cout << "-" << (*it) << std::endl; - } -} - GarageEquipment::~GarageEquipment() = default; void GarageEquipment::print() { pr::Doc::detail("Garage equipment:\n"); - pr::Doc::detail(" "); for (std::list::iterator it = contents.begin(); it != contents.end(); ++it) { + pr::Doc::detail(" "); pr::Doc::detail(*it); + pr::Doc::detail("\n"); } pr::Doc::detail("\n"); } \ No newline at end of file diff --git a/src/log/races/GarageEquipment.h b/src/log/races/GarageEquipment.h index 88ddc31..043854f 100644 --- a/src/log/races/GarageEquipment.h +++ b/src/log/races/GarageEquipment.h @@ -16,8 +16,6 @@ namespace lg { GarageEquipment(std::list insides); - void unpack() override; - ~GarageEquipment() override; void print() override; diff --git a/src/main.cpp b/src/main.cpp index 8e3202e..3d72b90 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,20 +14,21 @@ #include "pr/Doc.h" #include "log/Logistics.h" -int pr::Doc::transparency = 0; +int pr::Doc::transparency = 1; void logDeptTesting(); void engTeamTesting(); void seasonRun(); void testTyres(); -void testContainers(); + int main() { //logDeptTesting(); //engTeamTesting(); -// seasonRun(); - testTyres(); + seasonRun(); +// testTyres(); + } @@ -76,6 +77,8 @@ void seasonRun() { car->print();*/ + + } void engTeamTesting() { @@ -157,4 +160,3 @@ void testTyres() { delete tyres3; } - From 5507f6f9288d32817c212ce2cc512c649991051c Mon Sep 17 00:00:00 2001 From: ArdentiaCM Date: Wed, 4 Nov 2020 18:07:16 +0200 Subject: [PATCH 06/13] Implemented int constructors to Catering and Garage equipments. Prints out right --- CMakeLists.txt | 16 +++--- src/log/Colleague.h | 2 +- src/log/Logistics.cpp | 17 +++--- src/log/Mediator.h | 2 +- src/log/{races => containers}/Box.cpp | 0 src/log/{races => containers}/Box.h | 0 .../CateringEquipment.cpp | 27 ++++++--- .../{races => containers}/CateringEquipment.h | 2 +- src/log/{races => containers}/Container.cpp | 0 src/log/{races => containers}/Container.h | 0 src/log/containers/GarageEquipment.cpp | 56 +++++++++++++++++++ .../{races => containers}/GarageEquipment.h | 2 +- src/log/races/GarageEquipment.cpp | 42 -------------- src/rce/RaceWeekend.h | 2 +- 14 files changed, 98 insertions(+), 70 deletions(-) rename src/log/{races => containers}/Box.cpp (100%) rename src/log/{races => containers}/Box.h (100%) rename src/log/{races => containers}/CateringEquipment.cpp (52%) rename src/log/{races => containers}/CateringEquipment.h (87%) rename src/log/{races => containers}/Container.cpp (100%) rename src/log/{races => containers}/Container.h (100%) create mode 100644 src/log/containers/GarageEquipment.cpp rename src/log/{races => containers}/GarageEquipment.h (87%) delete mode 100644 src/log/races/GarageEquipment.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index aa5da25..de7d764 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,14 +72,14 @@ add_executable(VierEenTwee src/log/enums/TrackComplexity.h src/log/enums/WeatherConditions.h src/log/races/Aggregate.h - src/log/races/Box.cpp - src/log/races/Box.h - src/log/races/CateringEquipment.cpp - src/log/races/CateringEquipment.h - src/log/races/Container.cpp - src/log/races/Container.h - src/log/races/GarageEquipment.cpp - src/log/races/GarageEquipment.h + src/log/containers/Box.cpp + src/log/containers/Box.h + src/log/containers/CateringEquipment.cpp + src/log/containers/CateringEquipment.h + src/log/containers/Container.cpp + src/log/containers/Container.h + src/log/containers/GarageEquipment.cpp + src/log/containers/GarageEquipment.h src/log/races/Iterator.h src/log/races/Race.cpp src/log/races/Race.h diff --git a/src/log/Colleague.h b/src/log/Colleague.h index cf61a4c..08b63b4 100644 --- a/src/log/Colleague.h +++ b/src/log/Colleague.h @@ -7,7 +7,7 @@ #include #include "Car.h" -#include "races/Container.h" +#include "containers/Container.h" //#include //both eng- and racing- need it namespace lg { class Mediator; diff --git a/src/log/Logistics.cpp b/src/log/Logistics.cpp index f0778c9..80c400a 100644 --- a/src/log/Logistics.cpp +++ b/src/log/Logistics.cpp @@ -10,9 +10,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include "enums/randomisation.h" @@ -150,13 +150,14 @@ void Logistics::packContainers() { */ Container *Logistics::packSingleContainer() { Box *box = new Box(); - auto *garageEquip = new GarageEquipment(); - auto *cateringEquip = new CateringEquipment(); + auto *garageEquip = new GarageEquipment(budget); + auto *cateringEquip = new CateringEquipment(budget); box->addElement(garageEquip); box->addElement(cateringEquip); pr::Doc::summary("Packed a container\n"); + pr::Doc::detail("\n"); box->print(); pr::Doc::detail("\n"); @@ -351,17 +352,17 @@ void Logistics::driverBootCamp() { void Logistics::sponsoredBudget(int sumPositions) { - pr::Doc::summary("Approaching sponsors to negotiate a new budget"); + pr::Doc::summary("Approaching sponsors to negotiate a new budget\n"); if (budget == 0) { //default argument budget = abs(rand() % 100 + 1); } else { if (sumPositions >= 3) { - pr::Doc::detail("Rolex is the team's next sponsor! Budget increases wildly"); + pr::Doc::detail("Rolex is the team's next sponsor! Budget increases wildly\n"); budget = max((int) ((double) budget * 1.5),(100- (int) ((double) budget * 0.5))) ; } else if (sumPositions <= 6) { - pr::Doc::detail("Emirates is the team's next sponsor! Budget increases wildly"); + pr::Doc::detail("Emirates is the team's next sponsor! Budget increases wildly\n"); budget = max((int) ((double) budget * 0.2),(80- (int) ((double) budget * 0.2))); } else if (sumPositions <= 10) { pr::Doc::detail("The sponsor is satisfied with the performance"); diff --git a/src/log/Mediator.h b/src/log/Mediator.h index 7a0ade6..8c3741b 100644 --- a/src/log/Mediator.h +++ b/src/log/Mediator.h @@ -7,7 +7,7 @@ #include #include "Car.h" -#include "races/Container.h" +#include "containers/Container.h" namespace lg { diff --git a/src/log/races/Box.cpp b/src/log/containers/Box.cpp similarity index 100% rename from src/log/races/Box.cpp rename to src/log/containers/Box.cpp diff --git a/src/log/races/Box.h b/src/log/containers/Box.h similarity index 100% rename from src/log/races/Box.h rename to src/log/containers/Box.h diff --git a/src/log/races/CateringEquipment.cpp b/src/log/containers/CateringEquipment.cpp similarity index 52% rename from src/log/races/CateringEquipment.cpp rename to src/log/containers/CateringEquipment.cpp index 9c7763a..124aa5e 100644 --- a/src/log/races/CateringEquipment.cpp +++ b/src/log/containers/CateringEquipment.cpp @@ -19,13 +19,27 @@ CateringEquipment::CateringEquipment() { contents.emplace_back("A torch"); } -CateringEquipment::CateringEquipment(std::list insides) { - if (insides.size() == 0) { - contents.push_back("Lots and lots of stuff"); - return; +CateringEquipment::CateringEquipment(int budget) { + int arr = 4; + + std::string poorArr[] = {"Benches", "Water bottles", "Salty Cracks", "Gazebo"}; + std::string aveArr[] = {"Camping chairs", "Energy drinks", "Nutri bars", "Tent"}; + std::string richArr[] = {"Hospitality Sofas - Inflatable", "Champagne", "Caviar", "Gala Performance Dual Pit Walling"}; + + if (budget < 51) { + for (int x = 0; x < arr; x++) { + contents.push_back(poorArr[x]); + } + } + else if (budget < 76) { + for (int x = 0; x < arr; x++) { + contents.push_back(aveArr[x]); + } } - for (std::list::iterator it = insides.begin(); it != insides.end(); ++it) { - contents.push_back(*it); + else { + for (int x = 0; x < arr; x++) { + contents.push_back(richArr[x]); + } } } @@ -38,5 +52,4 @@ void CateringEquipment::print() { pr::Doc::detail(*it); pr::Doc::detail("\n"); } - pr::Doc::detail("\n"); } \ No newline at end of file diff --git a/src/log/races/CateringEquipment.h b/src/log/containers/CateringEquipment.h similarity index 87% rename from src/log/races/CateringEquipment.h rename to src/log/containers/CateringEquipment.h index 41a9772..149656b 100644 --- a/src/log/races/CateringEquipment.h +++ b/src/log/containers/CateringEquipment.h @@ -18,7 +18,7 @@ namespace lg { CateringEquipment(); - CateringEquipment(std::list insides); + CateringEquipment(int); ~CateringEquipment() override; diff --git a/src/log/races/Container.cpp b/src/log/containers/Container.cpp similarity index 100% rename from src/log/races/Container.cpp rename to src/log/containers/Container.cpp diff --git a/src/log/races/Container.h b/src/log/containers/Container.h similarity index 100% rename from src/log/races/Container.h rename to src/log/containers/Container.h diff --git a/src/log/containers/GarageEquipment.cpp b/src/log/containers/GarageEquipment.cpp new file mode 100644 index 0000000..baf7b7d --- /dev/null +++ b/src/log/containers/GarageEquipment.cpp @@ -0,0 +1,56 @@ +// +// Created by jo-anne on 2020/10/26. +// + +#include +#include "GarageEquipment.h" + +using namespace lg; + +/** + * @author Marike + * //TODO: create int parameter constructor + */ +GarageEquipment::GarageEquipment() { + contents.emplace_back("Spare Tyres"); + contents.emplace_back("Oil can"); + contents.emplace_back("Elbow Grease"); + contents.emplace_back("Nuts and bolts"); + contents.emplace_back("A spanner"); +} + +GarageEquipment::GarageEquipment(int budget) { + int arr = 5; + std::string poorArr[5] = {"Spanners", "Extra helmet", "Elbow Grease", "Nuts and bolts", "Vehicle Skates"}; + std::string aveArr[5] = {"Wheel guns", "Custom paint helmet", "Ratchet", "Dive bottle compressor", "Air Lifts"}; + std::string richArr[5] = {"Easy roll rim cleaner", "Air bottle trolleys", "Tyre warmer tent", "Box with secret compartment for Plutonium Hammer", "Wheel Gun Service Kits"}; + + if (budget < 51) { + for (int x = 0; x < arr; x++) { + contents.push_back(poorArr[x]); + } + } + else if (budget < 76) { + for (int x = 0; x < arr; x++) { + contents.push_back(aveArr[x]); + } + } + else { + for (int x = 0; x < arr; x++) { + contents.push_back(richArr[x]); + } + } + +} + +GarageEquipment::~GarageEquipment() = default; + +void GarageEquipment::print() { + pr::Doc::detail("Garage equipment:\n"); + for (std::list::iterator it = contents.begin(); it != contents.end(); ++it) { + pr::Doc::detail(" "); + pr::Doc::detail(*it); + pr::Doc::detail("\n"); + } + pr::Doc::detail("\n"); +} \ No newline at end of file diff --git a/src/log/races/GarageEquipment.h b/src/log/containers/GarageEquipment.h similarity index 87% rename from src/log/races/GarageEquipment.h rename to src/log/containers/GarageEquipment.h index 043854f..966c10d 100644 --- a/src/log/races/GarageEquipment.h +++ b/src/log/containers/GarageEquipment.h @@ -14,7 +14,7 @@ namespace lg { public: GarageEquipment(); - GarageEquipment(std::list insides); + GarageEquipment(int); ~GarageEquipment() override; diff --git a/src/log/races/GarageEquipment.cpp b/src/log/races/GarageEquipment.cpp deleted file mode 100644 index 1986ed4..0000000 --- a/src/log/races/GarageEquipment.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// -// Created by jo-anne on 2020/10/26. -// - -#include -#include "GarageEquipment.h" - -using namespace lg; - -/** - * @author Marike - * //TODO: create int parameter constructor - */ -GarageEquipment::GarageEquipment() { - contents.emplace_back("Spare Tyres"); - contents.emplace_back("Oil can"); - contents.emplace_back("Elbow Grease"); - contents.emplace_back("Nuts and bolts"); - contents.emplace_back("A spanner"); -} - -GarageEquipment::GarageEquipment(std::list insides) { - if (insides.empty()) { - contents.emplace_back("Lots and lots of stuff"); - return; - } - for (std::list::iterator it = insides.begin(); it != insides.end(); ++it) { - contents.push_back(*it); - } -} - -GarageEquipment::~GarageEquipment() = default; - -void GarageEquipment::print() { - pr::Doc::detail("Garage equipment:\n"); - for (std::list::iterator it = contents.begin(); it != contents.end(); ++it) { - pr::Doc::detail(" "); - pr::Doc::detail(*it); - pr::Doc::detail("\n"); - } - pr::Doc::detail("\n"); -} \ No newline at end of file diff --git a/src/rce/RaceWeekend.h b/src/rce/RaceWeekend.h index c4460aa..72f0b79 100644 --- a/src/rce/RaceWeekend.h +++ b/src/rce/RaceWeekend.h @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include "PitCrew.h" From 50a5d27488931593ebc89175d6d7ab07628031bd Mon Sep 17 00:00:00 2001 From: jo-anne Date: Wed, 4 Nov 2020 20:48:27 +0200 Subject: [PATCH 07/13] in progress: work on Driver training regime --- src/log/Logistics.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/log/Logistics.cpp b/src/log/Logistics.cpp index f0778c9..e83fd12 100644 --- a/src/log/Logistics.cpp +++ b/src/log/Logistics.cpp @@ -343,7 +343,23 @@ eng::EngTeam *Logistics::callEngDept() { void Logistics::driverBootCamp() { /*moet meer spesifiek wees hierso. gaan ons van hulle verwag of gaan ons self check dat die driver genoeg xp het? Dalk kan ons dit volgens riskLevel doen*/ - for (ppl::Driver *d: drivers) { + switch (currentTeamStrategy->getRiskLevel()) { + case Safe: + //time higher + //more weather conditions + //higher time complexity + //worse weather condtions + break; + case Moderate: + + break; + case Aggressive: + + break; + + } + +for (ppl::Driver *d: drivers) { //randomise weathering callRacingDept()->trainDriver(d, rand() % 10 + 1, randomWC(), randomTL()); } @@ -381,10 +397,15 @@ void Logistics::sponsoredBudget(int sumPositions) { //TODO : Strategy for using windTunnel; void Logistics::sendCarToFactory(std::vector cars, Race *r) { + int i = 0; for (eng::Car *c: cars) { transportManager->transport(r, nullptr, c); - callEngDept()->carArrivesAtFactory(c); - callEngDept()->improveCar(c->getId(), true); + int performance = cars[i]->getSpeed() + cars[i++]->getHandling(); + if (performance > 10) { + callEngDept()->improveCar(c->getId(), false); + } else { + callEngDept()->improveCar(c->getId(), true) + } } } From c72aec19668dd8434a6c028be25fc145c247256d Mon Sep 17 00:00:00 2001 From: jo-anne Date: Thu, 5 Nov 2020 07:54:17 +0200 Subject: [PATCH 08/13] removed unneccessary todo's and finished wind-tunnel basic strategy --- src/log/Colleague.cpp | 4 ++-- src/log/Colleague.h | 2 +- src/log/Logistics.cpp | 25 ++++++++++++--------- src/log/Logistics.h | 4 ++-- src/log/Mediator.h | 2 +- src/rce/RacingDep.cpp | 26 +++++++++++----------- src/rce/RacingDep.h | 2 +- src/rce/carState/CarState.cpp | 2 +- src/rce/carState/CarStateDamaged.cpp | 2 +- src/rce/leaderboard/DriversLeaderboard.cpp | 2 +- src/rce/pitstop/ChangeTyre.cpp | 2 +- src/rce/pitstop/DriverPitStop.cpp | 6 ++--- src/rce/pitstop/PitCrew.cpp | 4 ++-- src/rce/pitstop/Pitstop.cpp | 12 +++++----- 14 files changed, 49 insertions(+), 46 deletions(-) diff --git a/src/log/Colleague.cpp b/src/log/Colleague.cpp index fe1ad1a..d6e7813 100644 --- a/src/log/Colleague.cpp +++ b/src/log/Colleague.cpp @@ -16,9 +16,9 @@ void Colleague::notify(std::vectorcars, Race* r) { logisticsDept->sendCarToFactory(cars, r); } -void Colleague::notify(Container *container) { +/*void Colleague::notify(Container *container) { logisticsDept->containerHasBeenPacked(container); -} +}*/ void Colleague::notify(bool isEuropeanRace) { //logisticsDept->requestContainerStateChange(isEuropeanRace); diff --git a/src/log/Colleague.h b/src/log/Colleague.h index 08b63b4..05658c6 100644 --- a/src/log/Colleague.h +++ b/src/log/Colleague.h @@ -20,7 +20,7 @@ namespace lg { void notify(std::vectorcars, Race*); - void notify(Container *container); + /*void notify(Container *container);*/ void notify(bool isEuropeanRace); diff --git a/src/log/Logistics.cpp b/src/log/Logistics.cpp index 018b095..b0aaeb5 100644 --- a/src/log/Logistics.cpp +++ b/src/log/Logistics.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -32,11 +33,11 @@ Logistics::Logistics(int numDriverCarPairs) { racingCalendar = nullptr; europeanContainer = nullptr; currentTeamStrategy = nullptr; + tyreSpecs = nullptr; budget = -1; } -Logistics::~Logistics() { -} +Logistics::~Logistics() = default; /** @@ -78,7 +79,7 @@ void Logistics::doYearPlanning() { //5. Hire drivers ppl::HireDriver driverCurator; for (int i = 0; i < numPairs; ++i) { - drivers.push_back(static_cast(driverCurator.hire("Driver"))); + drivers.push_back(dynamic_cast(driverCurator.hire("Driver"))); } //6. Set drivers' home tracks @@ -148,7 +149,7 @@ void Logistics::packContainers() { * @status She be done * @return Packed Container */ -Container *Logistics::packSingleContainer() { +Container *Logistics::packSingleContainer() const { Box *box = new Box(); auto *garageEquip = new GarageEquipment(budget); auto *cateringEquip = new CateringEquipment(budget); @@ -208,6 +209,7 @@ void Logistics::simulateEvent(Race *r) { } } if (!r->isRaceEuropean()) { + //TODO : check possible double-delete here delete tCont; //nonEuropeanContainer won't be used again } //else stay with the container @@ -396,24 +398,25 @@ void Logistics::sponsoredBudget(int sumPositions) { // =========================== MEDIATOR =========================== -//TODO : Strategy for using windTunnel; void Logistics::sendCarToFactory(std::vector cars, Race *r) { - int i = 0; - for (eng::Car *c: cars) { + + for (int i = 0; i < cars.size(); ++i) { + eng::Car* c = cars[i]; transportManager->transport(r, nullptr, c); - int performance = cars[i]->getSpeed() + cars[i++]->getHandling(); + int performance = cars[i]->getSpeed() + cars[i]->getHandling(); + // TODO : Check parameter at runtime ( & Improve strategy for using windTunnel) if (performance > 10) { callEngDept()->improveCar(c->getId(), false); } else { - callEngDept()->improveCar(c->getId(), true) + callEngDept()->improveCar(c->getId(), true); } } } //NOT STARTED - should transport container here -void Logistics::containerHasBeenPacked(Container *) { +/*void Logistics::containerHasBeenPacked(Container *) { cout << "fly container" << endl; -} +}*/ /** * @status Should be done diff --git a/src/log/Logistics.h b/src/log/Logistics.h index 5de9120..c3f50f0 100644 --- a/src/log/Logistics.h +++ b/src/log/Logistics.h @@ -44,7 +44,7 @@ namespace lg { void packContainers(); - Container* packSingleContainer(); + Container* packSingleContainer() const; void simulateEvent(Race *); @@ -71,7 +71,7 @@ namespace lg { Container *europeanContainer; //1 container for European rce::CreateStrategy *currentTeamStrategy; - rce::Tyres* tyreSpecs; //possibly unnecessary? No + rce::Tyres* tyreSpecs{}; //possibly unnecessary? No std::vector seasonPointTally; diff --git a/src/log/Mediator.h b/src/log/Mediator.h index 8c3741b..9547638 100644 --- a/src/log/Mediator.h +++ b/src/log/Mediator.h @@ -13,7 +13,7 @@ namespace lg { class Mediator { protected: -// virtual ~Mediator(); + virtual ~Mediator() = default; virtual void sendCarToFactory(std::vector, Race*) = 0; diff --git a/src/rce/RacingDep.cpp b/src/rce/RacingDep.cpp index 78c5fd7..98ec6ef 100644 --- a/src/rce/RacingDep.cpp +++ b/src/rce/RacingDep.cpp @@ -10,7 +10,7 @@ using namespace rce; void RacingDep::hireEmployees(int b) { - // TODO - implement RacingDep::HireWorker + // - implement RacingDep::HireWorker //throw "Not yet implemented"; } @@ -139,7 +139,7 @@ ppl::Driver *RacingDep::trainDriver(ppl::Driver *driver, int time, lg::WeatherCo }*/ void RacingDep::preRaceArrival(std::vector cars, std::vector, lg::Race *r, lg::Container *cont, Tyres *) { -// TODO - implement RacingDep::preRaceArrival +// - implement RacingDep::preRaceArrival this->CarContainer = cont; this->race = r; this->cars = cars; @@ -148,25 +148,25 @@ void RacingDep::preRaceArrival(std::vector cars, std::vector RacingDep::getStategist() { - // TODO - implement RacingDep::getStategist + // - implement RacingDep::getStategist throw "Not yet implemented"; } void RacingDep::setStategist(std::list Stategist) { - // TODO - implement RacingDep::setStategist + // - implement RacingDep::setStategist throw "Not yet implemented"; } @@ -225,7 +225,7 @@ void RacingDep::setPitcrew(std::list pitcrew) void RacingDep::SetCarAfterRace() { - // TODO - implement RacingDep::SetCarAfterRace + // - implement RacingDep::SetCarAfterRace throw "Not yet implemented"; } diff --git a/src/rce/RacingDep.h b/src/rce/RacingDep.h index 010272f..74b7b88 100644 --- a/src/rce/RacingDep.h +++ b/src/rce/RacingDep.h @@ -57,7 +57,7 @@ namespace rce { int* getFinalResults(); - // TODO : Besluit dalk watter funksies eintlik protected en private moet wees + // Besluit dalk watter funksies eintlik protected en private moet wees Leaderboard *getResults(); diff --git a/src/rce/carState/CarState.cpp b/src/rce/carState/CarState.cpp index f99a008..649e5db 100644 --- a/src/rce/carState/CarState.cpp +++ b/src/rce/carState/CarState.cpp @@ -16,7 +16,7 @@ void CarState::setDamage(int damage) { } void CarState::Deal_damage(int d) { - // TODO - implement carState::Deal damage + // implement carState::Deal damage throw "Not yet implemented"; } diff --git a/src/rce/carState/CarStateDamaged.cpp b/src/rce/carState/CarStateDamaged.cpp index 397cb4e..98213b1 100644 --- a/src/rce/carState/CarStateDamaged.cpp +++ b/src/rce/carState/CarStateDamaged.cpp @@ -3,7 +3,7 @@ using namespace rce; void CarStateDamaged::handleChange(int i, int d) { - // TODO - implement CarStateDamaged::handleChange + // - implement CarStateDamaged::handleChange throw "Not yet implemented"; } diff --git a/src/rce/leaderboard/DriversLeaderboard.cpp b/src/rce/leaderboard/DriversLeaderboard.cpp index 982c832..5de77f8 100644 --- a/src/rce/leaderboard/DriversLeaderboard.cpp +++ b/src/rce/leaderboard/DriversLeaderboard.cpp @@ -4,7 +4,7 @@ using namespace rce; /*void DriversLeaderboard::UpdateDriverLeaderBoard(String driverName, int Score) { - // TODO - implement DriversLeaderboard::UpdateDriverLeaderBoard + // - implement DriversLeaderboard::UpdateDriverLeaderBoard throw "Not yet implemented"; }*/ diff --git a/src/rce/pitstop/ChangeTyre.cpp b/src/rce/pitstop/ChangeTyre.cpp index 09457b5..441ce06 100644 --- a/src/rce/pitstop/ChangeTyre.cpp +++ b/src/rce/pitstop/ChangeTyre.cpp @@ -3,6 +3,6 @@ using namespace rce; void ChangeTyre::changetyres() { - // TODO - implement ChangeTyre::changetyres + // - implement ChangeTyre::changetyres throw "Not yet implemented"; } diff --git a/src/rce/pitstop/DriverPitStop.cpp b/src/rce/pitstop/DriverPitStop.cpp index cf6a514..a0dae56 100644 --- a/src/rce/pitstop/DriverPitStop.cpp +++ b/src/rce/pitstop/DriverPitStop.cpp @@ -3,7 +3,7 @@ using namespace rce; /*void DriverPitStop::tyres(int t, int compounds) { - // TODO - implement DriverPitStop::tyres + // implement DriverPitStop::tyres throw "Not yet implemented"; }*/ @@ -12,11 +12,11 @@ void DriverPitStop::setCar(eng::Car* c) { } void DriverPitStop::tyres(Tyres *t) { - // TODO - implement DriverPitStop::tyres + // - implement DriverPitStop::tyres throw "Not yet implemented"; } void DriverPitStop::race() { - // TODO - implement DriverPitStop::race + // - implement DriverPitStop::race throw "Not yet implemented"; } diff --git a/src/rce/pitstop/PitCrew.cpp b/src/rce/pitstop/PitCrew.cpp index 5261fa4..8b891fb 100644 --- a/src/rce/pitstop/PitCrew.cpp +++ b/src/rce/pitstop/PitCrew.cpp @@ -3,11 +3,11 @@ using namespace rce; PitCrew::PitCrew() { - // TODO - implement PitCrew::PitCrew + // - implement PitCrew::PitCrew throw "Not yet implemented"; } void PitCrew::setCar(RaceDaysIterator* c) { - // TODO - implement PitCrew::setCar + // - implement PitCrew::setCar throw "Not yet implemented"; } diff --git a/src/rce/pitstop/Pitstop.cpp b/src/rce/pitstop/Pitstop.cpp index 0c39a4f..1dc7d00 100644 --- a/src/rce/pitstop/Pitstop.cpp +++ b/src/rce/pitstop/Pitstop.cpp @@ -3,33 +3,33 @@ using namespace rce; void Pitstop::addCrew(std::list p) { -// TODO - implement Pitstop::addCrew +// - implement Pitstop::addCrew throw "Not yet implemented"; } void Pitstop::detachCrew(std::list p) { -// TODO - implement Pitstop::detachCrew +// - implement Pitstop::detachCrew throw "Not yet implemented"; } void Pitstop::tyres(Tyres* t) { - // TODO - implement Pitstop::tyres + // - implement Pitstop::tyres throw "Not yet implemented"; } void Pitstop::notify() { - // TODO - implement Pitstop::notify + // - implement Pitstop::notify throw "Not yet implemented"; } void Pitstop::setCar(eng::Car* c) { - // TODO - implement Pitstop::setCar + // - implement Pitstop::setCar throw "Not yet implemented"; } /* void Pitstop::race() { - // TODO - implement Pitstop::race + // - implement Pitstop::race throw "Not yet implemented"; } */ From e8acc01e0acfcb31058d791fd0821a29d176aa20 Mon Sep 17 00:00:00 2001 From: jo-anne Date: Thu, 5 Nov 2020 08:26:34 +0200 Subject: [PATCH 09/13] divided tasks --- src/log/Logistics.cpp | 83 ++++++++++++++++++++++--------------------- src/log/Mediator.h | 2 +- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/src/log/Logistics.cpp b/src/log/Logistics.cpp index b0aaeb5..d8e1a35 100644 --- a/src/log/Logistics.cpp +++ b/src/log/Logistics.cpp @@ -19,6 +19,8 @@ using namespace lg; +// TODO : @jo Implement and check accuracy of pop and push for cars + /** * @author Jo * @status Done and dusted! @@ -39,7 +41,6 @@ Logistics::Logistics(int numDriverCarPairs) { Logistics::~Logistics() = default; - /** * @status completed * @param colleague @@ -56,7 +57,6 @@ void Logistics::registerNotifier(Colleague *colleague) { } - /** * @author Jo * @status really finished @@ -104,7 +104,8 @@ void Logistics::doYearPlanning() { void Logistics::preSeasonPreparation() { // 1. Get strategy currentTeamStrategy = callRacingDept()->PlanSeasonStrategy(budget); - pr::Doc::detail("The Strategists of the " + callRacingDept()->getTeamName() + " team have decided on a strategy: " + currentTeamStrategy->getStratName()); + pr::Doc::detail("The Strategists of the " + callRacingDept()->getTeamName() + " team have decided on a strategy: " + + currentTeamStrategy->getStratName()); // 1.1 Notified about tyres (in the meanwhile) // 1.2 Receive Order @@ -141,7 +142,7 @@ void Logistics::packContainers() { nonEuropeanContainers.push_back(packSingleContainer()); } } - cout << "Packed all containers" << endl; + pr::Doc::summary("Packed all containers\n"); } /** @@ -181,7 +182,7 @@ void Logistics::simulateEvent(Race *r) { pr::Doc::detail(r->getLocation()); //Transport drivers - // TODO : add fly functionality for drivers + //todolist : add fly functionality for drivers //3. get correct container, transport and fly and fly @@ -201,15 +202,15 @@ void Logistics::simulateEvent(Race *r) { //5. finish the packup Container *tCont = callRacingDept()->postRacePackUp(); //6. Transport drivers on and container back - if (r->nextRace()== nullptr) { - pr::Doc::detail ("The drivers are transported in a luxury mode of transport back to HQ"); + if (r->nextRace() == nullptr) { + pr::Doc::detail("The drivers are transported in a luxury mode of transport back to HQ"); transportManager->transport(r, nullptr); if (r->isRaceEuropean()) { delete tCont; //we need to get rid of it. } } if (!r->isRaceEuropean()) { - //TODO : check possible double-delete here + //TODO : @jo check possible double-delete here delete tCont; //nonEuropeanContainer won't be used again } //else stay with the container @@ -245,7 +246,7 @@ void Logistics::putRacesIntoCalender() { } infile.close(); } else { //exception e - std::cout << "There was a file-reading error !\n"; + std::cout << "There was a file-reading error !\n"; //die bly 'n cout aangesien dit 'n ernstige probleem is throw "Error"; } @@ -261,17 +262,15 @@ void Logistics::raceSeason() { } } - -//NOT STARTED -// TODO : get leaderboard from racingDept and decide accordingly void Logistics::postSeasonDebrief() { //1. Get results - int *tumTumTum = callRacingDept()->getFinalResults(); + int *tumTumTum = callRacingDept()->getFinalResults(); //structure: {points_d1, final_pos_d1, points_d2, final_pos_d2 //2. Flashy results - //Decorator here? + // TODO: @marike Flashy results based on leaderboard (maybe racing is doing that? I'll check with them during merging) //3. let transportManager take a holiday + //TODO: @marike cout some cool stuff delete transportManager; //4. Let driver take a holiday @@ -279,19 +278,19 @@ void Logistics::postSeasonDebrief() { for (int i = 0; i < numPairs; ++i) { ppl::Driver *d = drivers.back(); drivers.pop_back(); - if (tumTumTum[2*i+1] >= 3) { - pr::Doc::detail(d->getName() + " takes a well-earned holiday near Malibu\n"); + if (tumTumTum[2 * i + 1] >= 3) { + pr::Doc::detail(d->getName() + " loses all his winning money while on a holiday in Vegas\n"); } else { pr::Doc::detail(d->getName() + " is tactfully offered a retirement package\n"); } - sumPositions += tumTumTum[2*i+1]; - + sumPositions += tumTumTum[2 * i + 1]; } //5. Get some sponsors again. sponsoredBudget(sumPositions); //5. start building a new car? + // TODO : @jo NB NB NB Adjust whole flow for cross-season functionality pr::Doc::summary("Start working on a new car"); for (int i = 0; i < numPairs; ++i) { carsInSeasonIDs.push_back(callEngDept()->buildCar(budget)); @@ -321,7 +320,6 @@ Container *Logistics::getNextNonEuropean() { return back; } - /** * @author Jo * @return RacingDept Instance @@ -341,30 +339,35 @@ eng::EngTeam *Logistics::callEngDept() { } -//TODO : Decide on regime based on riskLevel //IDEA: Change to command? void Logistics::driverBootCamp() { -/*moet meer spesifiek wees hierso. gaan ons van hulle verwag of gaan ons self check dat die driver genoeg xp het? - Dalk kan ons dit volgens riskLevel doen*/ + //todolist : Check runtime accuracy of regime switch (currentTeamStrategy->getRiskLevel()) { case Safe: - //time higher - //more weather conditions - //higher time complexity - //worse weather condtions + for (ppl::Driver *d: drivers) { + callRacingDept()->trainDriver(d, abs(rand() % 50 + 51), Hot, Difficult); //interval [50,100] + callRacingDept()->trainDriver(d, abs(rand() % 50 + 51), Rainy, Extreme); + callRacingDept()->trainDriver(d, abs(rand() % 50 + 51), Hot, Extreme); + callRacingDept()->trainDriver(d,abs(rand() % 50 + 51), Rainy, Difficult); + } + //time higher, more weather conditions, higher track complexity, worse weather condtions break; case Moderate: - + for (ppl::Driver *d: drivers) { + callRacingDept()->trainDriver(d, abs(rand() % 30 + 51), Normal, Difficult); //interval [30,80] + callRacingDept()->trainDriver(d, abs(rand() % 30 + 51), Rainy, Average); + callRacingDept()->trainDriver(d, abs(rand() % 30 + 51), Hot, Easy); + } + //medium time, range of weather conditions, middling track complexity break; case Aggressive: - + for (ppl::Driver* d: drivers) { + callRacingDept()->trainDriver(d, abs(rand() % 100 + 1), randomWC(), randomTL()); //interval [1,100] + callRacingDept()->trainDriver(d, abs(rand() % 100 + 1), randomWC(), randomTL()); + callRacingDept()->trainDriver(d, abs(rand() % 100 + 1), randomWC(), randomTL()); + } + //any time,any weather, any track break; - - } - -for (ppl::Driver *d: drivers) { - //randomise weathering - callRacingDept()->trainDriver(d, rand() % 10 + 1, randomWC(), randomTL()); } } @@ -374,14 +377,13 @@ void Logistics::sponsoredBudget(int sumPositions) { if (budget == 0) { //default argument budget = abs(rand() % 100 + 1); - } - else { + } else { if (sumPositions >= 3) { pr::Doc::detail("Rolex is the team's next sponsor! Budget increases wildly\n"); - budget = max((int) ((double) budget * 1.5),(100- (int) ((double) budget * 0.5))) ; + budget = max((int) ((double) budget * 1.5), (100 - (int) ((double) budget * 0.5))); } else if (sumPositions <= 6) { pr::Doc::detail("Emirates is the team's next sponsor! Budget increases wildly\n"); - budget = max((int) ((double) budget * 0.2),(80- (int) ((double) budget * 0.2))); + budget = max((int) ((double) budget * 0.2), (80 - (int) ((double) budget * 0.2))); } else if (sumPositions <= 10) { pr::Doc::detail("The sponsor is satisfied with the performance"); } else { @@ -401,10 +403,10 @@ void Logistics::sponsoredBudget(int sumPositions) { void Logistics::sendCarToFactory(std::vector cars, Race *r) { for (int i = 0; i < cars.size(); ++i) { - eng::Car* c = cars[i]; + eng::Car *c = cars[i]; transportManager->transport(r, nullptr, c); int performance = cars[i]->getSpeed() + cars[i]->getHandling(); - // TODO : Check parameter at runtime ( & Improve strategy for using windTunnel) + // todolist : Check parameter at runtime ( & Improve strategy for using windTunnel) if (performance > 10) { callEngDept()->improveCar(c->getId(), false); } else { @@ -413,7 +415,6 @@ void Logistics::sendCarToFactory(std::vector cars, Race *r) { } } -//NOT STARTED - should transport container here /*void Logistics::containerHasBeenPacked(Container *) { cout << "fly container" << endl; }*/ diff --git a/src/log/Mediator.h b/src/log/Mediator.h index 9547638..904208b 100644 --- a/src/log/Mediator.h +++ b/src/log/Mediator.h @@ -17,7 +17,7 @@ namespace lg { virtual void sendCarToFactory(std::vector, Race*) = 0; - virtual void containerHasBeenPacked(Container *) = 0; + //virtual void containerHasBeenPacked(Container *) = 0; //virtual void requestContainerStateChange(bool isEuropeanRace) = 0; From ebc67db1f38d3e47f7c105f26953839c27861ab8 Mon Sep 17 00:00:00 2001 From: jo-anne Date: Thu, 5 Nov 2020 08:54:24 +0200 Subject: [PATCH 10/13] feat: allow for broken cars to be shipped --- src/log/Colleague.cpp | 9 ++++++++- src/log/Colleague.h | 2 ++ src/log/Logistics.cpp | 33 +++++++++++++++++++++------------ src/log/Logistics.h | 4 ++-- src/log/Mediator.h | 2 +- src/main.cpp | 2 +- 6 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/log/Colleague.cpp b/src/log/Colleague.cpp index d6e7813..d6d58bb 100644 --- a/src/log/Colleague.cpp +++ b/src/log/Colleague.cpp @@ -13,9 +13,16 @@ void Colleague::addObserver(Mediator *obs) { } void Colleague::notify(std::vectorcars, Race* r) { - logisticsDept->sendCarToFactory(cars, r); + logisticsDept->sendCarToFactory(cars, r, false); } +void Colleague::notify(eng::Car *broken, Race *r) { + std::vector brokenCar; + brokenCar.push_back(broken); + logisticsDept->sendCarToFactory(brokenCar, r, true) +} + + /*void Colleague::notify(Container *container) { logisticsDept->containerHasBeenPacked(container); }*/ diff --git a/src/log/Colleague.h b/src/log/Colleague.h index 05658c6..3230ad3 100644 --- a/src/log/Colleague.h +++ b/src/log/Colleague.h @@ -20,6 +20,8 @@ namespace lg { void notify(std::vectorcars, Race*); + void notify(eng::Car* brokenCar, Race*); + /*void notify(Container *container);*/ void notify(bool isEuropeanRace); diff --git a/src/log/Logistics.cpp b/src/log/Logistics.cpp index d8e1a35..e630920 100644 --- a/src/log/Logistics.cpp +++ b/src/log/Logistics.cpp @@ -182,7 +182,7 @@ void Logistics::simulateEvent(Race *r) { pr::Doc::detail(r->getLocation()); //Transport drivers - //todolist : add fly functionality for drivers + //IDEA : add fly functionality for drivers //3. get correct container, transport and fly and fly @@ -400,17 +400,26 @@ void Logistics::sponsoredBudget(int sumPositions) { // =========================== MEDIATOR =========================== -void Logistics::sendCarToFactory(std::vector cars, Race *r) { - - for (int i = 0; i < cars.size(); ++i) { - eng::Car *c = cars[i]; - transportManager->transport(r, nullptr, c); - int performance = cars[i]->getSpeed() + cars[i]->getHandling(); - // todolist : Check parameter at runtime ( & Improve strategy for using windTunnel) - if (performance > 10) { - callEngDept()->improveCar(c->getId(), false); - } else { - callEngDept()->improveCar(c->getId(), true); +void Logistics::sendCarToFactory(std::vector cars, Race *r, bool isBroken) { + if (isBroken) { + for (int i = 0; i < cars.size(); ++i) { + transportManager->transport(r, nullptr, cars[0]); + callEngDept()->carArrivesAtFactory(cars[0]); + callEngDept()->fixCar(cars[0]->getId()); + callEngDept()->improveCar(cars[0]->getId(), true); + } + } + else { + for (int i = 0; i < cars.size(); ++i) { + transportManager->transport(r, nullptr, cars[i]); + callEngDept()->carArrivesAtFactory(cars[i]); + int performance = cars[i]->getSpeed() + cars[i]->getHandling(); + // todolist : Check parameter at runtime ( & Improve strategy for using windTunnel) + if (performance > 10) { + callEngDept()->improveCar(cars[i]->getId(), false); + } else { + callEngDept()->improveCar(cars[i]->getId(), true); + } } } } diff --git a/src/log/Logistics.h b/src/log/Logistics.h index c3f50f0..3ad6445 100644 --- a/src/log/Logistics.h +++ b/src/log/Logistics.h @@ -34,9 +34,9 @@ namespace lg { void postSeasonDebrief(); protected: - void sendCarToFactory(std::vector, Race*) override; + void sendCarToFactory(std::vector, Race*, bool isBroken) override; - void containerHasBeenPacked(Container *) override; + //void containerHasBeenPacked(Container *) override; Container *getEuropeanContainer(); diff --git a/src/log/Mediator.h b/src/log/Mediator.h index 904208b..4e31052 100644 --- a/src/log/Mediator.h +++ b/src/log/Mediator.h @@ -15,7 +15,7 @@ namespace lg { protected: virtual ~Mediator() = default; - virtual void sendCarToFactory(std::vector, Race*) = 0; + virtual void sendCarToFactory(std::vector cars, Race* currentRace, bool isBroken) = 0; //virtual void containerHasBeenPacked(Container *) = 0; diff --git a/src/main.cpp b/src/main.cpp index a853af9..9158838 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -76,7 +76,7 @@ void seasonRun() { eng::Car* car = engDept->checkCarOutOfFactory(id); car->print();*/ - + engDept. } From d12d89632c054b3e421e516e16368c85760cfe3e Mon Sep 17 00:00:00 2001 From: jo-anne Date: Thu, 5 Nov 2020 10:40:39 +0200 Subject: [PATCH 11/13] fix: memleaks in race/iterator --- src/log/Colleague.cpp | 2 +- src/log/Logistics.cpp | 34 +++++++++++----- src/log/Logistics.h | 2 +- src/log/races/Race.cpp | 2 + src/log/races/Race.h | 2 + src/log/races/RaceIterator.cpp | 1 - src/log/races/RacesList.cpp | 10 +++++ src/log/races/RacesList.h | 6 +-- src/main.cpp | 74 ++++++++++++++++++++-------------- 9 files changed, 87 insertions(+), 46 deletions(-) diff --git a/src/log/Colleague.cpp b/src/log/Colleague.cpp index d6d58bb..aa85f59 100644 --- a/src/log/Colleague.cpp +++ b/src/log/Colleague.cpp @@ -19,7 +19,7 @@ void Colleague::notify(std::vectorcars, Race* r) { void Colleague::notify(eng::Car *broken, Race *r) { std::vector brokenCar; brokenCar.push_back(broken); - logisticsDept->sendCarToFactory(brokenCar, r, true) + logisticsDept->sendCarToFactory(brokenCar, r, true); } diff --git a/src/log/Logistics.cpp b/src/log/Logistics.cpp index e630920..2000ed2 100644 --- a/src/log/Logistics.cpp +++ b/src/log/Logistics.cpp @@ -20,6 +20,9 @@ using namespace lg; // TODO : @jo Implement and check accuracy of pop and push for cars +// IDEA : approach budget people in the middle to ask for raise? +// IDEA : use up the budget +// TODO : @both fix memleaks /** * @author Jo @@ -31,7 +34,6 @@ Logistics::Logistics(int numDriverCarPairs) { carsInSeasonIDs.reserve(numDriverCarPairs); seasonPointTally.reserve(numDriverCarPairs); transportManager = nullptr; - raceIterator = nullptr; racingCalendar = nullptr; europeanContainer = nullptr; currentTeamStrategy = nullptr; @@ -39,7 +41,16 @@ Logistics::Logistics(int numDriverCarPairs) { budget = -1; } -Logistics::~Logistics() = default; +// TODO : @jo finish destructor +Logistics::~Logistics(){ + if (transportManager) delete transportManager; + if (racingCalendar) { + //delete accordingly + } + if (europeanContainer) delete europeanContainer; + if (currentTeamStrategy) delete currentTeamStrategy; + if (tyreSpecs) delete tyreSpecs; +}; /** * @status completed @@ -67,6 +78,7 @@ void Logistics::doYearPlanning() { //2. Hire emplpoyees: each department for (auto const&[key, val] : departments) { + //TODO : check by departemente - kan julle dit hanteer dat ons re-hire gegewe 'n tweede seisoen? val->hireEmployees(budget); } @@ -178,14 +190,11 @@ void Logistics::simulateEvent(Race *r) { } //2. Transport Drivers + //IDEA : add fly functionality for drivers pr::Doc::detail("The two drivers are transported in a luxury mode of transport to "); pr::Doc::detail(r->getLocation()); - //Transport drivers - //IDEA : add fly functionality for drivers - //3. get correct container, transport and fly and fly - transportManager->transport(r->prevRace(), r); if (r->isRaceEuropean()) { callRacingDept()->preRaceArrival(carClipboard, drivers, r, getEuropeanContainer(), tyreSpecs); @@ -218,7 +227,7 @@ void Logistics::simulateEvent(Race *r) { /** * @author Jo - * @status nearly there + * @status I wash my hands off this one */ void Logistics::putRacesIntoCalender() { racingCalendar = new RacesList; @@ -257,8 +266,13 @@ void Logistics::putRacesIntoCalender() { void Logistics::raceSeason() { //And the season starts pr::Doc::summary("And the season begins!"); + int developTracker = 0; for (RaceIterator t = racingCalendar->begin(); !(t == racingCalendar->end()); ++t) { simulateEvent(t.currentItem()); + developTracker++; + if (developTracker==7 || developTracker==14) { //third of the way through + carsInDevIDs.push_back(callEngDept()->buildCar(budget)); + } } } @@ -371,13 +385,14 @@ void Logistics::driverBootCamp() { } } -void Logistics::sponsoredBudget(int sumPositions) { +void Logistics::sponsoredBudget(int sumPositions) { //default is 0 pr::Doc::summary("Approaching sponsors to negotiate a new budget\n"); - if (budget == 0) { //default argument + if (budget == -1) { //default argument in constructor budget = abs(rand() % 100 + 1); } else { + //todolist : check accuracy at runtime if (sumPositions >= 3) { pr::Doc::detail("Rolex is the team's next sponsor! Budget increases wildly\n"); budget = max((int) ((double) budget * 1.5), (100 - (int) ((double) budget * 0.5))); @@ -403,6 +418,7 @@ void Logistics::sponsoredBudget(int sumPositions) { void Logistics::sendCarToFactory(std::vector cars, Race *r, bool isBroken) { if (isBroken) { for (int i = 0; i < cars.size(); ++i) { + // TODO: @marike descriptionality of the rush to get the car fixed transportManager->transport(r, nullptr, cars[0]); callEngDept()->carArrivesAtFactory(cars[0]); callEngDept()->fixCar(cars[0]->getId()); diff --git a/src/log/Logistics.h b/src/log/Logistics.h index 3ad6445..2dc0df5 100644 --- a/src/log/Logistics.h +++ b/src/log/Logistics.h @@ -64,9 +64,9 @@ namespace lg { std::vector drivers; TransportHandler *transportManager; //Won't be holding a handle to car as will always be passing directly from one place to another - RaceIterator *raceIterator; RacesList *racingCalendar; std::vector carsInSeasonIDs; + std::vector carsInDevIDs; std::vector nonEuropeanContainers; //lots of containers for non-European Container *europeanContainer; //1 container for European rce::CreateStrategy *currentTeamStrategy; diff --git a/src/log/races/Race.cpp b/src/log/races/Race.cpp index 638c02d..ce0d0f9 100644 --- a/src/log/races/Race.cpp +++ b/src/log/races/Race.cpp @@ -102,6 +102,8 @@ int Race::getTrackID() { return id; } +Race::~Race() = default; + /*std::ostream &lg::operator<<(std::ostream &os, const Race &rc) { os << rc.location << '/nEurope: ' << rc.isInEurope << '/nNumLaps: ' << rc.numLaps << std::endl; return os; diff --git a/src/log/races/Race.h b/src/log/races/Race.h index c61f678..787054b 100644 --- a/src/log/races/Race.h +++ b/src/log/races/Race.h @@ -26,6 +26,8 @@ namespace lg { Race(std::string, int complexity, bool inEU, int laps, Race *next = nullptr, Race *prev = nullptr); + ~Race(); + void setNextRace(Race *); void setPrevRace(Race *); diff --git a/src/log/races/RaceIterator.cpp b/src/log/races/RaceIterator.cpp index 9d07846..ef34d14 100644 --- a/src/log/races/RaceIterator.cpp +++ b/src/log/races/RaceIterator.cpp @@ -21,7 +21,6 @@ void RaceIterator::first() { current = head; } -//RaceIterator RaceIterator::operator++() { void RaceIterator::operator++() { if (this != nullptr) { this->current = this->current->nextRace(); diff --git a/src/log/races/RacesList.cpp b/src/log/races/RacesList.cpp index 2c7df0c..3cca13a 100644 --- a/src/log/races/RacesList.cpp +++ b/src/log/races/RacesList.cpp @@ -7,6 +7,7 @@ #include "Doc.h" namespace lg { + // TODO : find suitable spot for this function std::string convertComplexityToString(TrackComplexity t) { switch (t) { case Easy: @@ -28,6 +29,15 @@ RacesList::RacesList() { numRaces = 0; } +RacesList::~RacesList() { + for (RaceIterator t = begin(); !(t == end()); ) { + Race* temp = t.currentItem(); + ++t; + delete temp; + } + +} + //IS DONE? void RacesList::addRace(Race *race) { if (isEmpty()) { diff --git a/src/log/races/RacesList.h b/src/log/races/RacesList.h index 154679b..9226873 100644 --- a/src/log/races/RacesList.h +++ b/src/log/races/RacesList.h @@ -10,18 +10,16 @@ #include "RaceIterator.h" namespace lg { -//class RacesList : public Aggregate { class RacesList { friend class RaceIterator; public: -// RaceIterator createIterator() override; RacesList(); - //RaceIterator createIterator(); + ~RacesList(); + void addRace(Race *); - //Race* removeRace(); Race *getHeadRace() const; bool isEmpty(); diff --git a/src/main.cpp b/src/main.cpp index 9158838..889b58d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "ppl/factories/KidnapStudent.h" #include "eng/EngTeam.h" #include "rce/RacingDep.h" @@ -18,23 +19,52 @@ int pr::Doc::transparency = 1; void logDeptTesting(); void engTeamTesting(); -void seasonRun(); +void seasonRun(lg::Logistics*); void testTyres(); - +void proto_FinalMain(); int main() { - //logDeptTesting(); + logDeptTesting(); //engTeamTesting(); - seasonRun(); + //seasonRun(); + // proto_FinalMain(); // testTyres(); + + } -void logDeptTesting() { +void proto_FinalMain() { auto* racingDept = new rce::RacingDep(); auto* engDept = new eng::EngTeam; + auto* logDept = new lg::Logistics; + + srand(time(0)); + logDept->registerNotifier(racingDept); + logDept->registerNotifier(engDept); + + seasonRun(logDept); + + delete racingDept; + delete engDept; + delete logDept; + +} + + +void seasonRun(lg::Logistics* a) { + a->doYearPlanning(); + a->preSeasonPreparation(); + a->raceSeason(); + a->postSeasonDebrief(); +} + +void logDeptTesting() { + //Testing containers + /* auto* racingDept = new rce::RacingDep(); + auto* engDept = new eng::EngTeam; auto* a = new lg::Logistics; lg::TransportHandler* curator = new lg::Road; @@ -53,33 +83,17 @@ void logDeptTesting() { delete racingDept; delete engDept; - delete a; + delete a;*/ + //Testing racingCalender destructor + lg::RacesList* r = new lg::RacesList; + r->addRace(new lg::Race("Australia", 0, 0,12)); + r->addRace(new lg::Race("Benoni", 1, 1,21)); + r->addRace(new lg::Race("Cambridge", 2, 0,112)); + r->addRace(new lg::Race("Dallas", 0, 1,212)); + r->printList(); + delete r; } -void seasonRun() { - auto* racingDept = new rce::RacingDep(); - auto* engDept = new eng::EngTeam; - auto* a = new lg::Logistics; - a->registerNotifier(racingDept); - a->registerNotifier(engDept); - a->doYearPlanning(); - a->preSeasonPreparation(); - a->raceSeason(); - a->postSeasonDebrief(); - delete racingDept; - delete engDept; - delete a; - /*engDept->hireEmployees(50); - engDept->resetTickets(); - engDept->setRiskLevel(lg::Aggressive); - int id = engDept->buildCar(50); - eng::Car* car = engDept->checkCarOutOfFactory(id); - car->print();*/ - - engDept. - - -} void engTeamTesting() { auto *e = new eng::EngTeam(); From e9605de3294be344fb7552ca06ab6c80ec7d7e5c Mon Sep 17 00:00:00 2001 From: Siocnarff Date: Thu, 5 Nov 2020 11:59:07 +0200 Subject: [PATCH 12/13] add check if null to ComponentSimulator --- src/eng/buildings/ComponentSimulator.cpp | 3 +++ src/main.cpp | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/eng/buildings/ComponentSimulator.cpp b/src/eng/buildings/ComponentSimulator.cpp index e1067d2..9fe20fe 100644 --- a/src/eng/buildings/ComponentSimulator.cpp +++ b/src/eng/buildings/ComponentSimulator.cpp @@ -3,6 +3,9 @@ using namespace eng; void ComponentSimulator::testComponent(Component* component) { + if (!component) { + return; + } int label = component->quality; label += (rand()%5)-2; if (label > 100) { diff --git a/src/main.cpp b/src/main.cpp index 889b58d..0282bd3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,11 +25,11 @@ void proto_FinalMain(); int main() { - logDeptTesting(); + //logDeptTesting(); //engTeamTesting(); //seasonRun(); - // proto_FinalMain(); -// testTyres(); + proto_FinalMain(); + //testTyres(); From e7bd1f12770683103571536cd38bb5152e2e4b2b Mon Sep 17 00:00:00 2001 From: Siocnarff Date: Thu, 5 Nov 2020 12:00:18 +0200 Subject: [PATCH 13/13] add check if null to ComponentSimulator --- src/eng/buildings/ComponentSimulator.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/eng/buildings/ComponentSimulator.cpp b/src/eng/buildings/ComponentSimulator.cpp index 9fe20fe..4485e48 100644 --- a/src/eng/buildings/ComponentSimulator.cpp +++ b/src/eng/buildings/ComponentSimulator.cpp @@ -3,9 +3,6 @@ using namespace eng; void ComponentSimulator::testComponent(Component* component) { - if (!component) { - return; - } int label = component->quality; label += (rand()%5)-2; if (label > 100) { @@ -21,7 +18,9 @@ void ComponentSimulator::testComponent(Component* component) { void ComponentSimulator::testComponents(Car* car) { for (Component* component : car->components) { - testComponent(component); + if (component) { + testComponent(component); + } } pr::Doc::detail("Components of car "); pr::Doc::detail(std::to_string(car->getId()));