MCPcopy Create free account
hub / github.com/devosoft/avida / Inst_ExploitForward3

Method Inst_ExploitForward3

avida-core/source/cpu/cHardwareCPU.cc:8818–8876  ·  view source on GitHub ↗

Sense neighboring cells, and rotate and move to the neighbor with the strongest pheromone. If there is no winner, just move forward. This instruction doesn't sense the three cells behind the organism, or the ones to the sides.

Source from the content-addressed store, hash-verified

8816// This instruction doesn't sense the three cells behind the organism,
8817// or the ones to the sides.
8818bool cHardwareCPU::Inst_ExploitForward3(cAvidaContext& ctx)
8819{
8820 int num_rotations = 0;
8821 double phero_amount = 0;
8822 double max_pheromone = 0;
8823
8824 cPopulation& pop = m_world->GetPopulation();
8825 int cellid = m_organism->GetCellID();
8826
8827 if (cellid == -1) {
8828 return false;
8829 }
8830
8831 cPopulationCell& mycell = pop.GetCell(cellid);
8832 cDeme &deme = pop.GetDeme(pop.GetCell(cellid).GetDemeID());
8833 const cResourceCount& deme_resource_count = deme.GetDemeResourceCount();
8834 Apto::Array<double> cell_resources;
8835
8836 if ( (m_world->GetConfig().EXPLOIT_EXPLORE_PROB.Get() >= 0) &&
8837 (ctx.GetRandom().P(m_world->GetConfig().EXPLOIT_EXPLORE_PROB.Get())) ) {
8838 num_rotations = ctx.GetRandom().GetUInt(m_organism->GetNeighborhoodSize());
8839 } else {
8840 // Find which neighbor has the strongest pheromone
8841 for (int i = 0; i < mycell.ConnectionList().GetSize(); i++) {
8842
8843 // Skip the cells in the back
8844 if (i == 2 || i == 3 || i == 4 || i == 5 || i == 6) {
8845 mycell.ConnectionList().CircNext();
8846 continue;
8847 }
8848
8849 phero_amount = 0;
8850 cell_resources = deme_resource_count.GetCellResources(deme.GetRelativeCellID(mycell.GetCellFaced().GetID()), ctx);
8851
8852 for (int j = 0; j < deme_resource_count.GetSize(); j++) {
8853 if (strncmp(deme_resource_count.GetResName(j), "pheromone", 9) == 0) {
8854 phero_amount += cell_resources[j];
8855 }
8856 }
8857
8858 if (phero_amount > max_pheromone) {
8859 num_rotations = i;
8860 max_pheromone = phero_amount;
8861 }
8862
8863 mycell.ConnectionList().CircNext();
8864 }
8865 }
8866
8867 // Rotate until we face the neighbor with the strongest pheromone.
8868 // If there was no winner, just move forward.
8869 for (int i = 0; i < num_rotations; i++) {
8870 mycell.ConnectionList().CircNext();
8871 }
8872
8873 m_organism->Move(ctx);
8874
8875 return true;

Callers

nothing calls this directly

Calls 14

GetConfigMethod · 0.80
GetUIntMethod · 0.80
GetNeighborhoodSizeMethod · 0.80
CircNextMethod · 0.80
GetRelativeCellIDMethod · 0.80
GetCellFacedMethod · 0.80
GetCellIDMethod · 0.45
GetCellMethod · 0.45
GetDemeMethod · 0.45
GetDemeIDMethod · 0.45
GetMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected