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

Method Inst_SenseNextResLevel

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

Must be nop-modified. * Places the number of resources in the group either +1 or -1 in register BX, * wrapping from the top group back to group 1 (skipping 0), * +1 group if the nop register has a positive number * -1 group if the nop register has a negative number. */

Source from the content-addressed store, hash-verified

4479 * -1 group if the nop register has a negative number.
4480 */
4481bool cHardwareCPU::Inst_SenseNextResLevel(cAvidaContext& ctx)
4482{
4483 // Check for an opinion.
4484 if (!m_organism->GetOrgInterface().HasOpinion(m_organism)) return false;
4485 if (m_world->GetConfig().USE_FORM_GROUPS.Get() != 2) return false;
4486 int opinion = m_organism->GetOpinion().first;
4487
4488 const int num_groups = m_organism->GetOrgInterface().GetResources(ctx).GetSize();
4489 if (num_groups <= 2) return false;
4490
4491 // If not nop-modified, fails to execute.
4492 if (!(m_inst_set->IsNop(getIP().GetNextInst()))) return false;
4493 // Retreives the value from the nop-modifying register.
4494 const int nop_register = FindModifiedRegister(REG_BX);
4495 int register_value = GetRegister(nop_register);
4496 if (register_value == 0) return false;
4497
4498 const Apto::Array<double> res_count = m_organism->GetOrgInterface().GetResources(ctx);
4499 if (opinion == (num_groups - 1)) {
4500 if (register_value > 0) GetRegister(REG_BX) = (int) (res_count[1] * 100 + 0.5);
4501 else if (register_value < 0) GetRegister(REG_BX) = (int) (res_count[opinion - 1] * 100 + 0.5);
4502 }
4503 else if ((opinion == 1) || (opinion == 0)) {
4504 if (register_value > 0) GetRegister(REG_BX) = (int) (res_count[opinion + 1] * 100 + 0.5);
4505 else if (register_value < 0) GetRegister(REG_BX) = (int) (res_count[num_groups - 1] * 100 + 0.5);
4506 }
4507 else if ((opinion != (num_groups - 1)) && (opinion != 1) && (opinion != 0)) {
4508 if (register_value > 0) GetRegister(REG_BX) = (int) (res_count[opinion + 1] * 100 + 0.5);
4509 else if (register_value < 0) GetRegister(REG_BX) = (int) (res_count[opinion - 1] * 100 + 0.5);
4510 }
4511 return true;
4512}
4513
4514bool cHardwareCPU::Inst_SenseDiffFaced(cAvidaContext& ctx)
4515{

Callers

nothing calls this directly

Calls 6

GetConfigMethod · 0.80
GetNextInstMethod · 0.80
HasOpinionMethod · 0.45
GetMethod · 0.45
GetSizeMethod · 0.45
IsNopMethod · 0.45

Tested by

no test coverage detected