[Avida-SVN] r2810 - in branches/hjg-dev/source: cpu main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Tue Sep 30 10:08:45 PDT 2008
Author: hjg
Date: 2008-09-30 13:08:45 -0400 (Tue, 30 Sep 2008)
New Revision: 2810
Modified:
branches/hjg-dev/source/cpu/cHardwareCPU.cc
branches/hjg-dev/source/cpu/cHardwareCPU.h
branches/hjg-dev/source/main/cOrganism.cc
branches/hjg-dev/source/main/cOrganism.h
Log:
added if-donor instruction
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-09-30 16:52:29 UTC (rev 2809)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-09-30 17:08:45 UTC (rev 2810)
@@ -452,8 +452,10 @@
// Reputation instructions
tInstLibEntry<tMethod>("donate-frm", &cHardwareCPU::Inst_DonateFacingRawMaterials, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("if-donor", &cHardwareCPU::Inst_IfDonor, nInstFlag::STALL),
+
// Must always be the last instruction in the array
tInstLibEntry<tMethod>("NULL", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
};
@@ -6689,7 +6691,7 @@
// Subtract raw materials from the organism (currently subtracts 1 resource...)
// fails if the organism does not have any more resources
if (organism->SubtractSelfRawMaterials(1)) {
- neighbor->AddOtherRawMaterials(1);
+ neighbor->AddOtherRawMaterials(1, organism->GetID());
// rotate recipient to face donor
// by rotating until the recipient faces the donor
@@ -6701,3 +6703,14 @@
}
return isSuccessful;
}
+
+
+/* Check if the neighbor organism that you are facing has previously donated
+to you. If so, */
+bool cHardwareCPU::Inst_IfDonor(cAvidaContext& ctx)
+{
+ if (!(organism->IsDonor(organism->GetNeighbor()->GetID())))
+ IP().Advance();
+ return true;
+}
+
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.h 2008-09-30 16:52:29 UTC (rev 2809)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.h 2008-09-30 17:08:45 UTC (rev 2810)
@@ -674,6 +674,7 @@
reputation based cooperation.
*/
bool Inst_DonateFacingRawMaterials(cAvidaContext& ctx);
+ bool Inst_IfDonor(cAvidaContext& ctx);
};
Modified: branches/hjg-dev/source/main/cOrganism.cc
===================================================================
--- branches/hjg-dev/source/main/cOrganism.cc 2008-09-30 16:52:29 UTC (rev 2809)
+++ branches/hjg-dev/source/main/cOrganism.cc 2008-09-30 17:08:45 UTC (rev 2810)
@@ -759,12 +759,13 @@
/* Called when raw materials are received from others. Amount is the number of resources received.
The boolean flag is used to indicate if the reception was successful, which should always
-be the case... */
+be the case... Additionally, we add the donor to a set*/
-bool cOrganism::AddOtherRawMaterials (int amount) {
+bool cOrganism::AddOtherRawMaterials (int amount, int donor_id) {
bool isSuccessful = true;
InitReputation();
m_other_raw_materials += amount;
+ donor_list.insert(donor_id);
return isSuccessful;
}
@@ -775,3 +776,15 @@
// this->GetWorld()->GetPopulation().GetCell(this->GetCellID()).ConnectionList().Front().ConnectionList().Rotate(org);
}
+
+
+/* Check if the id of this neighbor indicates that it has previously donated
+to the organism.*/
+bool cOrganism::IsDonor(int neighbor_id)
+{
+ bool success = false;
+ if (donor_list.find(neighbor_id) != donor_list.end())
+ success = true;
+ return success;
+
+}
Modified: branches/hjg-dev/source/main/cOrganism.h
===================================================================
--- branches/hjg-dev/source/main/cOrganism.h 2008-09-30 16:52:29 UTC (rev 2809)
+++ branches/hjg-dev/source/main/cOrganism.h 2008-09-30 17:08:45 UTC (rev 2810)
@@ -29,6 +29,7 @@
#include <iostream>
#include <string>
#include <vector>
+#include <set>
#ifndef cCPUMemory_h
#include "cCPUMemory.h"
@@ -446,7 +447,7 @@
// donate raw materials to others
bool SubtractSelfRawMaterials(int amount);
// receive raw materials from others
- bool AddOtherRawMaterials(int amount);
+ bool AddOtherRawMaterials(int amount, int donor_id);
// retrieve the organism's own amount of raw materials
int GetSelfRawMaterials() {InitReputation(); return m_self_raw_materials; }
// retrieve the amount of raw materials collected from others
@@ -454,6 +455,8 @@
// Rotate the organism to face a specific neighboring organism.
// This functionality is used to turn the donation recipient to the donor.
void RotateToFaceOrganism(cOrganism& org);
+ // Is donor?
+ bool IsDonor(int neighbor_id);
protected:
// Initialize reputation support
@@ -462,6 +465,8 @@
int m_self_raw_materials;
// The raw materials an oranism has collected from others
int m_other_raw_materials;
+ // a list of organism id's that have previously donated to this organism
+ set<int> donor_list;
// -------- End of reputation support --------
More information about the Avida-cvs
mailing list