Nano v1.0.0
Simulating Natural Selection
|
A class representing a single entity in the simulation. More...
#include <simulation.h>
Public Member Functions | |
Entity (size_t t_id, const int t_worldSize, const types::Trait &t_traits, std::vector< Food > *t_foods, size_t t_cycleBornAt) | |
types::EntityTarget | getBrain () const |
Peek into an entity's thoughts. More... | |
const types::fVec2 & | getPos () const |
Getter for position. More... | |
float | getFacingAngle () const |
Getter for facing angle. More... | |
Public Attributes | |
int | m_worldSize |
std::vector< Food > * | m_foods = nullptr |
size_t | m_id |
size_t | m_cycleBornAt |
size_t | m_cyclesLived = 0 |
size_t | m_cycleDiedAt = 0 |
types::fVec2 | m_pos = {0.0f, 0.0f} |
float | m_turnRate = 70.0f |
float | m_maxTurnAngle = 100.0f |
float | m_facingAngle = 0.0f |
float | m_turningAngle = 0.0f |
float | m_timeSinceLastTurn = 0.0f |
Food * | m_targetFood = nullptr |
float | m_energyMax |
float | m_currentEnergy = m_energyMax |
types::Trait | m_traits |
bool | m_isAlive = true |
bool | m_isDoneWithCycle = false |
bool | m_shouldReproduce = false |
EntityFoodStage | m_foodStage = EntityFoodStage::ZERO_FOOD |
Static Public Attributes | |
static constexpr float | traitPadding = 0.8f |
Private Member Functions | |
void | update (const float elapsedTime) |
Update the entity. More... | |
std::optional< float > | getAngleToClosestFoodInRange () |
Returns the angle to the closest food in range (if there is any). More... | |
float | getAngleToClosestWall () |
Returns the angle to the closest wall to the entity. More... | |
void | generateNewTurningAngle () |
Sets the turning angle to a new random value that's less than the max turning angle. More... | |
bool | isOutOfBounds () const |
Checks if the entity is outside the bounds of the board. More... | |
void | clampEntityPosToBoard () |
Limits the position of the entity to the board. More... | |
bool | handleFoodCollision (const float elapsedTime) |
Handles everything regarding food collision. More... | |
void | reset () |
Prepares the entity for the next cycle. More... | |
void | hanldeEnergy (const float elapsedTime) |
Handles the energy depletion of the entity. More... | |
void | walk (float elapsedTime) |
Handles special turning logic. More... | |
void | move (float elapsedTime) |
Moves the entity in it's facing direction. More... | |
Friends | |
class | Cycle |
class | Simulation |
A class representing a single entity in the simulation.
This class holds all the information and logic for the function of an entity.
ss::bll::simulation::Entity::Entity | ( | size_t | t_id, |
const int | t_worldSize, | ||
const types::Trait & | t_traits = {1.0f, 1.0f} , |
||
std::vector< Food > * | t_foods = nullptr , |
||
size_t | t_cycleBornAt = 0 |
||
) |
|
private |
Limits the position of the entity to the board.
If the entity ends up outside the board, this returns the coordinates to the appropriate point on the board.
|
private |
Sets the turning angle to a new random value that's less than the max turning angle.
|
private |
Returns the angle to the closest food in range (if there is any).
|
private |
Returns the angle to the closest wall to the entity.
ss::types::EntityTarget ss::bll::simulation::Entity::getBrain | ( | ) | const |
Peek into an entity's thoughts.
float ss::bll::simulation::Entity::getFacingAngle | ( | ) | const |
Getter for facing angle.
const ss::types::fVec2 & ss::bll::simulation::Entity::getPos | ( | ) | const |
Getter for position.
|
private |
Handles everything regarding food collision.
|
private |
Handles the energy depletion of the entity.
|
private |
Checks if the entity is outside the bounds of the board.
|
private |
Moves the entity in it's facing direction.
Just for moving forward based on position and facing angle.
|
private |
Prepares the entity for the next cycle.
|
private |
Update the entity.
This function checks for food collision and etc. It handles everything an entity should do.
elapsedTime |
|
private |
Handles special turning logic.
|
friend |
|
friend |
float ss::bll::simulation::Entity::m_currentEnergy = m_energyMax |
size_t ss::bll::simulation::Entity::m_cycleBornAt |
size_t ss::bll::simulation::Entity::m_cycleDiedAt = 0 |
size_t ss::bll::simulation::Entity::m_cyclesLived = 0 |
float ss::bll::simulation::Entity::m_energyMax |
float ss::bll::simulation::Entity::m_facingAngle = 0.0f |
std::vector<Food>* ss::bll::simulation::Entity::m_foods = nullptr |
EntityFoodStage ss::bll::simulation::Entity::m_foodStage = EntityFoodStage::ZERO_FOOD |
size_t ss::bll::simulation::Entity::m_id |
bool ss::bll::simulation::Entity::m_isAlive = true |
bool ss::bll::simulation::Entity::m_isDoneWithCycle = false |
float ss::bll::simulation::Entity::m_maxTurnAngle = 100.0f |
types::fVec2 ss::bll::simulation::Entity::m_pos = {0.0f, 0.0f} |
bool ss::bll::simulation::Entity::m_shouldReproduce = false |
Food* ss::bll::simulation::Entity::m_targetFood = nullptr |
float ss::bll::simulation::Entity::m_timeSinceLastTurn = 0.0f |
types::Trait ss::bll::simulation::Entity::m_traits |
float ss::bll::simulation::Entity::m_turningAngle = 0.0f |
float ss::bll::simulation::Entity::m_turnRate = 70.0f |
int ss::bll::simulation::Entity::m_worldSize |
|
inlinestaticconstexpr |