[Avida-SVN] r3058 - branches/hjg-dev/source/cpu
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Thu Dec 18 12:19:48 PST 2008
Author: hjg
Date: 2008-12-18 15:19:48 -0500 (Thu, 18 Dec 2008)
New Revision: 3058
Modified:
branches/hjg-dev/source/cpu/cHardwareCPU.cc
branches/hjg-dev/source/cpu/cHardwareCPU.h
Log:
added donate-string-if-rep instruction, which only donates if the neighbor has a reputation > 0
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-12-18 16:06:28 UTC (rev 3057)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-12-18 20:19:48 UTC (rev 3058)
@@ -463,8 +463,8 @@
tInstLibEntry<tMethod>("donate-string", &cHardwareCPU::Inst_DonateString, nInstFlag::STALL),
tInstLibEntry<tMethod>("donate-if-donor", &cHardwareCPU::Inst_DonateIfDonor, nInstFlag::STALL),
tInstLibEntry<tMethod>("donate-string-if-donor", &cHardwareCPU::Inst_DonateStringIfDonor, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("donate-string-if-donor-rep", &cHardwareCPU::Inst_DonateStringIfDonorRep, nInstFlag::STALL),
-
tInstLibEntry<tMethod>("get-neighbors-reputation", &cHardwareCPU::Inst_GetNeighborsReputation, nInstFlag::STALL),
tInstLibEntry<tMethod>("get-reputation", &cHardwareCPU::Inst_GetReputation, nInstFlag::STALL),
tInstLibEntry<tMethod>("get-raw-mat-amount", &cHardwareCPU::Inst_GetAmountOfRawMaterials, nInstFlag::STALL),
@@ -7445,6 +7445,21 @@
return true;
}
+
+/* Donate if the neighbor has a reputation of > 0 */
+bool cHardwareCPU::Inst_DonateStringIfDonorRep(cAvidaContext& ctx)
+{
+ cOrganism * neighbor = organism->GetNeighbor();
+ if (neighbor != NULL) {
+ // check if the neighbor was a donor
+ if (neighbor->GetReputation()) {
+ Inst_DonateString(ctx);
+ }
+ }
+ return true;
+}
+
+
/* This instruction does not do anything, but rather is used
as a signal to indicate that the organism has chosen to perform
the string cat task. */
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.h 2008-12-18 16:06:28 UTC (rev 3057)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.h 2008-12-18 20:19:48 UTC (rev 3058)
@@ -691,6 +691,8 @@
bool Inst_DonateFacingRawMaterialsOtherSpecies(cAvidaContext& ctx);
// Donate a raw material to the neighbor if it was a prior donor
bool Inst_DonateIfDonor(cAvidaContext& ctx);
+ // Donate a string to the neighbor, if it's reputation is > 0
+ bool Inst_DonateStringIfDonorRep(cAvidaContext& ctx);
// Donate a raw material to the neighbor, if its reputation > k
bool Inst_DonateFacingConditionalOnK(cAvidaContext& ctx);
// Donate string
More information about the Avida-cvs
mailing list