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

Method Inst_SenseAI

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

Source from the content-addressed store, hash-verified

3724}
3725
3726bool cHardwareCPU::Inst_SenseAI(cAvidaContext& ctx)
3727{
3728 int ai_counter = 0;
3729
3730 int cellID = m_organism->GetCellID();
3731 int radius = 1;
3732
3733 int world_x = m_world->GetConfig().WORLD_X.Get();
3734 int world_y = m_world->GetConfig().WORLD_Y.Get();
3735 int cell_x = cellID % world_x;
3736 int cell_y = (cellID - cell_x)/world_x;
3737
3738
3739 for (int i = cell_x - radius; i <= cell_x + radius; i++) {
3740 for (int j = cell_y - radius; j <= cell_y + radius; j++) {
3741 int y;
3742 int x;
3743 //if (i==cell_x && j ==cell_y) continue;
3744
3745 if (i<0) x = world_x + i;
3746 else if (i>= world_x) x = i-world_x;
3747 else x = i;
3748
3749 if (j<0) y = world_y + j;
3750 else if (j >= world_y) y = j-world_y;
3751 else y = j;
3752
3753 cPopulationCell& neighbor_cell = m_world->GetPopulation().GetCell(y*world_x + x);
3754
3755
3756 //do we actually have someone in neighborhood?
3757 if (neighbor_cell.IsOccupied() == false) continue;
3758
3759 cOrganism* org_temp = neighbor_cell.GetOrganism();
3760
3761 if (org_temp != NULL) {
3762 if (org_temp->GetLyseDisplay()) ai_counter ++;
3763 }
3764
3765 }
3766 }
3767
3768 if (ai_counter >=3)
3769 {
3770 //The organism is now 'producing' a public good that surrounding organism can gain from
3771 m_organism->GetPhenotype().SetKaboomExecuted(true);
3772 return true;
3773 }
3774 else return false;
3775
3776}
3777
3778bool cHardwareCPU::Inst_NopPre(cAvidaContext& ctx)
3779{

Callers

nothing calls this directly

Calls 8

GetConfigMethod · 0.80
IsOccupiedMethod · 0.80
GetLyseDisplayMethod · 0.80
SetKaboomExecutedMethod · 0.80
GetCellIDMethod · 0.45
GetMethod · 0.45
GetCellMethod · 0.45
GetOrganismMethod · 0.45

Tested by

no test coverage detected