[Avida-SVN] r3352 - in development/source: cpu main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Mon Jul 6 13:53:35 PDT 2009


Author: beckma24
Date: 2009-07-06 16:53:35 -0400 (Mon, 06 Jul 2009)
New Revision: 3352

Modified:
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
   development/source/main/cPopulation.cc
Log:
Added instruction if-opinion-notset and sense-pheromone-global

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2009-07-06 13:45:19 UTC (rev 3351)
+++ development/source/cpu/cHardwareCPU.cc	2009-07-06 20:53:35 UTC (rev 3352)
@@ -509,6 +509,7 @@
     tInstLibEntry<tMethod>("sense-pheromone", &cHardwareCPU::Inst_SensePheromone),
     tInstLibEntry<tMethod>("sense-pheromone-faced", &cHardwareCPU::Inst_SensePheromoneFaced),
     tInstLibEntry<tMethod>("sense-pheromone-inDemeGlobal", &cHardwareCPU::Inst_SensePheromoneInDemeGlobal),
+		tInstLibEntry<tMethod>("sense-pheromone-global", &cHardwareCPU::Inst_SensePheromoneGlobal),
     tInstLibEntry<tMethod>("exploit", &cHardwareCPU::Inst_Exploit, nInstFlag::STALL),
     tInstLibEntry<tMethod>("exploit-forward5", &cHardwareCPU::Inst_ExploitForward5, nInstFlag::STALL),
     tInstLibEntry<tMethod>("exploit-forward3", &cHardwareCPU::Inst_ExploitForward3, nInstFlag::STALL),
@@ -530,6 +531,7 @@
 		tInstLibEntry<tMethod>("get-opinionOnly", &cHardwareCPU::Inst_GetOpinionOnly_ZeroIfNone, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("clear-opinion", &cHardwareCPU::Inst_ClearOpinion, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("if-opinion-set", &cHardwareCPU::Inst_IfOpinionSet, nInstFlag::STALL),
+		tInstLibEntry<tMethod>("if-opinion-notset", &cHardwareCPU::Inst_IfOpinionNotSet, nInstFlag::STALL),
 		
 		// Data collection
 		tInstLibEntry<tMethod>("if-cell-data-changed", &cHardwareCPU::Inst_IfCellDataChanged, nInstFlag::STALL),
@@ -7009,6 +7011,22 @@
 	return true;
 }
 
+bool cHardwareCPU::DoSensePheromoneGlobal(cAvidaContext& ctx) {
+	int reg_to_set = FindModifiedRegister(REG_BX);
+	const cResourceCount& resource_count = m_world->GetPopulation().GetResourceCount();
+	
+	if(resource_count.GetSize() == 0) assert(false); // change to: return false;
+	
+	double pher_amount = 0;
+	for (int i = 0; i < resource_count.GetSize(); i++) {
+    if(strncmp(resource_count.GetResName(i), "pheromone", 9) == 0) {
+      pher_amount += resource_count.Get(i);
+    }
+  }
+	GetRegister(reg_to_set) = (int)floor(pher_amount + 0.5);
+	return true;
+}
+
 bool cHardwareCPU::Inst_SensePheromone(cAvidaContext& ctx)
 {
   int cellid = m_organism->GetCellID(); //absolute id of current cell
@@ -7040,6 +7058,10 @@
 	return DoSensePheromoneInDemeGlobal(ctx);
 }
 
+bool cHardwareCPU::Inst_SensePheromoneGlobal(cAvidaContext& ctx) {
+	return DoSensePheromoneGlobal(ctx);
+}
+
 bool cHardwareCPU::Inst_Exploit(cAvidaContext& ctx)
 {
   int num_rotations = 0;
@@ -8315,8 +8337,15 @@
   return true;
 }
 
+bool cHardwareCPU::Inst_IfOpinionNotSet(cAvidaContext& ctx)
+{
+	assert(m_organism != 0);
+  if(m_organism->HasOpinion()) IP().Advance();
+  return true;
+}
 
 
+
 /*! Collect this cell's data, and place it in ?BX?.  Set the flag indicating that
  this organism has collected cell data to true, and set the last collected cell data
  as well.

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2009-07-06 13:45:19 UTC (rev 3351)
+++ development/source/cpu/cHardwareCPU.h	2009-07-06 20:53:35 UTC (rev 3352)
@@ -775,9 +775,11 @@
   bool Inst_SenseTargetFaced(cAvidaContext& ctx);
   bool DoSensePheromone(cAvidaContext& ctx, int cellid);
 	bool DoSensePheromoneInDemeGlobal(cAvidaContext& ctx);
+	bool DoSensePheromoneGlobal(cAvidaContext& ctx);
   bool Inst_SensePheromone(cAvidaContext& ctx);
   bool Inst_SensePheromoneFaced(cAvidaContext& ctx);
 	bool Inst_SensePheromoneInDemeGlobal(cAvidaContext& ctx);
+	bool Inst_SensePheromoneGlobal(cAvidaContext& ctx);
   bool Inst_Exploit(cAvidaContext& ctx);
   bool Inst_ExploitForward5(cAvidaContext& ctx);
   bool Inst_ExploitForward3(cAvidaContext& ctx);
@@ -811,6 +813,7 @@
   bool Inst_ClearOpinion(cAvidaContext& ctx);
 	//! Execute next instruction is org has an opinion, otherwise skip
 	bool Inst_IfOpinionSet(cAvidaContext& ctx);
+	bool Inst_IfOpinionNotSet(cAvidaContext& ctx);
 
 	// -------- Cell Data Support --------
 public:

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2009-07-06 13:45:19 UTC (rev 3351)
+++ development/source/main/cPopulation.cc	2009-07-06 20:53:35 UTC (rev 3352)
@@ -5074,7 +5074,7 @@
   InjectGenotype( cell_id, new_genotype );
 }
 
-
+// Note: cPopulation::SerialTransfer does not respect deme boundaries and only acts on a single population.
 void cPopulation::SerialTransfer(int transfer_size, bool ignore_deads)
 {
   assert(transfer_size > 0);




More information about the Avida-cvs mailing list