[Avida-SVN] r3051 - branches/hjg-dev/source/main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Tue Dec 16 07:44:03 PST 2008
Author: hjg
Date: 2008-12-16 10:44:02 -0500 (Tue, 16 Dec 2008)
New Revision: 3051
Modified:
branches/hjg-dev/source/main/cAvidaConfig.h
branches/hjg-dev/source/main/cTaskLib.cc
branches/hjg-dev/source/main/cTaskLib.h
Log:
added a toggle that enables MatchString to be used either only on strings produced by the organism or on both produced and donated strings.
Modified: branches/hjg-dev/source/main/cAvidaConfig.h
===================================================================
--- branches/hjg-dev/source/main/cAvidaConfig.h 2008-12-15 22:44:20 UTC (rev 3050)
+++ branches/hjg-dev/source/main/cAvidaConfig.h 2008-12-16 15:44:02 UTC (rev 3051)
@@ -571,6 +571,7 @@
CONFIG_ADD_VAR(DONATION_RESTRICTIONS, int, 0, "0=none\n1=inter-species only\n2=different tag only");
CONFIG_ADD_VAR(INHERIT_REPUTATION, int, 0, "0=reputation are not inherited\n1=reputations are inherited\n2=tags are inherited");
CONFIG_ADD_VAR(MATCH_PERCENT, int, 0, "0=percentage above chance\n1=percentage");
+ CONFIG_ADD_VAR(STRING_MATCH, int, 0, "0=only production\n1=production and donation");
#endif
Modified: branches/hjg-dev/source/main/cTaskLib.cc
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.cc 2008-12-15 22:44:20 UTC (rev 3050)
+++ branches/hjg-dev/source/main/cTaskLib.cc 2008-12-16 15:44:02 UTC (rev 3051)
@@ -359,7 +359,6 @@
if (name == "strcat")
Load_StrCat(name, info, envreqs, errors);
-
if (name == "sort_inputs")
Load_SortInputs(name, info, envreqs, errors);
@@ -2044,41 +2043,11 @@
if (string_to_match[j]=='0' && temp_buf[j]==0 ||
string_to_match[j]=='1' && temp_buf[j]==1)
num_matched++;
- if (temp_buf[j]==0) {
- int q = 0;
- }
- if (temp_buf[j]==1) {
- int p = 1;
- }
-
}
max_num_matched = num_matched;
}
-
- bool used_received = false;
- if (ctx.GetReceivedMessages()) {
- tBuffer<int> received(*(ctx.GetReceivedMessages()));
- for (int i = 0; i < received.GetNumStored(); i++) {
- test_output = received[i];
- num_matched = 0;
-
- for (int j = 0; j < string_to_match.GetSize(); j++) {
- string_index = string_to_match.GetSize() - j - 1; // start with last char in string
- int k = 1 << j;
- if ((string_to_match[string_index]=='0' && !(test_output & k)) ||
- (string_to_match[string_index]=='1' && (test_output & k))) num_matched++;
- }
-
- if (num_matched > max_num_matched) {
- max_num_matched = num_matched;
- used_received = true;
- }
- }
-
- }
-
// Update the organism's tag.
ctx.GetOrganism()->UpdateTag(string_to_match.AsInt(), max_num_matched);
// Update stats
@@ -2094,10 +2063,32 @@
ctx.GetOrganism()->SetReputation(0);
}
+ std::pair < int, int > best_string;
+ int donated_string;
+
+ // Check if the organism received this string
+ if (m_world->GetConfig().STRING_MATCH.Get()==1) {
+ best_string = ctx.GetOrganism()->MatchString(string_to_match);
+ num_matched = best_string.first;
+ donated_string = num_matched;
+ if (num_matched > max_num_matched) {
+ max_num_matched = num_matched;
+ // max_org_id = best_string.second;
+ }
+ }
+
double bonus = 0.0;
- // return value between 0 & 1 representing the percentage of string that was matched
+ double base_bonus = 0.0;
+
+ if (m_world->GetConfig().MATCH_PERCENT.Get() == 0) {
+ // percent over 50% (Sherri)
+ base_bonus = static_cast<double>(max_num_matched) * 2.0 / static_cast<double>(string_to_match.GetSize()) - 1;
+ } else if (m_world->GetConfig().MATCH_PERCENT.Get() == 1) {
+ // percent (hjg)
+ base_bonus = static_cast<double>(max_num_matched) / static_cast<double>(string_to_match.GetSize());
+ }
- double base_bonus = static_cast<double>(max_num_matched) * 2.0 / static_cast<double>(string_to_match.GetSize()) - 1;
+
if (partial)
{
base_bonus=double(max_num_matched)*2/double(num_real) -1;
@@ -2105,10 +2096,6 @@
if (base_bonus > 0.0) {
bonus = pow(base_bonus,mypow);
- if (used_received)
- m_world->GetStats().AddMarketItemUsed();
- else
- m_world->GetStats().AddMarketOwnItemUsed();
}
return bonus;
Modified: branches/hjg-dev/source/main/cTaskLib.h
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.h 2008-12-15 22:44:20 UTC (rev 3050)
+++ branches/hjg-dev/source/main/cTaskLib.h 2008-12-16 15:44:02 UTC (rev 3051)
@@ -253,6 +253,7 @@
void Load_StrCat(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors);
double Task_StrCat(cTaskContext& ctx) const;
+
void Load_SortInputs(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors);
double Task_SortInputs(cTaskContext& ctx) const;
void Load_FibonacciSequence(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors);
More information about the Avida-cvs
mailing list