Creepy-simulation
 
Loading...
Searching...
No Matches
SimulationFabric.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4
5#include "Creeper.hpp"
6#include "FieldParams.hpp"
7#include "Simulation.hpp"
8#include "Steve.hpp"
14 std::shared_ptr<FieldParams> fieldParams_;
15 std::shared_ptr<CreepersParams> CreepersParams_;
16 std::shared_ptr<StevesParams> StevesParams_;
17
18 public:
22 SimulationFabric() = default;
29 SimulationFabric& setFieldParams(const Rectangle& bounds, const std::function<double(Point p1, Point p2)>& distanceFunc) {
30 fieldParams_ = std::make_shared<FieldParams>(bounds, distanceFunc);
31 return *this;
32 }
38 decltype(fieldParams_) getFieldParams() {
39 if (!fieldParams_) throw std::invalid_argument("FieldParams_ is not set");
40 return fieldParams_;
41 }
50 SimulationFabric& setCreeperParams(double moveRadius = 10, double explodeRadius = 10, uint32_t count = 0) {
51 if (!fieldParams_) {
52 throw std::invalid_argument("fieldParams_ is not set");
53 }
54 CreepersParams_ = std::make_shared<CreepersParams>(moveRadius, explodeRadius, fieldParams_, count);
55 return *this;
56 }
57 decltype(CreepersParams_) getCreepersParams_() {
58 if (!CreepersParams_) throw std::invalid_argument("CreepersParams_ is not set");
59 return CreepersParams_;
60 }
68 SimulationFabric& setSteveParams(double moveRadius = 10, uint32_t count = 0) {
69 if (!fieldParams_) {
70 throw std::invalid_argument("fieldParams_ is not set");
71 }
72 StevesParams_ = std::make_shared<StevesParams>(moveRadius, fieldParams_, count);
73 return *this;
74 }
75
76 decltype(StevesParams_) getStevesParams_() {
77 if (!StevesParams_) throw std::invalid_argument("StevesParams_ is not set");
78 return StevesParams_;
79 }
80
82 const auto upBound = fieldParams_->getBounds().rightUpBound;
83 const auto downBound = fieldParams_->getBounds().leftDownBound;
84 if (bedrock.rightUpBound.x > upBound.x || bedrock.rightUpBound.y > upBound.y ||
85 bedrock.leftDownBound.x < downBound.x || bedrock.leftDownBound.y < downBound.y) {
86 LOG(WARNING) << "Bedrock is out of field bounds!";
87 }
88 fieldParams_->setBedrock(bedrock);
89 return *this;
90 }
91
93 if (!CreepersParams_) setCreeperParams();
94 if (!StevesParams_) setSteveParams();
95 return Simulation(fieldParams_, CreepersParams_, StevesParams_);
96 }
97};
A factory class for configuring and creating Simulation objects.
Definition SimulationFabric.hpp:13
SimulationFabric()=default
Default constructor for SimulationFabric.
decltype(fieldParams_) getFieldParams()
Retrieves the field parameters.
Definition SimulationFabric.hpp:38
SimulationFabric & setBedrock(const Rectangle &bedrock)
Definition SimulationFabric.hpp:81
SimulationFabric & setCreeperParams(double moveRadius=10, double explodeRadius=10, uint32_t count=0)
Sets the parameters for creepers in the simulation.
Definition SimulationFabric.hpp:50
SimulationFabric & setSteveParams(double moveRadius=10, uint32_t count=0)
Sets the parameters for Steves in the simulation.
Definition SimulationFabric.hpp:68
Simulation build()
Definition SimulationFabric.hpp:92
decltype(CreepersParams_) getCreepersParams_()
Definition SimulationFabric.hpp:57
SimulationFabric & setFieldParams(const Rectangle &bounds, const std::function< double(Point p1, Point p2)> &distanceFunc)
Sets the field parameters for the simulation.
Definition SimulationFabric.hpp:29
decltype(StevesParams_) getStevesParams_()
Definition SimulationFabric.hpp:76
Main controller for managing the simulation of creepers and Steves.
Definition Simulation.hpp:16
Represents a 2D point with x and y coordinates.
Definition utils.hpp:10
Represents a rectangle defined by two points: bottom-left and top-right.
Definition utils.hpp:24