[Avida-SVN] r2126 - branches/dkdev/source/main

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Fri Oct 5 11:23:11 PDT 2007


Author: dknoester
Date: 2007-10-05 14:23:03 -0400 (Fri, 05 Oct 2007)
New Revision: 2126

Modified:
   branches/dkdev/source/main/cOrganism.h
   branches/dkdev/source/main/cTaskLib.cc
   branches/dkdev/source/main/cTaskLib.h
Log:
Added tasks to reward for detection top-half/bottom-half location in environment.

Modified: branches/dkdev/source/main/cOrganism.h
===================================================================
--- branches/dkdev/source/main/cOrganism.h	2007-10-04 14:29:20 UTC (rev 2125)
+++ branches/dkdev/source/main/cOrganism.h	2007-10-05 18:23:03 UTC (rev 2126)
@@ -283,7 +283,6 @@
   int _region;
 public:
   void SetRegion(int region) { if(!_region_latched) { _region = region; _region_latched = true; } }
-  
   int GetRegion() const { return _region; }
   bool IsRegionLatched() const { return _region_latched; }
 };

Modified: branches/dkdev/source/main/cTaskLib.cc
===================================================================
--- branches/dkdev/source/main/cTaskLib.cc	2007-10-04 14:29:20 UTC (rev 2125)
+++ branches/dkdev/source/main/cTaskLib.cc	2007-10-05 18:23:03 UTC (rev 2126)
@@ -332,7 +332,20 @@
   if(name == "correct-region")
     NewTask(name, "Determined whether in the correct region of the environment", &cTaskLib::Task_CorrectRegion);
 
+  if(name == "top-half")
+    NewTask(name, "Determined whether in the top half of the environment", &cTaskLib::Task_TopHalf);
+  else if(name == "bottom-half")
+    NewTask(name, "Determined whether in the bottom half of the environment", &cTaskLib::Task_BottomHalf);
+  else if(name == "top-forward-diag")
+    NewTask(name, "Determined whether in the top forward diagonal region of the environment", &cTaskLib::Task_BottomHalf);
+  else if(name == "bottom-forward-diag")
+    NewTask(name, "Determined whether in the bottom forward diagonal region of the environment", &cTaskLib::Task_BottomHalf);
+  else if(name == "top-backward-diag")
+    NewTask(name, "Determined whether in the top backward diagonal region of the environment", &cTaskLib::Task_BottomHalf);
+  else if(name == "bottom-backward-diag")
+    NewTask(name, "Determined whether in the bottom backward diagonal region of the environment", &cTaskLib::Task_BottomHalf);
   
+  
   // Make sure we have actually found a task  
   if (task_array.GetSize() == start_size) {
     cerr << "Unknown task entry '" << name << "'." << endl;
@@ -1915,3 +1928,127 @@
   m_world->GetStats().TwoCellsPartialRegion();
   return 1.0;
 }
