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

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Mon Nov 17 05:59:37 PST 2008


Author: hjg
Date: 2008-11-17 08:59:37 -0500 (Mon, 17 Nov 2008)
New Revision: 2946

Modified:
   branches/hjg-dev/source/cpu/cHardwareCPU.cc
   branches/hjg-dev/source/cpu/cHardwareCPU.h
Log:
donate to other species instruction.

Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-11-16 18:11:58 UTC (rev 2945)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-11-17 13:59:37 UTC (rev 2946)
@@ -455,6 +455,7 @@
 	
 		tInstLibEntry<tMethod>("donate-mat", &cHardwareCPU::Inst_DonateFacingRawMaterialsOneType, nInstFlag::STALL),
   	tInstLibEntry<tMethod>("donate-frm", &cHardwareCPU::Inst_DonateFacingRawMaterials, nInstFlag::STALL),
+  	tInstLibEntry<tMethod>("donate-spec", &cHardwareCPU::Inst_DonateFacingRawMaterialsOtherSpecies, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("donate-k", &cHardwareCPU::Inst_DonateFacingConditionalOnK, nInstFlag::STALL),
   	tInstLibEntry<tMethod>("donate-if-donor", &cHardwareCPU::Inst_DonateIfDonor, nInstFlag::STALL),		
     tInstLibEntry<tMethod>("get-neighbors-reputation", &cHardwareCPU::Inst_GetNeighborsReputation, nInstFlag::STALL),
@@ -6737,9 +6738,26 @@
 			Inst_DonateFacingRawMaterialsOneType(ctx);	
 		}
 	}
+	return true;
+}
 
+/* Donate raw materials (of one kind) to a neighbor, but 
+ only if the neighbor is of a different species. If the 
+ instruction fails, there is no consequence. */
+bool cHardwareCPU::Inst_DonateFacingRawMaterialsOtherSpecies(cAvidaContext& ctx) 
+{ 
+	cOrganism * neighbor = organism->GetNeighbor();
+	if (neighbor != NULL) {
+
+		int spec_self =  organism->GetLineageLabel();
+		int spec_neighbor = neighbor->GetLineageLabel();
+		
+		if (spec_self != spec_neighbor) {
+			m_world->GetStats().IncDonateToDonor();
+			Inst_DonateFacingRawMaterialsOneType(ctx);	
+		}
+	}
 	return true;
-
 }
 
 /* Donate raw materials to the facing organism. */

Modified: branches/hjg-dev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.h	2008-11-16 18:11:58 UTC (rev 2945)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.h	2008-11-17 13:59:37 UTC (rev 2946)
@@ -316,7 +316,6 @@
   
 	// Reputation
 	void ComputeReputation();
-	double ComputeDonateBenefit();
 	
 private:
   // ---------- Instruction Library -----------
@@ -684,6 +683,8 @@
   bool Inst_DonateFacingRawMaterials(cAvidaContext& ctx);
   // Donate a raw material to the neighbor -- one type of raw material
   bool Inst_DonateFacingRawMaterialsOneType(cAvidaContext& ctx);
+	// Donate a raw material to the neighbor if it is another species
+	bool Inst_DonateFacingRawMaterialsOtherSpecies(cAvidaContext& ctx);
 	// Donate a raw material to the neighbor if it was a prior donor
 	bool Inst_DonateIfDonor(cAvidaContext& ctx);	
 	// Donate a raw material to the neighbor, if its reputation > k




More information about the Avida-cvs mailing list