Skip to content

Commit 8e419a8

Browse files
committed
refactor to use functors for point awards
1 parent 7712982 commit 8e419a8

4 files changed

Lines changed: 52 additions & 5 deletions

File tree

source/sgp_mode/SGPConfigSetup.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
namespace sgpmode {
1212

13-
// TODO - rename TASK_TYPE to be more specific
14-
13+
// TODO rename SymConfigSGP to avoid confusion and add clarity with sym/host nameing conventtions
1514
EMP_EXTEND_CONFIG(SymConfigSGP, SymConfigBase,
1615
GROUP(SGP, "Complex Genomes Settings"),
1716
VALUE(CYCLES_PER_UPDATE, size_t, 4, "Number of CPU cycles that organisms run every update"),
@@ -22,7 +21,6 @@ EMP_EXTEND_CONFIG(SymConfigSGP, SymConfigBase,
2221
VALUE(HOST_MIN_CYCLES_BEFORE_REPRO, size_t, 0, "Number of CPU cycles organisms must wait between reproductions"),
2322
VALUE(SYM_MIN_CYCLES_BEFORE_REPRO, size_t, 0, "Number of CPU cycles organisms must wait between reproductions"),
2423

25-
// NOTE - Might be able to eliminate ORGANISM_TYPE if interaction modes are allowed to be "layered on"
2624
VALUE(INTERACTION_MECHANISM, std::string, "default", "What sgp organisms should population the world? (Options: 'default')"),
2725
VALUE(VT_TASK_MATCH, bool, false, "Should task matching be required for vertical transmission? (0 for no, 1 for yes)"),
2826
VALUE(TASK_PROFILE_MODE, std::string, "self-all", "What should we use for task profiles for host-symbiont compatibility, preferential ousting, etc.? Options are parent-all, self-all, self-first, parent-first. 'all' means all tasks, 'first' means only first task performed."),
@@ -42,7 +40,6 @@ EMP_EXTEND_CONFIG(SymConfigSGP, SymConfigBase,
4240
VALUE(PARASITE_NUM_OFFSPRING_ON_STRESS_INTERACTION, size_t, 1, "Number of offspring stress parasite can produce when host dies during stress event"),
4341
VALUE(PARASITE_ESCAPEE_TIMING, std::string, "on-match-host-death", "When should parasites have the opportunity to produce escapees during a stress event? Options: on-match-host-death, on-match"),
4442

45-
// NOTE - HEALTH_X is less descriptive than STRESS_X; shift language to HEALTH_INTERACTION_X?
4643
GROUP(HEALTH, "Health interaction settings"),
4744
VALUE(ENABLE_HEALTH, bool, false, "Health interactions enabled?"),
4845
VALUE(HEALTH_TYPE, std::string, "mutualist", "What kind of health symbionts are used?"),

source/sgp_mode/SGPSymbiont.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ void ProcessOutputBuffer() {
383383
);
384384
double task_points = new_points - GetPoints();
385385

386+
/*
386387
//Parasitic Nutrient symbionts receieve less rewards from completing tasks to incentivize matching tasks with hosts
387388
if(my_world->GetConfig().ENABLE_NUTRIENT() && my_world->GetNutrientSymType() == nutrient_sym_mode_t::PARASITE){
388389
task_points *= my_world->GetConfig().PARASITE_BASE_TASK_VALUE_PROP();
@@ -393,7 +394,9 @@ void ProcessOutputBuffer() {
393394
// // Enforce limits on points
394395
395396
//^^^ 386 through here are doing the work in 455 in SGPHost - could be refactored
396-
397+
*/
398+
//World handles point movement between hosts and symbionts
399+
my_world->ApplySymPoints(*this, task_points, task_id);
397400
my_world->GetSymTaskSuccesses()[task_id] += 1;
398401
}
399402
}

source/sgp_mode/SGPW_InteractionMechanismSetup.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ namespace sgpmode {
2929
SetupNutrientInteractions();
3030
} // default is no nutrient interactions, which is set in SGPWorld constructor
3131

32+
3233
SetupHostTaskRewards();
34+
SetupSymTaskRewards();
3335

3436
}
3537

@@ -742,6 +744,35 @@ namespace sgpmode {
742744
}
743745
}
744746

747+
/*
748+
* Input: None
749+
* Outpt: None
750+
* Purpose: Sets up functor to decide what happens when a sym tries to receive point reward for completing a task
751+
*/
752+
void SGPWorld::SetupSymTaskRewards() {
753+
if (sgp_config.ENABLE_NUTRIENT() == false) {
754+
fun_apply_sym_points = [this](
755+
sgp_sym_t& sym,
756+
double task_value_before,
757+
size_t task_id
758+
) {
759+
sym.AddPoints(task_value_before);
760+
};
761+
} else {
762+
fun_apply_sym_points = [this](
763+
sgp_sym_t& sym,
764+
double task_value_before,
765+
size_t task_id
766+
) {
767+
double task_value = task_value_before;
768+
if(GetNutrientSymType() == nutrient_sym_mode_t::PARASITE){
769+
task_value *= sgp_config.PARASITE_BASE_TASK_VALUE_PROP();
770+
}
771+
sym.AddPoints(task_value);
772+
};
773+
}
774+
775+
}
745776

746777

747778

source/sgp_mode/SGPWorld.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ class SGPWorld : public SymWorld {
102102
size_t /* task id */
103103
)>;
104104

105+
using func_apply_sym_points_t = std::function<void(
106+
sgp_sym_t&,
107+
double, /* task value before nutrient interaction */
108+
size_t /* task id */
109+
)>;
110+
105111
// using fun_process_endosym_t = std::function<void(
106112
// sgp_sym_t&, /* endosymbiont */
107113
// const emp::WorldPosition&, /* sym pos */
@@ -428,6 +434,7 @@ class SGPWorld : public SymWorld {
428434
fun_calc_host_nutrient_interaction_t fun_calc_host_nutrient_interaction;
429435
fun_calc_sym_nutrient_interaction_t fun_calc_sym_nutrient_interaction;
430436
func_apply_host_points_t fun_apply_host_points;
437+
func_apply_sym_points_t fun_apply_sym_points;
431438

432439
// NOTE - Don't love this being owned by the world.
433440
// Not sure of better alterative. Need to know this in InitializeState
@@ -543,6 +550,7 @@ class SGPWorld : public SymWorld {
543550
void SetupSymReproduction();
544551
void SetupHostReproduction();
545552
void SetupHostTaskRewards();
553+
void SetupSymTaskRewards();
546554
void SetupTaskProfileMode();
547555
void SetupTaskProfileCompatibilityMode();
548556
void SetupHorizontalTransmissionCompatibilityMode();
@@ -708,6 +716,14 @@ class SGPWorld : public SymWorld {
708716
fun_apply_host_points(host,task_value_before, task_id);
709717
}
710718

719+
void ApplySymPoints(
720+
sgp_sym_t& sym,
721+
double task_value_before,
722+
size_t task_id
723+
) {
724+
fun_apply_sym_points(sym,task_value_before, task_id);
725+
}
726+
711727
const emp::BitVector& GetSymTaskProfile(
712728
sgp_sym_t& sym
713729
) {

0 commit comments

Comments
 (0)