[Avida-SVN] r3019 - branches/movement/source/cpu
welsberr at myxo.css.msu.edu
welsberr at myxo.css.msu.edu
Thu Dec 11 09:30:24 PST 2008
Author: welsberr
Date: 2008-12-11 12:30:24 -0500 (Thu, 11 Dec 2008)
New Revision: 3019
Modified:
branches/movement/source/cpu/cHardwareCPU.cc
Log:
Additional comments for cHardwareCPU.cc
Modified: branches/movement/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/movement/source/cpu/cHardwareCPU.cc 2008-12-10 15:27:07 UTC (rev 3018)
+++ branches/movement/source/cpu/cHardwareCPU.cc 2008-12-11 17:30:24 UTC (rev 3019)
@@ -209,6 +209,7 @@
tInstLibEntry<tMethod>("sense", &cHardwareCPU::Inst_SenseLog2, nInstFlag::STALL), // If you add more sense instructions
tInstLibEntry<tMethod>("sense-unit", &cHardwareCPU::Inst_SenseUnit, nInstFlag::STALL), // and want to keep stats, also add
tInstLibEntry<tMethod>("sense-m100", &cHardwareCPU::Inst_SenseMult100, nInstFlag::STALL), // the names to cStats::cStats() @JEB
+ // @WRE: Single local knowledge sense instruction
tInstLibEntry<tMethod>("sense-diff-facing", &cHardwareCPU::Inst_SenseDiffFacing, nInstFlag::STALL),
tInstLibEntry<tMethod>("if-resources", &cHardwareCPU::Inst_IfResources, nInstFlag::STALL),
tInstLibEntry<tMethod>("collect", &cHardwareCPU::Inst_Collect, nInstFlag::STALL),
@@ -3320,11 +3321,17 @@
// Note that we are converting <double> resources to <int> register values
}
+// sense-diff-facing instruction
+// @WRE: 3 Oct 2008
+// This implements a sense instruction that gets resource information from two cells,
+// the one currently occupied and the one currently faced, and puts the difference of those
+// values into the BX register, clearing the CX register.
bool cHardwareCPU::Inst_SenseDiffFacing(cAvidaContext& ctx)
{
return DoSenseDiffFacing(ctx, 1, 1000);
}
-
+
+// @WRE: Helper method that implements the sense-diff-facing instruction. 3 Oct 2008
bool cHardwareCPU::DoSenseDiffFacing(cAvidaContext& ctx, int conversion_method, double base)
{
// Returns the amount of a resource or resources
@@ -3362,6 +3369,7 @@
if (0 > organism->GetCellID()) return false;
facedcellID = pop.GetCell(organism->GetCellID()).GetCellFaced().GetID();
if (0 > facedcellID) return false;
+
const tArray<double> & facedres_count = pop.GetResourceCount().GetCellResources(facedcellID);
// Arbitrarily set to BX since the conditional instructions use this directly.
@@ -3429,13 +3437,13 @@
if (conversion_method == 0) // Log
{
// for log, add together and then take log
- dresource_result += ( (double) facedres_count[i] - (double) res_count[i]);
+ dresource_result += ( (double) facedres_count[i] - (double) res_count[i]);
}
else if (conversion_method == 1) // Addition of multiplied resource amount
{
int add_amount = ( (int) ((facedres_count[i] - res_count[i]) * base));
// Do some range checking to make sure we don't overflow
- resource_result = (INT_MAX - resource_result <= add_amount) ? INT_MAX : resource_result + add_amount;
+ resource_result = (INT_MAX - resource_result <= add_amount) ? INT_MAX : resource_result + add_amount;
}
}
}
More information about the Avida-cvs
mailing list