[Avida-SVN] r2763 - in development/source: cpu main
connel42 at myxo.css.msu.edu
connel42 at myxo.css.msu.edu
Thu Aug 28 10:23:55 PDT 2008
Author: connel42
Date: 2008-08-28 13:23:54 -0400 (Thu, 28 Aug 2008)
New Revision: 2763
Modified:
development/source/cpu/cHardwareCPU.cc
development/source/main/cTaskLib.cc
Log:
Update movement and pheromone-sensing instructions and tasks to work better with the test CPU
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2008-08-27 13:22:23 UTC (rev 2762)
+++ development/source/cpu/cHardwareCPU.cc 2008-08-28 17:23:54 UTC (rev 2763)
@@ -4106,6 +4106,12 @@
// Declarations
int fromcellID, destcellID; //, actualNeighborhoodSize, fromFacing, destFacing, currentFacing;
+ fromcellID = organism->GetCellID(); //absolute id of current cell
+
+ if(fromcellID == -1) {
+ return false;
+ }
+
// Get population
cPopulation& pop = m_world->GetPopulation();
cDeme &deme = pop.GetDeme(pop.GetCell(organism->GetCellID()).GetDemeID());
@@ -4121,7 +4127,7 @@
// Code
if (0 < stepsize) {
// Current cell
- fromcellID = organism->GetCellID();
+ //fromcellID = organism->GetCellID();
// With sanity check
if (-1 == fromcellID) return false;
// Destination cell
@@ -5312,9 +5318,15 @@
// Sense if the organism is on a target -- put 1 in reg is so, 0 otherwise
bool cHardwareCPU::Inst_SenseTarget(cAvidaContext& ctx) {
int reg_to_set = FindModifiedRegister(REG_CX);
- int cell_data = m_world->GetPopulation().GetCell(organism->GetCellID()).GetCellData();
+ int cellid = organism->GetCellID();
+
+ if(cellid == -1) {
+ return false;
+ }
+
+ int cell_data = m_world->GetPopulation().GetCell(cellid).GetCellData();
int val = 0;
-
+
if(cell_data > 0) {
val = 1;
}
@@ -5328,11 +5340,17 @@
int reg_to_set = FindModifiedRegister(REG_CX);
cPopulation& pop = m_world->GetPopulation();
- cPopulationCell& mycell = pop.GetCell(organism->GetCellID());
-
+ int cellid = organism->GetCellID();
+
+ if(cellid == -1) {
+ return true;
+ }
+
+ cPopulationCell& mycell = pop.GetCell(cellid);
+
int cell_data = mycell.GetCellFaced().GetCellData(); //absolute id of faced cell
int val = 0;
-
+
if(cell_data > 0) {
val = 1;
}
@@ -5347,6 +5365,10 @@
{
int reg_to_set = FindModifiedRegister(REG_BX);
+ if(cellid == -1) {
+ return false;
+ }
+
cPopulation& pop = m_world->GetPopulation();
cDeme &deme = pop.GetDeme(pop.GetCell(cellid).GetDemeID());
int relative_cell_id = deme.GetRelativeCellID(cellid);
@@ -6454,7 +6476,13 @@
bool cHardwareCPU::Inst_IfTarget(cAvidaContext& ctx)
{
- int cell_data = m_world->GetPopulation().GetCell(organism->GetCellID()).GetCellData();
+ int cellid = organism->GetCellID(); //absolute id of current cell
+
+ if(cellid == -1) {
+ return true;
+ }
+
+ int cell_data = m_world->GetPopulation().GetCell(cellid).GetCellData();
if(cell_data == -1) {
IP().Advance();
@@ -6466,7 +6494,13 @@
bool cHardwareCPU::Inst_IfNotTarget(cAvidaContext& ctx)
{
- int cell_data = m_world->GetPopulation().GetCell(organism->GetCellID()).GetCellData();
+ int cellid = organism->GetCellID(); //absolute id of current cell
+
+ if(cellid == -1) {
+ return true;
+ }
+
+ int cell_data = m_world->GetPopulation().GetCell(cellid).GetCellData();
if(cell_data > 0) {
IP().Advance();
Modified: development/source/main/cTaskLib.cc
===================================================================
--- development/source/main/cTaskLib.cc 2008-08-27 13:22:23 UTC (rev 2762)
+++ development/source/main/cTaskLib.cc 2008-08-28 17:23:54 UTC (rev 2763)
@@ -2898,7 +2898,7 @@
return 1.0;
}
-double cTaskLib::Task_MoveToRightSide(cTaskContext& ctx) const {
+double cTaskLib::Task_MoveToRightSide(cTaskContext& ctx) const {
cDeme& deme = m_world->GetPopulation().GetDeme(ctx.GetOrgInterface()->GetDemeID());
std::pair<int, int> location = deme.GetCellPosition(ctx.GetOrgInterface()->GetCellID());
@@ -2931,6 +2931,11 @@
//Note - a generic version of this is now at - Task_MoveToMovementEvent
{
cOrgInterface* iface = ctx.GetOrgInterface();
+
+ if(ctx.GetOrganism()->GetCellID() == -1) {
+ return 0.0;
+ }
+
cDeme& deme = m_world->GetPopulation().GetDeme(ctx.GetOrgInterface()->GetDemeID());
int celldata = m_world->GetPopulation().GetCell(iface->GetCellID()).GetCellData();
@@ -2958,6 +2963,11 @@
} //End cTaskLib::TaskMoveToTarget()
double cTaskLib::Task_MoveToMovementEvent(cTaskContext& ctx) const {
+
+ if(ctx.GetOrganism()->GetCellID() == -1) {
+ return 0.0;
+ }
+
cDeme& deme = m_world->GetPopulation().GetDeme(ctx.GetOrgInterface()->GetDemeID());
int cell_data = m_world->GetPopulation().GetCell(ctx.GetOrgInterface()->GetCellID()).GetCellData();
cOrgInterface* iface = ctx.GetOrgInterface();
@@ -2977,6 +2987,11 @@
double cTaskLib::Task_MoveBetweenMovementEvent(cTaskContext& ctx) const {
+
+ if(ctx.GetOrganism()->GetCellID() == -1) {
+ return 0.0;
+ }
+
cDeme& deme = m_world->GetPopulation().GetDeme(ctx.GetOrgInterface()->GetDemeID());
int cell_data = m_world->GetPopulation().GetCell(ctx.GetOrgInterface()->GetCellID()).GetCellData();
cOrgInterface* iface = ctx.GetOrgInterface();
@@ -3019,6 +3034,11 @@
}
double cTaskLib::Task_MoveToEvent(cTaskContext& ctx) const {
+
+ if(ctx.GetOrganism()->GetCellID() == -1) {
+ return 0.0;
+ }
+
cDeme* deme = ctx.GetOrganism()->GetOrgInterface().GetDeme();
int cell_data = ctx.GetOrganism()->GetOrgInterface().GetCellData();
if(cell_data <= 0)
More information about the Avida-cvs
mailing list