| 8695 | } |
| 8696 | |
| 8697 | bool cHardwareCPU::Inst_Exploit(cAvidaContext& ctx) |
| 8698 | { |
| 8699 | int num_rotations = 0; |
| 8700 | double phero_amount = 0; |
| 8701 | double max_pheromone = 0; |
| 8702 | |
| 8703 | cPopulation& pop = m_world->GetPopulation(); |
| 8704 | int cellid = m_organism->GetCellID(); |
| 8705 | |
| 8706 | if (cellid == -1) return false; |
| 8707 | |
| 8708 | cPopulationCell& mycell = pop.GetCell(cellid); |
| 8709 | cDeme &deme = pop.GetDeme(pop.GetCell(cellid).GetDemeID()); |
| 8710 | const cResourceCount& deme_resource_count = deme.GetDemeResourceCount(); |
| 8711 | Apto::Array<double> cell_resources; |
| 8712 | |
| 8713 | if ( (m_world->GetConfig().EXPLOIT_EXPLORE_PROB.Get() >= 0) && |
| 8714 | (ctx.GetRandom().P(m_world->GetConfig().EXPLOIT_EXPLORE_PROB.Get())) ) { |
| 8715 | num_rotations = ctx.GetRandom().GetUInt(m_organism->GetNeighborhoodSize()); |
| 8716 | } else { |
| 8717 | // Find which neighbor has the strongest pheromone |
| 8718 | for (int i = 0; i < mycell.ConnectionList().GetSize(); i++) { |
| 8719 | |
| 8720 | phero_amount = 0; |
| 8721 | cell_resources = deme_resource_count.GetCellResources(deme.GetRelativeCellID(mycell.GetCellFaced().GetID()), ctx); |
| 8722 | |
| 8723 | for (int j = 0; j < deme_resource_count.GetSize(); j++) { |
| 8724 | if (strncmp(deme_resource_count.GetResName(j), "pheromone", 9) == 0) { |
| 8725 | phero_amount += cell_resources[j]; |
| 8726 | } |
| 8727 | } |
| 8728 | |
| 8729 | if (phero_amount > max_pheromone) { |
| 8730 | num_rotations = i; |
| 8731 | max_pheromone = phero_amount; |
| 8732 | } |
| 8733 | |
| 8734 | mycell.ConnectionList().CircNext(); |
| 8735 | } |
| 8736 | } |
| 8737 | |
| 8738 | // Rotate until we face the neighbor with the strongest pheromone. |
| 8739 | // If there was no winner, just move forward. |
| 8740 | for (int i = 0; i < num_rotations; i++) mycell.ConnectionList().CircNext(); |
| 8741 | |
| 8742 | m_organism->Move(ctx); |
| 8743 | |
| 8744 | return true; |
| 8745 | } //End Inst_Exploit() |
| 8746 | |
| 8747 | |
| 8748 |
nothing calls this directly
no test coverage detected