Skip to content

Commit

Permalink
Add Fortress Climb
Browse files Browse the repository at this point in the history
  • Loading branch information
APN-Pucky committed Sep 12, 2018
1 parent 02eabdf commit 93767a7
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 28 deletions.
Binary file modified SimpleTUOptimizeStarter-x86.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions SimpleTUOptimizeStarter.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ if (IniEffectNum = 0) {

Gui, Add, ComboBox, vEffect xs Choose%IniEffectNum% section, %BGEffects%
Gui, Add, DDL, altsubmit vMode Choose%IniMode%, Battle / Mission|Battle (defense)|GW|GW (defense)|Brawl|Brawl (defense)|Raid|Campaign|CQ / Surge
Gui, Add, DDL, altsubmit vOperation Group Choose%IniOperation% xs, Climb|Sim|Reorder|Climbex|Anneal|Debug
Gui, Add, DDL, altsubmit vOperation Group Choose%IniOperation% xs, Climb|Sim|Reorder|Climbex|Anneal|Debug|Climb_Forts
Gui, Add, DDL, altsubmit vDominion Group Choose%IniDominion% xs, dom-owned|dom-maxed|dom-none
Gui, Add, DDL, altsubmit vStrategy Group Choose%IniStrategy%, none|recent|jam|mortar|siege|strike|sunder|weaken|enhance|evolve|heal|mend|overload|protect|rally|fortify|enrage|entrap|rush|mimic|armor|avenge|scavenge|corrosive|counter|evade|subdue|absorb|flying|payback|revenge|tribute|refresh|wall|barrier|coalition|legion|pierce|rupture|swipe|drain|venom|hunt|berserk|inhibit|sabotage|leech|poison|allegiance|flurry|valor|stasis|summon|bravery|enfeeble

Expand Down Expand Up @@ -140,7 +140,7 @@ Gui, Submit, NoHide ; save the changes and not hide the windows)
selTUO := (x86 ? (debug ? "tuo-x86-debug" : "tuo-x86") : (debug ? "tuo-debug" : "tuo"))
selMode := (Mode == 1 ? "pvp" : Mode == 2 ? "pvp-defense" : Mode == 3 ? "gw" : Mode == 4 ? "gw-defense" :Mode == 5 ? "brawl" : Mode == 6 ? "brawl-defense" : Mode == 7 ? "raid" : Mode == 8 ? "campaign" : "surge")
selOrder := (Order == 1 ? "random" : Order == 2 ? "ordered" : "flexible")
selOperation := (Operation == 1 ? "climb" : Operation == 2 ? "sim" : Operation == 3 ? "reorder": Operation == 4 ? "climbex" : Operation == 5 ? "anneal" : "debug sim" )
selOperation := (Operation == 1 ? "climb" : Operation == 2 ? "sim" : Operation == 3 ? "reorder": Operation == 4 ? "climbex" : Operation == 5 ? "anneal" : Operation==6 ? "debug sim" : "climb_forts")
selMySiege := (MySiege == "" ? "" : "yf """ MySiege """ ")
selEnemySiege := ( EnemySiege == "" ? "" : "ef """ EnemySiege """ ")
selVIP := ( VIP == "" ? "" : "vip """ VIP """ " )
Expand Down
Binary file modified SimpleTUOptimizeStarter.exe
Binary file not shown.
5 changes: 4 additions & 1 deletion deck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ void Deck::add_pool_forts(const std::string& deck_string, unsigned amount)
auto && id_marks = string_to_ids(all_cards, deck_string, "fortress_cards");
unsigned replicates{1};
std::vector<const Card*> cards;
if(id_marks.first.size() < amount) {
std::cerr << "WARNING: fortress pool bigger than fortress cards";
}
for (auto id: id_marks.first)
{
cards.push_back(all_cards.by_id(id));
Expand Down Expand Up @@ -587,7 +590,7 @@ const Card* Deck::next(Field* f)
_DEBUG_MSG(1,">>>>FLEX SIMS>>>>\n");
std::vector<uint64_t> res(std::min<unsigned>(3u,shuffled_cards.size()));
unsigned iter = f->flexible_iter;

bool all_same{true};
for(unsigned j =1; j < res.size();j++)
{
Expand Down
135 changes: 110 additions & 25 deletions tyrant_optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ void print_results(const EvaluatedResults& results, std::vector<long double>& fa
break;
}
}

//------------------------------------------------------------------------------
void print_upgraded_cards(Deck* deck)
{
if(!print_upgraded)return;
Expand Down Expand Up @@ -1091,6 +1091,34 @@ void print_upgraded_cards(Deck* deck)
std::cout << std::endl;
}
//------------------------------------------------------------------------------
void print_cards_inline(std::vector<const Card*> cards)
{
std::string last_name;
unsigned num_repeat(0);
for (const Card* card: cards)
{
if (card->m_name == last_name)
{
++ num_repeat;
}
else
{
if (num_repeat > 1)
{
std::cout << " #" << num_repeat;
}
std::cout << ", " << card->m_name;
last_name = card->m_name;
num_repeat = 1;
}
}
if (num_repeat > 1)
{
std::cout << " #" << num_repeat;
}
std::cout << std::endl;
}
//------------------------------------------------------------------------------
void print_deck_inline(const unsigned deck_cost, const FinalResults<long double> score, Deck * deck)
{
// print units count
Expand Down Expand Up @@ -1169,30 +1197,7 @@ void print_deck_inline(const unsigned deck_cost, const FinalResults<long double>
{
std::sort(deck->cards.begin(), deck->cards.end(), [](const Card* a, const Card* b) { return a->m_id < b->m_id; });
}
std::string last_name;
unsigned num_repeat(0);
for (const Card* card: deck->cards)
{
if (card->m_name == last_name)
{
++ num_repeat;
}
else
{
if (num_repeat > 1)
{
std::cout << " #" << num_repeat;
}
std::cout << ", " << card->m_name;
last_name = card->m_name;
num_repeat = 1;
}
}
if (num_repeat > 1)
{
std::cout << " #" << num_repeat;
}
std::cout << std::endl;
print_cards_inline(deck->cards);
}
//------------------------------------------------------------------------------
inline bool is_timeout_reached()
Expand Down Expand Up @@ -1765,13 +1770,84 @@ void simulated_annealing(unsigned num_min_iterations, unsigned num_iterations, D
print_deck_inline(get_deck_cost(best_deck), best_score, best_deck);
print_upgraded_cards(best_deck);
}
unsigned factorial(unsigned n)
{
unsigned retval = 1;
for (int i = n; i > 1; --i)
retval *= i;
return retval;
}

void recursion(unsigned num_iterations, std::vector<unsigned> used, unsigned pool, std::vector<const Card*> forts,Process&proc, FinalResults<long double>& best_score,std::vector<const Card*> & best_forts,std::unordered_map<std::string,EvaluatedResults> & evaluated_decks, EvaluatedResults& zero_results, unsigned long& skipped_simulations)
{
if(used.size()==pool)
{
for(auto your_deck : proc.your_decks)
{
your_deck->fortress_cards.clear();
for(unsigned i = 0; i < pool;++i)
{
your_deck->fortress_cards.emplace_back(forts[used[i]]);
}
}
//sim
std::stringstream ios;
encode_deck_ext_b64(ios,proc.your_decks[0]->fortress_cards);
auto hash = ios.str();
auto && emplace_rv = evaluated_decks.insert({hash,zero_results});
auto & prev_results = emplace_rv.first->second;
if(!emplace_rv.second)
{
skipped_simulations += prev_results.second;
}
auto compare_results= proc.evaluate(num_iterations, prev_results);
auto current_score = compute_score(compare_results, proc.factors);

if(current_score.points > best_score.points+min_increment_of_score) {
best_score = current_score;
std::vector<const Card*> copy_forts(proc.your_decks[0]->fortress_cards);
best_forts = copy_forts;
std::cout << "Forts improved: " << hash << " : ";
print_cards_inline(best_forts);
print_score_info(compare_results, proc.factors);
}
used.clear();
used.shrink_to_fit();
}
for(unsigned i =0;i < forts.size();++i)
{
if(std::find(used.begin(),used.end(),i)==used.end()) //not contained
{
std::vector<unsigned> tmp_used (used);
tmp_used.emplace_back(i);
recursion(num_iterations,tmp_used,pool,forts,proc,best_score,best_forts,evaluated_decks,zero_results,skipped_simulations);
}
}
}

void forts_climbing(unsigned num_iterations, Process& proc) {
EvaluatedResults zero_results = { EvaluatedResults::first_type(proc.enemy_decks.size()*proc.your_decks.size()), 0 };
unsigned pool = std::get<0>(proc.your_decks[0]->variable_forts[0]);
std::vector<const Card*> forts(std::get<1>(proc.your_decks[0]->variable_forts[0]));
for(unsigned i =0; i < proc.your_decks.size();++i)
{
proc.your_decks[i]->variable_forts.clear();
}
std::vector<unsigned> used{pool};
std::vector<const Card*> best_forts{pool};
FinalResults<long double> best_score;
unsigned long skipped_simulations{0};
std::unordered_map<std::string,EvaluatedResults> evaluated_decks{{"",zero_results}};
recursion(num_iterations,used,pool,forts, proc,best_score,best_forts,evaluated_decks,zero_results,skipped_simulations);
}


//------------------------------------------------------------------------------
enum Operation {
noop,
simulate,
climb,
climb_forts,
anneal,
reorder,
debug,
Expand Down Expand Up @@ -2433,6 +2509,12 @@ int main(int argc, char** argv)
opt_do_optimization = true;
argIndex += 1;
}
else if (strcmp(argv[argIndex], "climb_forts") == 0)
{
opt_todo.push_back(std::make_tuple((unsigned)atoi(argv[argIndex + 1]), (unsigned)atoi(argv[argIndex + 1]), climb_forts));
if (std::get<1>(opt_todo.back()) < 10) { opt_num_threads = 1; }
argIndex += 1;
}
else if ( strcmp(argv[argIndex], "anneal") == 0)
{
opt_todo.push_back(std::make_tuple((unsigned)atoi(argv[argIndex + 1]), (unsigned)atoi(argv[argIndex + 1]), anneal));
Expand Down Expand Up @@ -3119,6 +3201,9 @@ int main(int argc, char** argv)
print_results(results, p.factors);
break;
}
case climb_forts: {
forts_climbing(std::get<0>(op),p);
}
case climb: {
//TODO check for your_decks.size()==1
hill_climbing(std::get<0>(op), std::get<1>(op), your_deck, p, requirement
Expand Down

0 comments on commit 93767a7

Please sign in to comment.