[Avida-SVN] r2829 - in branches/hjg-dev/source: cpu main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Fri Oct 10 06:13:50 PDT 2008
Author: hjg
Date: 2008-10-10 09:13:49 -0400 (Fri, 10 Oct 2008)
New Revision: 2829
Modified:
branches/hjg-dev/source/cpu/cHardwareCPU.cc
branches/hjg-dev/source/cpu/cHardwareCPU.h
branches/hjg-dev/source/main/cAvidaConfig.h
branches/hjg-dev/source/main/cOrganism.cc
branches/hjg-dev/source/main/cOrganism.h
branches/hjg-dev/source/main/cStats.cc
Log:
Added new sense instructions for raw materials and reputation. Modified stats to include standard deviation. Added a configuration option for the raw material amount of an organism. Fixed a bug in the donate raw material instruction.
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-10-10 01:36:21 UTC (rev 2828)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-10-10 13:13:49 UTC (rev 2829)
@@ -454,6 +454,8 @@
// Reputation instructions
tInstLibEntry<tMethod>("donate-frm", &cHardwareCPU::Inst_DonateFacingRawMaterials, 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),
// Must always be the last instruction in the array
@@ -6695,6 +6697,7 @@
}
+
/* Donate raw materials to the facing organism. */
bool cHardwareCPU::Inst_DonateFacingRawMaterials(cAvidaContext& ctx)
{
@@ -6759,5 +6762,36 @@
GetRegister(age_reg) = m_world->GetStats().GetUpdate();
}
return true;
+}
+
+/*! An organism's reputation is stored as an opinion. This instruction
+ uses Inst_GetOpinion to do the heavy lifting, but includes
+ default behavior suitable for reputations. Specifically, if an
+ organism has no reputation (i.e., it has not donated), then this
+ instruction puts zeros into the registers.
+ */
+bool cHardwareCPU::Inst_GetReputation(cAvidaContext& ctx)
+{
+
+ if (organism->HasOpinion()) {
+ Inst_GetOpinion(ctx);
+ } else {
+ const int opinion_reg = FindModifiedRegister(REG_BX);
+ const int age_reg = FindNextRegister(opinion_reg);
+
+ GetRegister(opinion_reg) = 0;
+ GetRegister(age_reg) = m_world->GetStats().GetUpdate();
+ }
+ return true;
}
+
+/* Sense the number of raw materials an organism has. Store in
+ ?REG_AX? */
+bool cHardwareCPU::Inst_GetAmountOfRawMaterials(cAvidaContext& ctx)
+{
+ const int raw_mat_reg = FindModifiedRegister(REG_AX);
+ GetRegister(raw_mat_reg) = organism->GetSelfRawMaterials();
+ return true;
+}
+
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.h 2008-10-10 01:36:21 UTC (rev 2828)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.h 2008-10-10 13:13:49 UTC (rev 2829)
@@ -680,7 +680,10 @@
bool Inst_DonateFacingRawMaterials(cAvidaContext& ctx);
// Get a neighbor's reputation
bool Inst_GetNeighborsReputation(cAvidaContext& ctx);
-
+ // Get the organism's reputation
+ bool Inst_GetReputation(cAvidaContext& ctx);
+ // Get the organism's raw material level
+ bool Inst_GetAmountOfRawMaterials(cAvidaContext& ctx);
};
Modified: branches/hjg-dev/source/main/cAvidaConfig.h
===================================================================
--- branches/hjg-dev/source/main/cAvidaConfig.h 2008-10-10 01:36:21 UTC (rev 2828)
+++ branches/hjg-dev/source/main/cAvidaConfig.h 2008-10-10 13:13:49 UTC (rev 2829)
@@ -555,6 +555,10 @@
CONFIG_ADD_CUSTOM_FORMAT(INST_SET_NEW, "Instruction Set Definition");
CONFIG_ADD_FORMAT_VAR(INST, "Instruction entry in the instruction set");
+
+ CONFIG_ADD_CUSTOM_FORMAT(REPUTATION_GROUP, "Reputation Settings");
+ CONFIG_ADD_VAR(RAW_MATERIAL_AMOUNT, int, 100, "Number of raw materials an organism starts with");
+
#endif
Modified: branches/hjg-dev/source/main/cOrganism.cc
===================================================================
--- branches/hjg-dev/source/main/cOrganism.cc 2008-10-10 01:36:21 UTC (rev 2828)
+++ branches/hjg-dev/source/main/cOrganism.cc 2008-10-10 13:13:49 UTC (rev 2829)
@@ -76,7 +76,7 @@
, m_net(NULL)
, m_msg(0)
, m_opinion(0)
- , m_self_raw_materials(100)
+ , m_self_raw_materials(world->GetConfig().RAW_MATERIAL_AMOUNT.Get())
, m_other_raw_materials(0)
{
m_hardware = m_world->GetHardwareManager().Create(this);
@@ -752,7 +752,7 @@
{
bool isSuccessful = false;
// InitReputation();
- if (amount < m_self_raw_materials) {
+ if (amount <= m_self_raw_materials) {
isSuccessful = true;
m_self_raw_materials -= amount;
}
Modified: branches/hjg-dev/source/main/cOrganism.h
===================================================================
--- branches/hjg-dev/source/main/cOrganism.h 2008-10-10 01:36:21 UTC (rev 2828)
+++ branches/hjg-dev/source/main/cOrganism.h 2008-10-10 13:13:49 UTC (rev 2829)
@@ -452,7 +452,7 @@
// retrieve the amount of raw materials collected from others
int GetOtherRawMaterials() { return m_other_raw_materials; }
// get the number of donations
- int GetReputation() { return (100 - m_self_raw_materials); }
+ int GetReputation() { return (m_world->GetConfig().RAW_MATERIAL_AMOUNT.Get() - m_self_raw_materials); }
protected:
// Initialize reputation support
Modified: branches/hjg-dev/source/main/cStats.cc
===================================================================
--- branches/hjg-dev/source/main/cStats.cc 2008-10-10 01:36:21 UTC (rev 2828)
+++ branches/hjg-dev/source/main/cStats.cc 2008-10-10 13:13:49 UTC (rev 2829)
@@ -1720,7 +1720,7 @@
void cStats::PrintReputationData(const cString& filename){
cDataFile& df = m_world->GetDataFile(filename);
- int reputations = 0;
+ cDoubleSum reputations;
int min_rep = 100;
int max_rep = 0;
int cur_rep;
@@ -1740,14 +1740,15 @@
if (cur_rep < min_rep) min_rep = cur_rep;
if (max_rep < cur_rep) max_rep = cur_rep;
- reputations += cur_rep;
+ reputations.Add(cur_rep);
pop_size++;
if (cur_rep > 0) num_alt++;
}
}
- float rep = reputations/pop_size;
- df.Write(rep, "Avg. reputation");
+// float rep = reputations/pop_size;
+ df.Write(reputations.Average(), "Avg. reputation");
+ df.Write(reputations.StdDeviation(), "Standard Deviation");
df.Write(min_rep, "Minimum reputation");
df.Write(max_rep, "Maximum reputation");
df.Write(num_alt, "Number of altruists");
More information about the Avida-cvs
mailing list