From e9091d9ca3943517693aedab86c55294e9fa17c2 Mon Sep 17 00:00:00 2001 From: Matthew Andres Moreno Date: Wed, 22 Nov 2023 18:30:51 +0000 Subject: [PATCH] Allow specification of REQUIRE_SINGLE_REACTION > 1 --- avida-core/source/main/cAvidaConfig.h | 2 +- avida-core/source/main/cOrganism.cc | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/avida-core/source/main/cAvidaConfig.h b/avida-core/source/main/cAvidaConfig.h index 0e102b6dd..c006a1360 100644 --- a/avida-core/source/main/cAvidaConfig.h +++ b/avida-core/source/main/cAvidaConfig.h @@ -399,7 +399,7 @@ class cAvidaConfig { CONFIG_ADD_VAR(IMMUNITY_TASK, int, -1, "Task providing immunity from the required task"); CONFIG_ADD_VAR(REQUIRED_REACTION, int, -1, "Reaction ID required for successful divide"); CONFIG_ADD_VAR(IMMUNITY_REACTION, int, -1, "Reaction ID that provides immunity for successful divide"); - CONFIG_ADD_VAR(REQUIRE_SINGLE_REACTION, int, 0, "If set to 1, at least one reaction is required for a successful divide"); + CONFIG_ADD_VAR(REQUIRE_SINGLE_REACTION, int, 0, "If set to 1, at least one reaction is required for a successful divide; if set to n > 1, at least n reactions are required for a successful divide"); CONFIG_ADD_VAR(MAX_UNIQUE_TASK_COUNT, int, -1, "Division will fail if organism performs more than MAX_TASK_COUNT when MAX_TASK_COUNT >= 0"); CONFIG_ADD_VAR(REQUIRED_BONUS, double, 0.0, "Required bonus to divide"); CONFIG_ADD_VAR(REQUIRE_EXACT_COPY, int, 0, "Require offspring to be an exact copy (checked before divide mutations)"); diff --git a/avida-core/source/main/cOrganism.cc b/avida-core/source/main/cOrganism.cc index b8a98e030..943176891 100644 --- a/avida-core/source/main/cOrganism.cc +++ b/avida-core/source/main/cOrganism.cc @@ -860,22 +860,22 @@ bool cOrganism::Divide_CheckViable(cAvidaContext& ctx) } if (single_reaction != 0) { - bool toFail = true; + int toFail = single_reaction; Apto::Array reactionCounts = m_phenotype.GetCurReactionCount(); - for (int i=0; i 0) toFail = false; + for (int i=0; i 0) --toFail; } if (toFail) { const Apto::Array& stolenReactions = m_phenotype.GetStolenReactionCount(); - for (int i = 0; i < stolenReactions.GetSize(); i++) + for (int i = 0; i < stolenReactions.GetSize() && toFail; i++) { - if (stolenReactions[i] > 0) toFail = false; + if (stolenReactions[i] > 0) --toFail; } } if (toFail) { - Fault(FAULT_LOC_DIVIDE, FAULT_TYPE_ERROR, cStringUtil::Stringf("Lacks any reaction required for divide")); + Fault(FAULT_LOC_DIVIDE, FAULT_TYPE_ERROR, cStringUtil::Stringf("Lacks sufficient reactions required for divide")); return false; // (divide fails) } }