MCPcopy Create free account
hub / github.com/devosoft/avida / Task_MatchProdStr

Method Task_MatchProdStr

avida-core/source/main/cTaskLib.cc:2241–2326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2239
2240
2241double cTaskLib::Task_MatchProdStr(cTaskContext& ctx) const
2242{
2243 // These even out the stats tracking.
2244 m_world->GetStats().AddTag(ctx.GetTaskEntry()->GetArguments().GetInt(2), 0);
2245 m_world->GetStats().AddTag(-1, 0);
2246
2247 tBuffer<int> temp_buf(ctx.GetOutputBuffer());
2248
2249 const cString& string_to_match = ctx.GetTaskEntry()->GetArguments().GetString(0);
2250 int partial = ctx.GetTaskEntry()->GetArguments().GetInt(0);
2251 int binary = ctx.GetTaskEntry()->GetArguments().GetInt(1);
2252 double mypow = ctx.GetTaskEntry()->GetArguments().GetDouble(0);
2253 int string_index;
2254 int num_matched = 0;
2255 int test_output;
2256 int max_num_matched = 0;
2257 int num_real=0;
2258
2259 if (!binary) {
2260 if (temp_buf.GetNumStored() > 0) {
2261 test_output = temp_buf[0];
2262
2263 for (int j = 0; j < string_to_match.GetSize(); j++) {
2264 string_index = string_to_match.GetSize() - j - 1; // start with last char in string
2265 int k = 1 << j;
2266 if ((string_to_match[string_index] == '0' && !(test_output & k)) ||
2267 (string_to_match[string_index] == '1' && (test_output & k))) num_matched++;
2268 }
2269 max_num_matched = num_matched;
2270 }
2271 }
2272 else {
2273 for (int j = 0; j < string_to_match.GetSize(); j++) {
2274 if (string_to_match[j]!='9') num_real++;
2275 if ((string_to_match[j]=='0' && temp_buf[j]==0) ||
2276 (string_to_match[j]=='1' && temp_buf[j]==1))
2277 num_matched++;
2278 }
2279 max_num_matched = num_matched;
2280 }
2281
2282 // Check if the organism already produced this string.
2283 // If so, it receives a perfect score for this task.
2284 int tag = ctx.GetTaskEntry()->GetArguments().GetInt(2);
2285
2286 if (m_world->GetConfig().MATCH_ALREADY_PRODUCED.Get()) {
2287 int prod = ctx.GetOrganism()->GetNumberStringsProduced(tag);
2288 if (prod) max_num_matched = string_to_match.GetSize();
2289 }
2290
2291
2292 // Update the organism's tag.
2293 ctx.GetOrganism()->UpdateTag(tag, max_num_matched);
2294 if (ctx.GetOrganism()->GetTagLabel() == tag) {
2295 ctx.GetOrganism()->SetLineageLabel(ctx.GetTaskEntry()->GetArguments().GetInt(2));
2296 }
2297
2298

Callers

nothing calls this directly

Calls 15

AddTagMethod · 0.80
GetIntMethod · 0.80
GetTaskEntryMethod · 0.80
GetNumStoredMethod · 0.80
GetConfigMethod · 0.80
UpdateTagMethod · 0.80
GetTagLabelMethod · 0.80
GetReputationMethod · 0.80
GetNumberOfDonationsMethod · 0.80
SetReputationMethod · 0.80

Tested by

no test coverage detected