[Avida-SVN] r2818 - in branches/hjg-dev/source: cpu main

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Wed Oct 8 07:16:53 PDT 2008


Author: hjg
Date: 2008-10-08 10:16:53 -0400 (Wed, 08 Oct 2008)
New Revision: 2818

Modified:
   branches/hjg-dev/source/cpu/cHardwareCPU.cc
   branches/hjg-dev/source/main/cOrganism.h
   branches/hjg-dev/source/main/cTaskLib.cc
   branches/hjg-dev/source/main/cTaskLib.h
Log:
new task rewarding for checking reputation.

Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-10-08 02:08:24 UTC (rev 2817)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-10-08 14:16:53 UTC (rev 2818)
@@ -6689,6 +6689,10 @@
   
     GetRegister(opinion_reg) = neighbor->GetOpinion().first;
     GetRegister(age_reg) = m_world->GetStats().GetUpdate() - neighbor->GetOpinion().second;
+	
+	// track if an organism has checked reputation
+	organism->CheckedReputation();
+	
   }
   return true;
 }

Modified: branches/hjg-dev/source/main/cOrganism.h
===================================================================
--- branches/hjg-dev/source/main/cOrganism.h	2008-10-08 02:08:24 UTC (rev 2817)
+++ branches/hjg-dev/source/main/cOrganism.h	2008-10-08 14:16:53 UTC (rev 2818)
@@ -454,16 +454,21 @@
 	int GetOtherRawMaterials() {InitReputation(); return m_other_raw_materials; }
 	// Has previously donated to this organism
 	bool IsDonor(int neighbor_id);
+	// Has checked reputation
+	void CheckedReputation() {InitReputation(); checkedReputation=true; }
+	bool HasCheckedReputation() { return checkedReputation; }
 		
 protected:
 	// Initialize reputation support
-	inline void InitReputation() {if (!m_self_raw_materials) {m_self_raw_materials = 100; m_other_raw_materials =0; }}
+	inline void InitReputation() {if (!m_self_raw_materials) {m_self_raw_materials = 100; m_other_raw_materials =0; checkedReputation =false;}}
 	// The organism's own raw materials
 	int m_self_raw_materials; 
 	// The raw materials an oranism has collected from others
 	int m_other_raw_materials;
 	// a list of organism id's that have previously donated to this organism
 	set<int> donor_list;
+	// whether an organism has used the check reputation functionality
+	bool checkedReputation;
   
   // -------- End of reputation support --------
 

Modified: branches/hjg-dev/source/main/cTaskLib.cc
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.cc	2008-10-08 02:08:24 UTC (rev 2817)
+++ branches/hjg-dev/source/main/cTaskLib.cc	2008-10-08 14:16:53 UTC (rev 2818)
@@ -420,6 +420,8 @@
   // reputation based tasks
   else if(name == "use_raw_mat")
     NewTask(name, "Use raw materials from self and other", &cTaskLib::Task_UseRawMaterials);
+  else if(name == "check_rep")
+    NewTask(name, "Check a neighbor's reputation", &cTaskLib::Task_CheckReputation);
 
   // event tasks
   if(name == "move_to_event")
@@ -3074,3 +3076,11 @@
 	}
 	return bonus;
 }
+
+
+/* This task rewards an organism for checking out the reputation of 
+another organism.*/
+double cTaskLib::Task_CheckReputation(cTaskContext& ctx) const {
+	return (double) ctx.GetOrganism()->HasCheckedReputation();
+}
+

Modified: branches/hjg-dev/source/main/cTaskLib.h
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.h	2008-10-08 02:08:24 UTC (rev 2817)
+++ branches/hjg-dev/source/main/cTaskLib.h	2008-10-08 14:16:53 UTC (rev 2818)
@@ -299,6 +299,8 @@
   
   // reputation
   double Task_UseRawMaterials(cTaskContext& ctx) const;
+  double Task_CheckReputation(cTaskContext& ctx) const;
+
 };
 
 




More information about the Avida-cvs mailing list