78 Entity(
size_t t_id,
const int t_worldSize,
const types::Trait &t_traits, std::vector<Food> *t_foods,
79 size_t t_cycleBornAt);
83 void update(
const float elapsedTime);
96 void walk(
float elapsedTime);
97 void move(
float elapsedTime);
128 Cycle(std::vector<Entity> *t_entities, std::vector<Entity>::iterator *t_entitiesEndIter,
size_t t_worldSize,
129 std::vector<Food> *t_foods,
size_t t_cycleId,
size_t *t_lastEntityId);
134 static void reproduceEntities(std::vector<Entity> &entities, std::vector<Entity>::iterator &entitiesEndIt,
135 size_t *lastEntityId,
size_t cycleId, std::vector<Food> *foods);
146 void update(
float elapsedTime);
177 [[nodiscard]]
static std::span<Entity>
getActiveEntities(std::vector<Entity> &entities,
178 std::vector<Entity>::iterator &iter);
179 const std::vector<Food> &
getFoods()
const;
190 void update(
float elapsedTime);
A class representing a single cycle in the simulation.
Definition: simulation.h:113
static void randomizeFoodPositions(std::span< Food > foods, size_t worldSize)
Redistributes the food particles on the board.
Definition: simulation.cpp:544
std::span< Entity > activeEntities
Definition: simulation.h:116
std::vector< Entity >::iterator * m_entitiesEndIter
Definition: simulation.h:115
size_t m_cycleId
Definition: simulation.h:123
size_t m_worldSize
Definition: simulation.h:121
static void handleFoodCount(std::vector< Food > &foods, int changeBy)
Definition: simulation.cpp:532
static void distributeEntities(std::span< Entity > entities, size_t wallSize)
Determines if there is enough space for equal distribution and calls the appropriate function.
Definition: simulation.cpp:520
static void randomEntitiesDistribution(std::span< Entity > entities, size_t wallSize)
Distributes entities randomly on the edges of the board.
Definition: simulation.cpp:475
static void reproduceEntities(std::vector< Entity > &entities, std::vector< Entity >::iterator &entitiesEndIt, size_t *lastEntityId, size_t cycleId, std::vector< Food > *foods)
Reproduces all entities that should reproduce with random traits inherited from their parent.
Definition: simulation.cpp:379
bool m_isCycleDone
Definition: simulation.h:124
size_t * m_lastEntityId
Definition: simulation.h:117
void update(float elapsedTime)
Updates the current cycle.
Definition: simulation.cpp:558
Cycle()
Necessary default constructor.
Definition: simulation.cpp:327
static void equalEntitiesDistribution(std::span< Entity > entities, size_t wallSize)
Distributes entities with equal spacing on the board.
Definition: simulation.cpp:417
std::vector< Entity > * m_entities
Definition: simulation.h:114
std::vector< Food > * m_foods
Definition: simulation.h:119
void CycleEnd()
Prepares the entities for the next cycle.
Definition: simulation.cpp:345
A class representing a single entity in the simulation.
Definition: simulation.h:45
void walk(float elapsedTime)
Handles special turning logic.
Definition: simulation.cpp:226
Entity(size_t t_id, const int t_worldSize, const types::Trait &t_traits, std::vector< Food > *t_foods, size_t t_cycleBornAt)
Definition: simulation.cpp:9
float getFacingAngle() const
Getter for facing angle.
Definition: simulation.cpp:317
int m_worldSize
Definition: simulation.h:48
void update(const float elapsedTime)
Update the entity.
Definition: simulation.cpp:22
size_t m_cycleDiedAt
Definition: simulation.h:54
float m_timeSinceLastTurn
Definition: simulation.h:61
float m_turningAngle
Definition: simulation.h:60
size_t m_cycleBornAt
Definition: simulation.h:52
void hanldeEnergy(const float elapsedTime)
Handles the energy depletion of the entity.
Definition: simulation.cpp:212
const types::fVec2 & getPos() const
Getter for position.
Definition: simulation.cpp:307
void reset()
Prepares the entity for the next cycle.
Definition: simulation.cpp:198
float m_energyMax
Definition: simulation.h:65
types::fVec2 m_pos
Definition: simulation.h:56
bool handleFoodCollision(const float elapsedTime)
Handles everything regarding food collision.
Definition: simulation.cpp:179
float getAngleToClosestWall()
Returns the angle to the closest wall to the entity.
Definition: simulation.cpp:122
types::EntityTarget getBrain() const
Peek into an entity's thoughts.
Definition: simulation.cpp:282
bool m_isDoneWithCycle
Definition: simulation.h:72
static constexpr float traitPadding
Definition: simulation.h:69
bool isOutOfBounds() const
Checks if the entity is outside the bounds of the board.
Definition: simulation.cpp:160
float m_maxTurnAngle
Definition: simulation.h:58
void generateNewTurningAngle()
Sets the turning angle to a new random value that's less than the max turning angle.
Definition: simulation.cpp:152
float m_turnRate
Definition: simulation.h:57
std::vector< Food > * m_foods
Definition: simulation.h:49
void move(float elapsedTime)
Moves the entity in it's facing direction.
Definition: simulation.cpp:260
Food * m_targetFood
Definition: simulation.h:63
bool m_shouldReproduce
Definition: simulation.h:73
size_t m_cyclesLived
Definition: simulation.h:53
float m_facingAngle
Definition: simulation.h:59
bool m_isAlive
Definition: simulation.h:71
types::Trait m_traits
Definition: simulation.h:68
size_t m_id
Definition: simulation.h:51
std::optional< float > getAngleToClosestFoodInRange()
Returns the angle to the closest food in range (if there is any).
Definition: simulation.cpp:85
void clampEntityPosToBoard()
Limits the position of the entity to the board.
Definition: simulation.cpp:170
EntityFoodStage m_foodStage
Definition: simulation.h:75
float m_currentEnergy
Definition: simulation.h:66
A class representing the simulation.
Definition: simulation.h:157
std::vector< Entity >::iterator m_entitiesEndIt
Definition: simulation.h:162
Simulation(types::SimulationInfo t_simInfo)
Constructor for the Simulation class.
Definition: simulation.cpp:688
types::Trait getAvgTraits() const
Calculates the average traits of all entities for the whole simulation.
Definition: simulation.cpp:743
bool isSimulationDone
Definition: simulation.h:170
Cycle m_currentCycle
Definition: simulation.h:167
std::vector< Entity > m_entities
Definition: simulation.h:161
void update(float elapsedTime)
Updates the simulation.
Definition: simulation.cpp:808
size_t m_currentCycle_n
Definition: simulation.h:166
void setFoodChange(int foodChange)
Definition: simulation.cpp:836
void setEntityTraits(size_t id, const types::Trait &traits)
Sets the traits of an entity.
Definition: simulation.cpp:671
const std::vector< Food > & getFoods() const
Getter for all the food particles.
Definition: simulation.cpp:626
static std::span< Entity > getActiveEntities(std::vector< Entity > &entities, std::vector< Entity >::iterator &iter)
Returns only the alive entities in the current cycle.
Definition: simulation.cpp:615
void cleanEntities()
Cleans up unused entities after the simulation has finished.
Definition: simulation.cpp:582
types::SimulationInfo m_simInfo
Definition: simulation.h:159
size_t m_lastEntityId
Definition: simulation.h:164
static void repositionEntitiesIter(std::vector< Entity > &entities, std::vector< Entity >::iterator &iter)
Sets an appropriate position for the iterator used to mark the point between the alive and dead entit...
Definition: simulation.cpp:635
size_t getTotalDiedEntities() const
Calculates the amount of the total died entities.
Definition: simulation.cpp:723
const Entity * getEntityById(size_t id)
Getter for entity by id.
Definition: simulation.cpp:653
void saveSimulationInfo(std::optional< std::string > fileName) const
Generates and attempts to save all of the information gathered throughout the simulation.
Definition: simulation.cpp:766
size_t getTotalAliveEntities() const
Calculates the amount of the total alive entities.
Definition: simulation.cpp:713
std::vector< Food > m_foods
Definition: simulation.h:163
Definition: simulation.h:9
DirectionsDeg
An enumeration type describing the directions of the board.
Definition: simulation.h:23
EntityFoodStage
An enumeration type describing the three states of an Entity.
Definition: simulation.h:34
EntityTarget
Definition: simulation_data.h:9
An enumeration type representing a single food particle.
Definition: simulation.h:14
bool isEaten
Definition: simulation.h:16
types::fVec2 pos
Definition: simulation.h:15
A struct holding the data for a simulation.
Definition: simulation_data.h:35
A struct holding the data for a trait.
Definition: simulation_data.h:26
Definition: simulation_data.h:17