[Avida-SVN] r2218 - in branches/energy/source: cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Sun Dec 2 17:35:18 PST 2007
Author: beckma24
Date: 2007-12-02 20:35:18 -0500 (Sun, 02 Dec 2007)
New Revision: 2218
Modified:
branches/energy/source/cpu/cHardwareCPU.cc
branches/energy/source/main/cOrganism.cc
branches/energy/source/main/cOrganism.h
branches/energy/source/main/cTaskLib.cc
branches/energy/source/main/cTaskLib.h
Log:
Added temp. hack for movement task
Modified: branches/energy/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.cc 2007-12-01 16:53:01 UTC (rev 2217)
+++ branches/energy/source/cpu/cHardwareCPU.cc 2007-12-03 01:35:18 UTC (rev 2218)
@@ -3908,6 +3908,18 @@
if (-1 == fromcellID) return false;
// Destination cell
destcellID = pop.GetCell(fromcellID).GetCellFaced().GetID();
+
+ /*********************/
+ // TEMP. Remove once movement tasks are implemented.
+ if(pop.GetCell(fromcellID).GetCellData() < pop.GetCell(destcellID).GetCellData()) { // move up gradient
+ organism->SetGradientMovement(1.0);
+ } else if(pop.GetCell(fromcellID).GetCellData() == pop.GetCell(destcellID).GetCellData()) {
+ organism->SetGradientMovement(0.0);
+ } else { // move down gradient
+ organism->SetGradientMovement(-1.0);
+ }
+ /*********************/
+
// Actually perform the move using SwapCells
//cout << "SwapCells: " << fromcellID << " to " << destcellID << endl;
pop.SwapCells(pop.GetCell(fromcellID),pop.GetCell(destcellID));
@@ -3917,6 +3929,8 @@
// updates movement predicates
m_world->GetStats().Move(*organism);
+ // check tasks. general movement tasks are not yet supported.
+ organism->DoOutput(ctx);
return true;
} else {
return false;
Modified: branches/energy/source/main/cOrganism.cc
===================================================================
--- branches/energy/source/main/cOrganism.cc 2007-12-01 16:53:01 UTC (rev 2217)
+++ branches/energy/source/main/cOrganism.cc 2007-12-03 01:35:18 UTC (rev 2218)
@@ -66,6 +66,7 @@
, m_sent_value(0)
, m_sent_active(false)
, m_test_receive_pos(0)
+ , m_gradient_movement(0.0) // TEMP. Remove once movement tasks are implemented.
, m_max_executed(-1)
, m_is_running(false)
, m_is_sleeping(false)
Modified: branches/energy/source/main/cOrganism.h
===================================================================
--- branches/energy/source/main/cOrganism.h 2007-12-01 16:53:01 UTC (rev 2217)
+++ branches/energy/source/main/cOrganism.h 2007-12-03 01:35:18 UTC (rev 2218)
@@ -118,6 +118,8 @@
bool m_sent_active; // Has this org sent a number?
int m_test_receive_pos; // In a test CPU, what message to receive next?
+ double m_gradient_movement; // TEMP. Remove once movement tasks are implemented.
+
int m_max_executed; // Max number of instruction executed before death.
bool m_is_running; // Does this organism have the CPU?
bool m_is_sleeping; // Is this organisms sleeping?
@@ -351,6 +353,18 @@
//! Called to check for (and initialize) messaging support within this organism.
inline void InitMessaging() { if(!m_msg) m_msg = new cMessagingSupport(); }
// -------- End of messaging support --------
+
+
+ // -------- Movement TEMP --------
+public:
+ const double GetGradientMovement() const {
+ return m_gradient_movement;
+ }
+
+ void SetGradientMovement(const double value) {
+ m_gradient_movement = value;
+ }
+
};
Modified: branches/energy/source/main/cTaskLib.cc
===================================================================
--- branches/energy/source/main/cTaskLib.cc 2007-12-01 16:53:01 UTC (rev 2217)
+++ branches/energy/source/main/cTaskLib.cc 2007-12-03 01:35:18 UTC (rev 2218)
@@ -385,6 +385,15 @@
else if (name == "net_sentEventID")
NewTask(name, "Successfully sent an event ID in a network message", &cTaskLib::Task_SentEventID);
+ // Movement Tasks
+ if (name == "move_up_gradient")
+ NewTask(name, "Move up gradient", &cTaskLib::Task_MoveUpGradient);
+ else if (name == "move_down_gradient")
+ NewTask(name, "Move down gradient", &cTaskLib::Task_MoveDownGradient);
+
+
+
+
// Make sure we have actually found a task
if (task_array.GetSize() == start_size) {
if (errors != NULL && errors->GetSize() == 0) {
@@ -2750,3 +2759,14 @@
return 0.0;
}
+double cTaskLib::Task_MoveUpGradient(cTaskContext& ctx) const {
+ if(ctx.GetOrganism()->GetGradientMovement() == 1.0)
+ return 1.0;
+ return 0.0;
+}
+
+double cTaskLib::Task_MoveDownGradient(cTaskContext& ctx) const {
+ if(ctx.GetOrganism()->GetGradientMovement() == -1.0)
+ return 1.0;
+ return 0.0;
+}
Modified: branches/energy/source/main/cTaskLib.h
===================================================================
--- branches/energy/source/main/cTaskLib.h 2007-12-01 16:53:01 UTC (rev 2217)
+++ branches/energy/source/main/cTaskLib.h 2007-12-03 01:35:18 UTC (rev 2218)
@@ -276,6 +276,10 @@
double Task_NetSend(cTaskContext& ctx) const;
double Task_NetReceive(cTaskContext& ctx) const;
double Task_SentEventID(cTaskContext& ctx) const;
+
+ // Movement tasks (temp, rely on hack)
+ double Task_MoveUpGradient(cTaskContext& ctx) const;
+ double Task_MoveDownGradient(cTaskContext& ctx) const;
};
More information about the Avida-cvs
mailing list