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

Method Inst_ExploitForward5

avida-core/source/cpu/cHardwareCPU.cc:8753–8811  ·  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, i.e. the one directly behind, and behind and to the left and right.

Source from the content-addressed store, hash-verified

8751// This instruction doesn't sense the three cells behind the organism,
8752// i.e. the one directly behind, and behind and to the left and right.
8753bool cHardwareCPU::Inst_ExploitForward5(cAvidaContext& ctx)
8754{
8755 int num_rotations = 0;
8756 double phero_amount = 0;
8757 double max_pheromone = 0;
8758
8759 cPopulation& pop = m_world->GetPopulation();
8760 int cellid = m_organism->GetCellID();
8761
8762 if (cellid == -1) {
8763 return false;
8764 }
8765
8766 cPopulationCell& mycell = pop.GetCell(cellid);
8767 cDeme &deme = pop.GetDeme(pop.GetCell(cellid).GetDemeID());
8768 const cResourceCount& deme_resource_count = deme.GetDemeResourceCount();
8769 Apto::Array<double> cell_resources;
8770
8771 if ( (m_world->GetConfig().EXPLOIT_EXPLORE_PROB.Get() >= 0) &&
8772 (ctx.GetRandom().P(m_world->GetConfig().EXPLOIT_EXPLORE_PROB.Get())) ) {
8773 num_rotations = ctx.GetRandom().GetUInt(m_organism->GetNeighborhoodSize());
8774 } else {
8775 // Find which neighbor has the strongest pheromone
8776 for (int i = 0; i < mycell.ConnectionList().GetSize(); i++) {
8777
8778 // Skip the cells in the back
8779 if (i == 3 || i == 4 || i == 5) {
8780 mycell.ConnectionList().CircNext();
8781 continue;
8782 }
8783
8784 phero_amount = 0;
8785 cell_resources = deme_resource_count.GetCellResources(deme.GetRelativeCellID(mycell.GetCellFaced().GetID()), ctx);
8786
8787 for (int j = 0; j < deme_resource_count.GetSize(); j++) {
8788 if (strncmp(deme_resource_count.GetResName(j), "pheromone", 9) == 0) {
8789 phero_amount += cell_resources[j];
8790 }
8791 }
8792
8793 if (phero_amount > max_pheromone) {
8794 num_rotations = i;
8795 max_pheromone = phero_amount;
8796 }
8797
8798 mycell.ConnectionList().CircNext();
8799 }
8800 }
8801
8802 // Rotate until we face the neighbor with the strongest pheromone.
8803 // If there was no winner, just move forward.
8804 for (int i = 0; i < num_rotations; i++) {
8805 mycell.ConnectionList().CircNext();
8806 }
8807
8808 m_organism->Move(ctx);
8809
8810 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