[Avida-SVN] r3052 - in branches/hjg-dev/source: cpu main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Tue Dec 16 12:07:39 PST 2008
Author: hjg
Date: 2008-12-16 15:07:39 -0500 (Tue, 16 Dec 2008)
New Revision: 3052
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
branches/hjg-dev/source/main/cTaskLib.cc
Log:
Made StrCat and MatchString mutually exclusive
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-12-16 15:44:02 UTC (rev 3051)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-12-16 20:07:39 UTC (rev 3052)
@@ -480,7 +480,7 @@
tInstLibEntry<tMethod>("rotate-to-rep-tag", &cHardwareCPU::Inst_RotateToGreatestReputationWithDifferentTag, nInstFlag::STALL),
tInstLibEntry<tMethod>("rotate-to-tag", &cHardwareCPU::Inst_RotateToDifferentTag, nInstFlag::STALL),
tInstLibEntry<tMethod>("if-donor", &cHardwareCPU::Inst_IfDonor, nInstFlag::STALL),
-
+ tInstLibEntry<tMethod>("str-cat", &cHardwareCPU::Inst_StrCatOrg, nInstFlag::STALL),
// Must always be the last instruction in the array
@@ -7400,7 +7400,7 @@
int cur = 0;
int best = 0;
vector<cString> strings_to_match = m_world->GetEnvironment().GetMatchStringsFromTask();
- for (int i=0; i < strings_to_match.size(); i++) {
+ for (unsigned int i=0; i < strings_to_match.size(); i++) {
cur = organism->MatchStringsHelper(org_str, strings_to_match[i]);
if (cur > max) {
max = cur;
@@ -7417,9 +7417,10 @@
return true;
}
- // update the reputation
- organism->SetAverageReputation(max);
-
+ // update the reputation unless the organism is a str catter
+ if (!organism->GetStringCatter()){
+ organism->SetAverageReputation(max);
+ }
// Donate the string
neighbor->ReceiveString(org_str, organism->GetID());
@@ -7444,3 +7445,11 @@
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. */
+bool cHardwareCPU::Inst_StrCatOrg(cAvidaContext& ctx)
+{
+ organism->SetStringCatter(true);
+ return true;
+}
\ No newline at end of file
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.h 2008-12-16 15:44:02 UTC (rev 3051)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.h 2008-12-16 20:07:39 UTC (rev 3052)
@@ -715,7 +715,9 @@
bool Inst_GetReputation(cAvidaContext& ctx);
// Execute the following instruction if the facing neighbor was a donor
bool Inst_IfDonor(cAvidaContext& ctx);
-
+ // Indicate that the organism is a string catter
+ bool Inst_StrCatOrg(cAvidaContext& ctx);
+
// Get the organism's raw material level
bool Inst_GetAmountOfRawMaterials(cAvidaContext& ctx);
// Get the number of raw materials the organism
Modified: branches/hjg-dev/source/main/cOrganism.cc
===================================================================
--- branches/hjg-dev/source/main/cOrganism.cc 2008-12-16 15:44:02 UTC (rev 3051)
+++ branches/hjg-dev/source/main/cOrganism.cc 2008-12-16 20:07:39 UTC (rev 3052)
@@ -85,6 +85,7 @@
, m_k(0)
, m_failed_reputation_increases(0)
, m_tag(make_pair(-1, 0))
+ , m_strcatter(0)
{
m_hardware = m_world->GetHardwareManager().Create(this);
Modified: branches/hjg-dev/source/main/cOrganism.h
===================================================================
--- branches/hjg-dev/source/main/cOrganism.h 2008-12-16 15:44:02 UTC (rev 3051)
+++ branches/hjg-dev/source/main/cOrganism.h 2008-12-16 20:07:39 UTC (rev 3052)
@@ -513,6 +513,8 @@
// Get tag
int GetTagLabel() { return m_tag.first; }
pair < int, int > GetTag() { return m_tag; }
+ void SetStringCatter(bool val) { m_strcatter = val; }
+ bool GetStringCatter() { return m_strcatter; }
protected:
@@ -537,6 +539,7 @@
// int number of reputation increase failures
int m_failed_reputation_increases;
std::pair < int, int > m_tag;
+ bool m_strcatter;
// -------- End of reputation support --------
Modified: branches/hjg-dev/source/main/cTaskLib.cc
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.cc 2008-12-16 15:44:02 UTC (rev 3051)
+++ branches/hjg-dev/source/main/cTaskLib.cc 2008-12-16 20:07:39 UTC (rev 3052)
@@ -1921,6 +1921,7 @@
schema.AddEntry("pow",0,2.0);
cArgContainer* args = cArgContainer::Load(argstr, schema, errors);
envreqs.SetMinOutputs(args->GetString(0).GetSize());
+ m_strings.push_back(args->GetString(0));
if (args) NewTask(name, "MatchStr", &cTaskLib::Task_MatchStr, 0, args);
}
@@ -1939,17 +1940,7 @@
vector<cString> cTaskLib::GetMatchStrings()
{
- if (m_strings.size() == 0) {
- for (int i = 0; i < task_array.GetSize(); i++) {
- assert(task_array[i] != NULL);
- if (task_array[i]->GetDesc() == "MatchStr") {
- cString string_to_match(task_array[i]->GetArguments().GetString(0));
- m_strings.push_back(string_to_match);
- }
- }
- }
-
return m_strings;
}
@@ -1958,6 +1949,9 @@
string in its buffer with each of the strings it has received as a donation. */
double cTaskLib::Task_StrCat(cTaskContext& ctx) const
{
+
+ if (ctx.GetOrganism()->GetStringCatter()==0) return 0;
+
tBuffer<int> temp_buf(ctx.GetOutputBuffer());
const cString& string_to_match = ctx.GetTaskEntry()->GetArguments().GetString(0);
@@ -1974,13 +1968,19 @@
// Given the desired string, pass it to the organism which will
// check all possibilities. ?
+
+ for (unsigned int i=0; i<m_strings.size(); i++) {
+ max_num_matched += ctx.GetOrganism()->MatchString(m_strings[i]).first;
+ }
- max_num_matched = ctx.GetOrganism()->CheckStrCat(string_to_match);
+ // Update tag
+ ctx.GetOrganism()->UpdateTag(0, (int)(max_num_matched/m_strings.size()));
+ // Update reputation
+ ctx.GetOrganism()->SetAverageReputation( (int)(max_num_matched/m_strings.size()));
+
cString name;
- name = "[catted";
- name += string_to_match;
- name += "]";
+ name = "[catted]";
m_world->GetStats().AddStringBitsMatchedValue(name, max_num_matched);
if (max_num_matched == string_to_match.GetSize()) m_world->GetStats().IncPerfectMatch();
@@ -2008,6 +2008,9 @@
double cTaskLib::Task_MatchStr(cTaskContext& ctx) const
{
+
+ if (ctx.GetOrganism()->GetStringCatter()) return 0;
+
tBuffer<int> temp_buf(ctx.GetOutputBuffer());
const cString& string_to_match = ctx.GetTaskEntry()->GetArguments().GetString(0);
@@ -2049,7 +2052,8 @@
}
// Update the organism's tag.
- ctx.GetOrganism()->UpdateTag(string_to_match.AsInt(), max_num_matched);
+ // Tag 0 indicates the organism is a producer
+ ctx.GetOrganism()->UpdateTag(0, max_num_matched);
// Update stats
cString name;
name = "[produced";
More information about the Avida-cvs
mailing list