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

A class representing a single cycle in the simulation. More...

#include <simulation.h>

Public Member Functions

 Cycle ()
 Necessary default constructor. More...
 
 Cycle (std::vector< Entity > *t_entities, std::vector< Entity >::iterator *t_entitiesEndIter, size_t t_worldSize, std::vector< Food > *t_foods, size_t t_cycleId, size_t *t_lastEntityId)
 
void CycleEnd ()
 Prepares the entities for the next cycle. More...
 
void update (float elapsedTime)
 Updates the current cycle. More...
 

Static Public Member Functions

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. More...
 
static void equalEntitiesDistribution (std::span< Entity > entities, size_t wallSize)
 Distributes entities with equal spacing on the board. More...
 
static void randomEntitiesDistribution (std::span< Entity > entities, size_t wallSize)
 Distributes entities randomly on the edges of the board. More...
 
static void distributeEntities (std::span< Entity > entities, size_t wallSize)
 Determines if there is enough space for equal distribution and calls the appropriate function. More...
 
static void handleFoodCount (std::vector< Food > &foods, int changeBy)
 
static void randomizeFoodPositions (std::span< Food > foods, size_t worldSize)
 Redistributes the food particles on the board. More...
 

Private Attributes

std::vector< Entity > * m_entities
 
std::vector< Entity >::iterator * m_entitiesEndIter
 
std::span< EntityactiveEntities
 
size_t * m_lastEntityId
 
std::vector< Food > * m_foods
 
size_t m_worldSize
 
size_t m_cycleId
 
bool m_isCycleDone = false
 

Friends

class Simulation
 

Detailed Description

A class representing a single cycle in the simulation.

This class holds all the information and logic for the function of a cycle.

Constructor & Destructor Documentation

◆ Cycle() [1/2]

ss::bll::simulation::Cycle::Cycle ( )

Necessary default constructor.

Note
Do not initialize a cycle without params.

◆ Cycle() [2/2]

ss::bll::simulation::Cycle::Cycle ( std::vector< Entity > *  t_entities,
std::vector< Entity >::iterator *  t_entitiesEndIter,
size_t  t_worldSize,
std::vector< Food > *  t_foods,
size_t  t_cycleId,
size_t *  t_lastEntityId = nullptr 
)

Member Function Documentation

◆ CycleEnd()

void ss::bll::simulation::Cycle::CycleEnd ( )

Prepares the entities for the next cycle.

Handles reproducing distributing and etc.

◆ distributeEntities()

void ss::bll::simulation::Cycle::distributeEntities ( std::span< Entity entities,
size_t  wallSize 
)
static

Determines if there is enough space for equal distribution and calls the appropriate function.

◆ equalEntitiesDistribution()

void ss::bll::simulation::Cycle::equalEntitiesDistribution ( std::span< Entity entities,
size_t  wallSize 
)
static

Distributes entities with equal spacing on the board.

Note
Used only when there is enough space for that on the board.

◆ handleFoodCount()

void ss::bll::simulation::Cycle::handleFoodCount ( std::vector< Food > &  foods,
int  changeBy 
)
static

◆ randomEntitiesDistribution()

void ss::bll::simulation::Cycle::randomEntitiesDistribution ( std::span< Entity entities,
size_t  wallSize 
)
static

Distributes entities randomly on the edges of the board.

Note
Used when there is not enough space for equal distribution.

◆ randomizeFoodPositions()

void ss::bll::simulation::Cycle::randomizeFoodPositions ( std::span< Food foods,
size_t  worldSize 
)
static

Redistributes the food particles on the board.

◆ reproduceEntities()

void ss::bll::simulation::Cycle::reproduceEntities ( std::vector< Entity > &  entities,
std::vector< Entity >::iterator &  entitiesEndIt,
size_t *  lastEntityId,
size_t  cycleId,
std::vector< Food > *  foods 
)
static

Reproduces all entities that should reproduce with random traits inherited from their parent.

◆ update()

void ss::bll::simulation::Cycle::update ( float  elapsedTime)

Updates the current cycle.

Loops through all the entities and calls their update. Checks if the cycle should end.

Friends And Related Function Documentation

◆ Simulation

friend class Simulation
friend

Member Data Documentation

◆ activeEntities

std::span<Entity> ss::bll::simulation::Cycle::activeEntities
private

◆ m_cycleId

size_t ss::bll::simulation::Cycle::m_cycleId
private

◆ m_entities

std::vector<Entity>* ss::bll::simulation::Cycle::m_entities
private

◆ m_entitiesEndIter

std::vector<Entity>::iterator* ss::bll::simulation::Cycle::m_entitiesEndIter
private

◆ m_foods

std::vector<Food>* ss::bll::simulation::Cycle::m_foods
private

◆ m_isCycleDone

bool ss::bll::simulation::Cycle::m_isCycleDone = false
private

◆ m_lastEntityId

size_t* ss::bll::simulation::Cycle::m_lastEntityId
private

◆ m_worldSize

size_t ss::bll::simulation::Cycle::m_worldSize
private

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