Skip to content

Commit

Permalink
Add an option to prevent downgrading core mods
Browse files Browse the repository at this point in the history
  • Loading branch information
DataBeaver committed Apr 24, 2019
1 parent ec9e6f8 commit 02354d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ options. Some of the more important are:

-k, --keep-core-mods
Prevent swapping of core mods. Only change the values of existing mods.
Specifying this option twice prevents downgrading mods from the original
values.

-i, --income
Optimize for runestone income instead of damage. This is much slower so it
Expand Down
17 changes: 15 additions & 2 deletions spire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Spire::Spire(int argc, char **argv):
budget(0),
core_budget(0),
core_mutate(Core::ALL_MUTATIONS),
no_core_downgrade(false),
income(false),
towers(false),
score_func(damage_score)
Expand All @@ -99,7 +100,7 @@ Spire::Spire(int argc, char **argv):
bool exact = false;
std::string budget_str;
std::string core_budget_str;
bool keep_core_mods = false;
unsigned keep_core_mods = 0;
std::string tower_type;
unsigned towers_seen = 0;

Expand Down Expand Up @@ -219,7 +220,10 @@ Spire::Spire(int argc, char **argv):
}

if(keep_core_mods)
{
core_mutate = Core::VALUES_ONLY;
no_core_downgrade = (keep_core_mods>=2);
}

if(!n_pools_seen && heterogeneous)
n_pools = 21;
Expand Down Expand Up @@ -1078,7 +1082,16 @@ void Spire::Worker::main()
Core core = mutated.get_core();
core.mutate(spire.core_mutate, 1+random()%5, random);
core.update();
if(core.cost<=spire.core_budget)

bool ok = (core.cost<=spire.core_budget);

if(ok && spire.no_core_downgrade)
{
for(unsigned j=0; (ok && j<Core::N_MODS); ++j)
ok = (core.get_mod(j)>=mutated.get_core().get_mod(j));
}

if(ok)
mutated.set_core(core);
}

Expand Down
1 change: 1 addition & 0 deletions spire.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Spire
Number budget;
Number core_budget;
Core::MutateMode core_mutate;
bool no_core_downgrade;
bool income;
bool towers;
Pool::ScoreFunc *score_func;
Expand Down

0 comments on commit 02354d4

Please sign in to comment.