+
+
+double cTaskLib::Task_TopHalf(cTaskContext* ctx) const {
+  cOrganism* organism = ctx->GetOrganism();
+  
+  // Did the organism even make a decision?
+  if(!organism->IsRegionLatched()) {
+    m_world->GetStats().TwoCellsUnlatched();
+    return 0.0;
+  }
+
+  cPopulationCell& cell = m_world->GetPopulation().GetCell(organism->GetCellID());
+  cDeme& deme = m_world->GetPopulation().GetDeme(cell.GetDemeID());
+
+  std::pair<int,int> deme_xy = std::make_pair(deme.GetWidth(), deme.GetHeight());
+  std::pair<int,int> self_xy = deme.GetCellPosition(organism->GetCellID());
+
+  if((self_xy.second >= (deme_xy.second/2)) && (organism->GetRegion()==1)) {
+    return 1.0;
+  } else {
+    return 0.0;
+  }
+}
+
+
+double cTaskLib::Task_BottomHalf(cTaskContext* ctx) const {
+  cOrganism* organism = ctx->GetOrganism();
+  
+  // Did the organism even make a decision?
+  if(!organism->IsRegionLatched()) {
+    m_world->GetStats().TwoCellsUnlatched();
+    return 0.0;
+  }
+  
+  cPopulationCell& cell = m_world->GetPopulation().GetCell(organism->GetCellID());
+  cDeme& deme = m_world->GetPopulation().GetDeme(cell.GetDemeID());
+
+  std::pair<int,int> deme_xy = std::make_pair(deme.GetWidth(), deme.GetHeight());
+  std::pair<int,int> self_xy = deme.GetCellPosition(organism->GetCellID());
+  
+  if((self_xy.second <= (deme_xy.second/2)) && (organism->GetRegion()==0)) {
+    return 1.0;
+  } else {
+    return 0.0;
+  }
+}
+
+
+double cTaskLib::Task_TopForwardDiagonal(cTaskContext* ctx) const {
+  cOrganism* organism = ctx->GetOrganism();
+  
+  // Did the organism even make a decision?
+  if(!organism->IsRegionLatched()) {
+    m_world->GetStats().TwoCellsUnlatched();
+    return 0.0;
+  }
+  
+  cPopulationCell& cell = m_world->GetPopulation().GetCell(organism->GetCellID());
+  cDeme& deme = m_world->GetPopulation().GetDeme(cell.GetDemeID());
+  
+  std::pair<int,int> deme_xy = std::make_pair(deme.GetWidth(), deme.GetHeight());
+  std::pair<int,int> self_xy = deme.GetCellPosition(organism->GetCellID());
+
+  if(((self_xy.second - self_xy.first) >= 0) && (organism->GetRegion()==1)) {
+    return 1.0;
+  } else {
+    return 0.0;
+  }
+}
+
+
+double cTaskLib::Task_BottomForwardDiagonal(cTaskContext* ctx) const {
+  cOrganism* organism = ctx->GetOrganism();
+  
+  // Did the organism even make a decision?
+  if(!organism->IsRegionLatched()) {
+    m_world->GetStats().TwoCellsUnlatched();
+    return 0.0;
+  }
+  
+  cPopulationCell& cell = m_world->GetPopulation().GetCell(organism->GetCellID());
+  cDeme& deme = m_world->GetPopulation().GetDeme(cell.GetDemeID());
+  
+  std::pair<int,int> deme_xy = std::make_pair(deme.GetWidth(), deme.GetHeight());
+  std::pair<int,int> self_xy = deme.GetCellPosition(organism->GetCellID());
+
+  if(((self_xy.second - self_xy.first) <= 0) && (organism->GetRegion()==0)) {
+    return 1.0;
+  } else {
+    return 0.0;
+  }  
+}
+
+
+double cTaskLib::Task_TopBackwardDiagonal(cTaskContext* ctx) const {
+  cOrganism* organism = ctx->GetOrganism();
+  
+  // Did the organism even make a decision?
+  if(!organism->IsRegionLatched()) {
+    m_world->GetStats().TwoCellsUnlatched();
+    return 0.0;
+  }
+  
+  cPopulationCell& cell = m_world->GetPopulation().GetCell(organism->GetCellID());
+  cDeme& deme = m_world->GetPopulation().GetDeme(cell.GetDemeID());
+  
+  return 0.0;
+}
+
+
+double cTaskLib::Task_BottomBackwardDiagonal(cTaskContext* ctx) const {
+  cOrganism* organism = ctx->GetOrganism();
+  
+  // Did the organism even make a decision?
+  if(!organism->IsRegionLatched()) {
+    m_world->GetStats().TwoCellsUnlatched();
+    return 0.0;
+  }
+  
+  cPopulationCell& cell = m_world->GetPopulation().GetCell(organism->GetCellID());
+  cDeme& deme = m_world->GetPopulation().GetDeme(cell.GetDemeID());
+  
+  return 0.0;
+}

Modified: branches/dkdev/source/main/cTaskLib.h
===================================================================
--- branches/dkdev/source/main/cTaskLib.h	2007-10-04 14:29:20 UTC (rev 2125)
+++ branches/dkdev/source/main/cTaskLib.h	2007-10-05 18:23:03 UTC (rev 2126)
@@ -227,6 +227,15 @@
   
   double Task_SentIdFromPerimeter(cTaskContext* ctx) const;
   double Task_CorrectRegion(cTaskContext* ctx) const;
+  
+  double Task_TopHalf(cTaskContext* ctx) const;
+  double Task_BottomHalf(cTaskContext* ctx) const;
+  
+  double Task_TopForwardDiagonal(cTaskContext* ctx) const;
+  double Task_BottomForwardDiagonal(cTaskContext* ctx) const;
+
+  double Task_TopBackwardDiagonal(cTaskContext* ctx) const;
+  double Task_BottomBackwardDiagonal(cTaskContext* ctx) const;
 };
 
 




More information about the Avida-cvs mailing list