[Avida-SVN] r3392 - development/source/cpu

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Wed Sep 2 12:58:53 PDT 2009


Author: beckma24
Date: 2009-09-02 15:58:53 -0400 (Wed, 02 Sep 2009)
New Revision: 3392

Modified:
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
Log:
Adding instructions if-notAboveResLevel.end and if-aboveResLevel.end

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2009-09-01 06:01:06 UTC (rev 3391)
+++ development/source/cpu/cHardwareCPU.cc	2009-09-02 19:58:53 UTC (rev 3392)
@@ -110,7 +110,9 @@
     tInstLibEntry<tMethod>("if-equ-X", &cHardwareCPU::Inst_IfEquX),
 		
 		tInstLibEntry<tMethod>("if-aboveResLevel", &cHardwareCPU::Inst_IfAboveResLevel),
+		tInstLibEntry<tMethod>("if-aboveResLevel.end", &cHardwareCPU::Inst_IfAboveResLevelEnd),
 		tInstLibEntry<tMethod>("if-notAboveResLevel", &cHardwareCPU::Inst_IfNotAboveResLevel),
+		tInstLibEntry<tMethod>("if-notAboveResLevel.end", &cHardwareCPU::Inst_IfNotAboveResLevelEnd),
 
 		// Probabilistic ifs.
 		tInstLibEntry<tMethod>("if-p-0.125", &cHardwareCPU::Inst_IfP0p125, nInstFlag::STALL),
@@ -2102,6 +2104,30 @@
 	return true;
 }
 
+bool cHardwareCPU::Inst_IfAboveResLevelEnd(cAvidaContext& ctx) {
+	const double resCrossoverLevel = 100;
+	
+	const cResourceLib& resLib = m_world->GetEnvironment().GetResourceLib();
+	
+	const tArray<double>& resource_count_array =  GetOrganism()->GetOrgInterface().GetResources(); 
+	const cResourceCount& resource_count = m_world->GetPopulation().GetResourceCount();
+	
+	if(resource_count.GetSize() == 0) assert(false); // change to: return false;
+	
+	double pher_amount = 0;
+	cResource* res = resLib.GetResource("pheromone");
+	
+	if(strncmp(resource_count.GetResName(res->GetID()), "pheromone", 9) == 0) {
+		pher_amount += resource_count_array[res->GetID()];
+	}
+	
+	if(pher_amount > resCrossoverLevel) {
+		Else_TopHalf();
+	}
+	
+	return true;
+}
+
 bool cHardwareCPU::Inst_IfNotAboveResLevel(cAvidaContext& ctx) {
 	const double resCrossoverLevel = 100;
 	
@@ -2126,6 +2152,30 @@
 	return true;
 }
 
+bool cHardwareCPU::Inst_IfNotAboveResLevelEnd(cAvidaContext& ctx) {
+	const double resCrossoverLevel = 100;
+	
+	const cResourceLib& resLib = m_world->GetEnvironment().GetResourceLib();
+	
+	const tArray<double>& resource_count_array =  GetOrganism()->GetOrgInterface().GetResources(); 
+	const cResourceCount& resource_count = m_world->GetPopulation().GetResourceCount();
+	
+	if(resource_count.GetSize() == 0) assert(false); // change to: return false;
+	
+	double pher_amount = 0;
+	cResource* res = resLib.GetResource("pheromone");
+	
+	if(strncmp(resource_count.GetResName(res->GetID()), "pheromone", 9) == 0) {
+		pher_amount += resource_count_array[res->GetID()];
+	}
+	
+	if(pher_amount <= resCrossoverLevel) {
+		Else_TopHalf();
+	}
+	
+	return true;
+}
+
 bool cHardwareCPU::Inst_IfP0p125(cAvidaContext& ctx) {
 	if(m_world->GetRandom().P(0.875)) {
 		IP().Advance();

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2009-09-01 06:01:06 UTC (rev 3391)
+++ development/source/cpu/cHardwareCPU.h	2009-09-02 19:58:53 UTC (rev 3392)
@@ -347,7 +347,9 @@
   bool Inst_IfEquX(cAvidaContext& ctx);
 	
 	bool Inst_IfAboveResLevel(cAvidaContext& ctx);
+	bool Inst_IfAboveResLevelEnd(cAvidaContext& ctx);
 	bool Inst_IfNotAboveResLevel(cAvidaContext& ctx);
+	bool Inst_IfNotAboveResLevelEnd(cAvidaContext& ctx);
 
 	// Probabilistic ifs.
 	bool Inst_IfP0p125(cAvidaContext& ctx);




More information about the Avida-cvs mailing list