[Avida-SVN] r2824 - branches/hjg-dev/source/cpu

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Thu Oct 9 11:56:00 PDT 2008


Author: hjg
Date: 2008-10-09 14:56:00 -0400 (Thu, 09 Oct 2008)
New Revision: 2824

Modified:
   branches/hjg-dev/source/cpu/cHardwareCPU.cc
   branches/hjg-dev/source/cpu/cHardwareCPU.h
Log:
added in support for checking a neighbor's reputation.

Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-10-09 17:51:53 UTC (rev 2823)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-10-09 18:56:00 UTC (rev 2824)
@@ -449,9 +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-neighbors-opinion", &cHardwareCPU::Inst_GetNeighborsOpinion, nInstFlag::STALL),
 	
 	// Reputation instructions
 	tInstLibEntry<tMethod>("donate-frm", &cHardwareCPU::Inst_DonateFacingRawMaterials, nInstFlag::STALL),
+    tInstLibEntry<tMethod>("get-neighbors-reputation", &cHardwareCPU::Inst_GetNeighborsReputation, nInstFlag::STALL),
 
 
     // Must always be the last instruction in the array
@@ -6671,6 +6673,28 @@
 }
 
 
+/*! Sense the neighbor's current opinion, placing the opinion in register ?BX?
+ and the age of that opinion (in updates) in register !?BX?.  If the neighbor has no
+ opinion, do nothing.
+ */
+bool cHardwareCPU::Inst_GetNeighborsOpinion(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)
 {
@@ -6712,3 +6736,28 @@
   }
   return isSuccessful;
 }  
+
+
+/*! An organism's reputation is stored as an opinion. This instruction 
+	uses Inst_GetNeighborsOpinion to do the heavy lifting, but includes
+	default behavior suitable for reputations. Specifically, if an 
+	neighbor has no reputation (i.e., it has not donated) or does not
+	exist, then this instruction puts zeros into the registers.
+ */
+bool cHardwareCPU::Inst_GetNeighborsReputation(cAvidaContext& ctx)
+{
+
+  // Get faced neighbor
+  cOrganism * neighbor = organism->GetNeighbor();
+  if (neighbor != NULL && neighbor->HasOpinion()) { 
+		Inst_GetNeighborsOpinion(ctx);
+	} else {
+		const int opinion_reg = FindModifiedRegister(REG_BX);
+		const int age_reg = FindNextRegister(opinion_reg);
+  
+		GetRegister(opinion_reg) = 0;
+		GetRegister(age_reg) = m_world->GetStats().GetUpdate();
+  }
+  return true;
+
+}

Modified: branches/hjg-dev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.h	2008-10-09 17:51:53 UTC (rev 2823)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.h	2008-10-09 18:56:00 UTC (rev 2824)
@@ -665,15 +665,22 @@
   bool Inst_SetOpinion(cAvidaContext& ctx);
   //! Retrieve this organism's current opinion.
   bool Inst_GetOpinion(cAvidaContext& ctx);
+  //! Retrieve the organism's neighbors current opinion. 
+  bool Inst_GetNeighborsOpinion(cAvidaContext& ctx);
   
   
+  
   // -------- Reputation support --------
   /* These instructions interact with the "reputation" support in cOrganism.h.  They 
   are  based on the donate instructions. However, these instructions donate
   "raw materials" rather than merit and will eventually be used to support 
   reputation based cooperation.
   */ 
+  // Donate a raw material to the neighbor
   bool Inst_DonateFacingRawMaterials(cAvidaContext& ctx);
+  // Get a neighbor's reputation
+  bool Inst_GetNeighborsReputation(cAvidaContext& ctx);
+  
 
 };
 




More information about the Avida-cvs mailing list