[Avida-SVN] r2815 - branches/hjg-dev/source/cpu
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Tue Oct 7 18:25:43 PDT 2008
Author: hjg
Date: 2008-10-07 21:25:43 -0400 (Tue, 07 Oct 2008)
New Revision: 2815
Modified:
branches/hjg-dev/source/cpu/cHardwareCPU.cc
branches/hjg-dev/source/cpu/cHardwareCPU.h
Log:
added a reputation tracker using the opinion infrastructure.
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-10-07 19:19:36 UTC (rev 2814)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-10-08 01:25:43 UTC (rev 2815)
@@ -449,10 +449,11 @@
// These are STALLs because opinions are only relevant with respect to time.
tInstLibEntry<tMethod>("set-opinion", &cHardwareCPU::Inst_SetOpinion, nInstFlag::STALL),
tInstLibEntry<tMethod>("get-opinion", &cHardwareCPU::Inst_GetOpinion, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("get-neighbor-opinion", &cHardwareCPU::Inst_GetNeighborOpinion, nInstFlag::STALL),
// Reputation instructions
tInstLibEntry<tMethod>("donate-frm", &cHardwareCPU::Inst_DonateFacingRawMaterials, nInstFlag::STALL),
- tInstLibEntry<tMethod>("if-donor", &cHardwareCPU::Inst_IfDonor, nInstFlag::STALL),
+// tInstLibEntry<tMethod>("if-donor", &cHardwareCPU::Inst_IfDonor, nInstFlag::STALL),
tInstLibEntry<tMethod>("sense-self-rm", &cHardwareCPU::Inst_SenseSelfRawMaterialAmount, nInstFlag::STALL),
@@ -6673,7 +6674,26 @@
return true;
}
+/*! Sense the organism's (facing) neighbor's current opinion, placing the opinion
+ in register ?BX? and the age of that opinion (in updates) in register !?BX?. If
+ the organism has no opinion, do nothing.
+ */
+bool cHardwareCPU::Inst_GetNeighborOpinion(cAvidaContext& ctx)
+{
+ // Get faced neighbor
+ cOrganism * neighbor = organism->GetNeighbor();
+
+ if(neighbor->HasOpinion()) {
+ const int opinion_reg = FindModifiedRegister(REG_BX);
+ const int age_reg = FindNextRegister(opinion_reg);
+
+ GetRegister(opinion_reg) = neighbor->GetOpinion().first;
+ GetRegister(age_reg) = m_world->GetStats().GetUpdate() - neighbor->GetOpinion().second;
+ }
+ return true;
+}
+
/* Donate raw materials to the facing organism. */
bool cHardwareCPU::Inst_DonateFacingRawMaterials(cAvidaContext& ctx)
{
@@ -6699,6 +6719,15 @@
while (neighbor->GetNeighbor() != organism) {
neighbor->Rotate(1);
}
+
+ // update the donor's reputation by incrementing by 1.
+
+ // check for a reputation
+ if (organism->HasOpinion()) {
+ organism->SetOpinion(organism->GetOpinion().first + 1);
+ } else {
+ organism->SetOpinion(1);
+ }
}
isSuccessful = true;
}
@@ -6708,7 +6737,7 @@
/* Check if the neighbor organism that you are facing has previously donated
to you. If so, */
-bool cHardwareCPU::Inst_IfDonor(cAvidaContext& ctx)
+/*bool cHardwareCPU::Inst_IfDonor(cAvidaContext& ctx)
{
if (organism->IsNeighborCellOccupied()) {
if (!(organism->IsDonor(organism->GetNeighbor()->GetID())))
@@ -6717,7 +6746,7 @@
IP().Advance();
}
return true;
-}
+}*/
/* Put the amout of raw materials this organism has into its
?BX? register. */
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.h 2008-10-07 19:19:36 UTC (rev 2814)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.h 2008-10-08 01:25:43 UTC (rev 2815)
@@ -665,6 +665,8 @@
bool Inst_SetOpinion(cAvidaContext& ctx);
//! Retrieve this organism's current opinion.
bool Inst_GetOpinion(cAvidaContext& ctx);
+ //! Retrieve the opinion of the facing neighbor.
+ bool Inst_GetNeighborOpinion(cAvidaContext& ctx);
// -------- Reputation support --------
@@ -674,7 +676,7 @@
reputation based cooperation.
*/
bool Inst_DonateFacingRawMaterials(cAvidaContext& ctx);
- bool Inst_IfDonor(cAvidaContext& ctx);
+// bool Inst_IfDonor(cAvidaContext& ctx);
bool Inst_SenseSelfRawMaterialAmount(cAvidaContext& ctx);
};
More information about the Avida-cvs
mailing list