[Avida-SVN] r2570 - branches/energy/source/cpu

connel42 at myxo.css.msu.edu connel42 at myxo.css.msu.edu
Thu May 1 13:20:37 PDT 2008


Author: connel42
Date: 2008-05-01 16:20:37 -0400 (Thu, 01 May 2008)
New Revision: 2570

Modified:
   branches/energy/source/cpu/cHardwareCPU.cc
   branches/energy/source/cpu/cHardwareCPU.h
Log:
* added if-not-target instruction
* fixed bugs in if-target, movetarget, exploit, and supermove commands



Modified: branches/energy/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.cc	2008-05-01 13:52:20 UTC (rev 2569)
+++ branches/energy/source/cpu/cHardwareCPU.cc	2008-05-01 20:20:37 UTC (rev 2570)
@@ -257,6 +257,7 @@
     tInstLibEntry<tMethod>("movetarget", &cHardwareCPU::Inst_MoveTarget),
     tInstLibEntry<tMethod>("supermove", &cHardwareCPU::Inst_SuperMove),
     tInstLibEntry<tMethod>("if-target", &cHardwareCPU::Inst_IfTarget),
+    tInstLibEntry<tMethod>("if-not-target", &cHardwareCPU::Inst_IfNotTarget),
     tInstLibEntry<tMethod>("if-pheromone", &cHardwareCPU::Inst_IfPheromone),
     tInstLibEntry<tMethod>("drop-pheromone", &cHardwareCPU::Inst_DropPheromone),
 
@@ -3184,9 +3185,11 @@
   double pher_amount = 0;
   int drop_mode = -1;
 
+  cPopulationCell faced = mycell.GetCellFaced();
+
   // Find if any neighbor is a target
   for(int i = 0; i < mycell.ConnectionList().GetSize(); i++) {
-    cell_data = m_world->GetPopulation().GetCell(organism->GetCellID()).GetCellData();
+    cell_data = mycell.GetCellFaced().GetCellData();
 
     if(cell_data > 0) {
       num_rotations = i;
@@ -3195,6 +3198,8 @@
     mycell.ConnectionList().CircNext();
   }
 
+  assert(faced == pop.GetCell(fromcellID).GetCellFaced());
+
   // Rotate until we face the neighbor with a target.
   // If there was no winner, just move forward.
   for(int i = 0; i < num_rotations; i++) {
@@ -3315,6 +3320,7 @@
   for(int i = 0; i < mycell.ConnectionList().GetSize(); i++) {
 
     phero_amount = 0;
+    cell_resources = deme_resource_count.GetCellResources(deme.GetRelativeCellID(mycell.GetCellFaced().GetID()));
 
     for (int j = 0; j < deme_resource_count.GetSize(); j++) {
       if(strcmp(deme_resource_count.GetResName(j), "pheromone") == 0) {
@@ -3332,7 +3338,7 @@
 
   // Find if any neighbor is a target -- highest priority
   for(int i = 0; i < mycell.ConnectionList().GetSize(); i++) {
-    cell_data = m_world->GetPopulation().GetCell(organism->GetCellID()).GetCellData();
+    cell_data = mycell.GetCellFaced().GetCellData();
 
     if(cell_data > 0) {
       num_rotations = i;
@@ -3541,7 +3547,8 @@
   cDeme &deme = pop.GetDeme(pop.GetCell(cellid).GetDemeID());
   cResourceCount deme_resource_count = deme.GetDemeResourceCount();
   int relative_cell_id = deme.GetRelativeCellID(cellid);
-  tArray<double> cell_resources = deme_resource_count.GetCellResources(relative_cell_id);
+  //tArray<double> cell_resources = deme_resource_count.GetCellResources(relative_cell_id);
+  tArray<double> cell_resources;
 
   int fromcellID, destcellID;
   
@@ -3557,6 +3564,7 @@
   for(int i = 0; i < mycell.ConnectionList().GetSize(); i++) {
 
     phero_amount = 0;
+    cell_resources = deme_resource_count.GetCellResources(deme.GetRelativeCellID(mycell.GetCellFaced().GetID()));
 
     for (int j = 0; j < deme_resource_count.GetSize(); j++) {
       if(strcmp(deme_resource_count.GetResName(j), "pheromone") == 0) {
@@ -3659,7 +3667,7 @@
 {
   int cell_data = m_world->GetPopulation().GetCell(organism->GetCellID()).GetCellData();
 
-  if(cell_data > 0) {
+  if(cell_data == -1) {
     IP().Advance();
   }
 
@@ -3667,6 +3675,18 @@
 } //End Inst_IfTarget()
 
 
+bool cHardwareCPU::Inst_IfNotTarget(cAvidaContext& ctx)
+{
+  int cell_data = m_world->GetPopulation().GetCell(organism->GetCellID()).GetCellData();
+
+  if(cell_data > 0) {
+    IP().Advance();
+  }
+
+  return true;
+} //End Inst_IfNotTarget()
+
+
 bool cHardwareCPU::Inst_IfPheromone(cAvidaContext& ctx)
 {
   int cellid = organism->GetCellID(); //absolute id of current cell

Modified: branches/energy/source/cpu/cHardwareCPU.h
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.h	2008-05-01 13:52:20 UTC (rev 2569)
+++ branches/energy/source/cpu/cHardwareCPU.h	2008-05-01 20:20:37 UTC (rev 2570)
@@ -503,6 +503,7 @@
   bool Inst_MoveTarget(cAvidaContext& ctx);
   bool Inst_SuperMove(cAvidaContext& ctx);
   bool Inst_IfTarget(cAvidaContext& ctx);
+  bool Inst_IfNotTarget(cAvidaContext& ctx);
   bool Inst_IfPheromone(cAvidaContext& ctx);
   bool Inst_DropPheromone(cAvidaContext& ctx);
 




More information about the Avida-cvs mailing list