Nano v1.0.0
Simulating Natural Selection
ss::bll::simulation::Entity Class Reference

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::fVec2getPos () 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
 
Foodm_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
 

Detailed Description

A class representing a single entity in the simulation.

This class holds all the information and logic for the function of an entity.

Constructor & Destructor Documentation

◆ 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 
)

Member Function Documentation

◆ clampEntityPosToBoard()

void ss::bll::simulation::Entity::clampEntityPosToBoard ( )
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.

◆ generateNewTurningAngle()

void ss::bll::simulation::Entity::generateNewTurningAngle ( )
private

Sets the turning angle to a new random value that's less than the max turning angle.

◆ getAngleToClosestFoodInRange()

std::optional< float > ss::bll::simulation::Entity::getAngleToClosestFoodInRange ( )
private

Returns the angle to the closest food in range (if there is any).

Returns
Angle in degrees.

◆ getAngleToClosestWall()

float ss::bll::simulation::Entity::getAngleToClosestWall ( )
private

Returns the angle to the closest wall to the entity.

Returns
Angle in degrees.

◆ getBrain()

ss::types::EntityTarget ss::bll::simulation::Entity::getBrain ( ) const

Peek into an entity's thoughts.

Returns
the appropriate thought depending on internal state.

◆ getFacingAngle()

float ss::bll::simulation::Entity::getFacingAngle ( ) const

Getter for facing angle.

Returns
the entity's facing angle.

◆ getPos()

const ss::types::fVec2 & ss::bll::simulation::Entity::getPos ( ) const

Getter for position.

Returns
a const reference to the entity's position.

◆ handleFoodCollision()

bool ss::bll::simulation::Entity::handleFoodCollision ( const float  elapsedTime)
private

Handles everything regarding food collision.

◆ hanldeEnergy()

void ss::bll::simulation::Entity::hanldeEnergy ( const float  elapsedTime)
private

Handles the energy depletion of the entity.

◆ isOutOfBounds()

bool ss::bll::simulation::Entity::isOutOfBounds ( ) const
private

Checks if the entity is outside the bounds of the board.

◆ move()

void ss::bll::simulation::Entity::move ( float  elapsedTime)
private

Moves the entity in it's facing direction.

Just for moving forward based on position and facing angle.

◆ reset()

void ss::bll::simulation::Entity::reset ( )
private

Prepares the entity for the next cycle.

◆ update()

void ss::bll::simulation::Entity::update ( const float  elapsedTime)
private

Update the entity.

This function checks for food collision and etc. It handles everything an entity should do.

Parameters
elapsedTime

◆ walk()

void ss::bll::simulation::Entity::walk ( float  elapsedTime)
private

Handles special turning logic.

Friends And Related Function Documentation

◆ Cycle

friend class Cycle
friend

◆ Simulation

friend class Simulation
friend

Member Data Documentation

◆ m_currentEnergy

float ss::bll::simulation::Entity::m_currentEnergy = m_energyMax

◆ m_cycleBornAt

size_t ss::bll::simulation::Entity::m_cycleBornAt

◆ m_cycleDiedAt

size_t ss::bll::simulation::Entity::m_cycleDiedAt = 0

◆ m_cyclesLived

size_t ss::bll::simulation::Entity::m_cyclesLived = 0

◆ m_energyMax

float ss::bll::simulation::Entity::m_energyMax

◆ m_facingAngle

float ss::bll::simulation::Entity::m_facingAngle = 0.0f

◆ m_foods

std::vector<Food>* ss::bll::simulation::Entity::m_foods = nullptr

◆ m_foodStage

EntityFoodStage ss::bll::simulation::Entity::m_foodStage = EntityFoodStage::ZERO_FOOD

◆ m_id

size_t ss::bll::simulation::Entity::m_id

◆ m_isAlive

bool ss::bll::simulation::Entity::m_isAlive = true

◆ m_isDoneWithCycle

bool ss::bll::simulation::Entity::m_isDoneWithCycle = false

◆ m_maxTurnAngle

float ss::bll::simulation::Entity::m_maxTurnAngle = 100.0f

◆ m_pos

types::fVec2 ss::bll::simulation::Entity::m_pos = {0.0f, 0.0f}

◆ m_shouldReproduce

bool ss::bll::simulation::Entity::m_shouldReproduce = false

◆ m_targetFood

Food* ss::bll::simulation::Entity::m_targetFood = nullptr

◆ m_timeSinceLastTurn

float ss::bll::simulation::Entity::m_timeSinceLastTurn = 0.0f

◆ m_traits

types::Trait ss::bll::simulation::Entity::m_traits

◆ m_turningAngle

float ss::bll::simulation::Entity::m_turningAngle = 0.0f

◆ m_turnRate

float ss::bll::simulation::Entity::m_turnRate = 70.0f

◆ m_worldSize

int ss::bll::simulation::Entity::m_worldSize

◆ traitPadding

constexpr float ss::bll::simulation::Entity::traitPadding = 0.8f
inlinestaticconstexpr

The documentation for this class was generated from the following files: