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

Method Inst_SenseDiffFaced

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

Source from the content-addressed store, hash-verified

4512}
4513
4514bool cHardwareCPU::Inst_SenseDiffFaced(cAvidaContext& ctx)
4515{
4516 const Apto::Array<double> res_count = m_organism->GetOrgInterface().GetResources(ctx);
4517 if(m_organism->GetOrgInterface().HasOpinion(m_organism)) {
4518 int opinion = m_organism->GetOpinion().first;
4519 int reg_to_set = FindModifiedRegister(REG_BX);
4520 double faced_res = m_organism->GetOrgInterface().GetFacedCellResources(ctx)[opinion];
4521 // return % change
4522 int res_diff = 0;
4523 if (res_count[opinion] == 0) res_diff = (int) faced_res;
4524 else res_diff = (int) (((faced_res - res_count[opinion])/res_count[opinion]) * 100 + 0.5);
4525 GetRegister(reg_to_set) = res_diff;
4526 }
4527 return true;
4528}
4529
4530
4531bool cHardwareCPU::Inst_SenseFacedHabitat(cAvidaContext& ctx)

Callers

nothing calls this directly

Calls 1

HasOpinionMethod · 0.45

Tested by

no test coverage detected