Skip to content

Commit

Permalink
Add option +uc
Browse files Browse the repository at this point in the history
  • Loading branch information
APN-Pucky committed Jun 6, 2018
1 parent df1b794 commit 1f721f5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion deck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ const Card* Deck::next(Field* f)
}

_DEBUG_MSG(1,"<<<<FLEX SIMS<<<<\n");
_DEBUG_MSG(1, "Flexible Order: (%s %llu, %s %llu, %s %llu)\n",shuffled_cards[0]->m_name.c_str(), res[0]/iter,res.size()>1?shuffled_cards[1]->m_name.c_str():"", res.size()>1?res[1]/iter:0,res.size()>2?shuffled_cards[2]->m_name.c_str():"", res.size()>2?res[2]/iter:0);
_DEBUG_MSG(1, "Flexible Order: (%s %llu, %s %llu, %s %llu)\n",shuffled_cards[0]->m_name.c_str(),static_cast<unsigned long long>(res[0]/iter),res.size()>1?shuffled_cards[1]->m_name.c_str():"", static_cast<unsigned long long>(res.size()>1?res[1]/iter:0),res.size()>2?shuffled_cards[2]->m_name.c_str():"", static_cast<unsigned long long>(res.size()>2?res[2]/iter:0));
unsigned best_j = std::distance(res.begin(), (f->tapi==0)?std::max_element(res.begin(), res.end()):std::min_element(res.begin(), res.end())); //max for own flex. enemy flex should optimize him, so min result is best for him
std::swap(shuffled_cards.begin()[0],shuffled_cards.begin()[best_j]);
const Card* card = shuffled_cards.front();
Expand Down
54 changes: 42 additions & 12 deletions tyrant_optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ namespace {
bool use_maxed_dominions{false};
unsigned use_fused_card_level{0};
unsigned use_fused_commander_level{0};
bool print_upgraded{false};
bool show_ci{false};
bool use_harmonic_mean{false};
unsigned iterations_multiplier{10};
Expand Down Expand Up @@ -938,7 +939,7 @@ void print_score_info(const EvaluatedResults& results, std::vector<long double>&
case OptimizationMode::brawl:
case OptimizationMode::brawl_defense:
case OptimizationMode::war:
case OptimizationMode::war_defense:
case OptimizationMode::war_defense:
#ifndef NQUEST
case OptimizationMode::quest:
#endif
Expand Down Expand Up @@ -1034,6 +1035,30 @@ void print_results(const EvaluatedResults& results, std::vector<long double>& fa
break;
}
}
void print_upgraded_cards(Deck* deck)
{
if(!print_upgraded)return;
auto owned_cards_c = owned_cards;
std::cout << "Upgraded Cards: ";
for (const Card * card : deck->cards)
{

if ((card->m_set == 1000) && (card->m_rarity <= 2) && (card->is_low_level_card()))
{ continue; }

if ((card->m_id == 50002) || (card->m_category == CardCategory::dominion_material))
{ continue; }

if ((fund || (card->m_category != CardCategory::normal))
&& (owned_cards_c[card->m_id] == 0))
{
//print card
std::cout << card->m_name << ", ";
}
if(owned_cards_c[card->m_id] >0)owned_cards_c[card->m_id]--;
}
std::cout << std::endl;
}
//------------------------------------------------------------------------------
void print_deck_inline(const unsigned deck_cost, const FinalResults<long double> score, Deck * deck)
{
Expand Down Expand Up @@ -1449,6 +1474,7 @@ void hill_climbing(unsigned num_min_iterations, unsigned num_iterations, Deck* d
std::cout << "Evaluated " << evaluated_decks.size() << " decks (" << simulations << " + " << skipped_simulations << " simulations)." << std::endl;
std::cout << "Optimized Deck: ";
print_deck_inline(get_deck_cost(d1), best_score, d1);
print_upgraded_cards(d1);
}

inline FinalResults<long double> fitness(Deck* d1,
Expand Down Expand Up @@ -1608,11 +1634,11 @@ void simulated_annealing(unsigned num_min_iterations, unsigned num_iterations, D
all_candidates.emplace_back(cur_deck->alpha_dominion);
}
}
if (!cur_deck->alpha_dominion && owned_alpha_dominion)
{
cur_deck->alpha_dominion = owned_alpha_dominion;
std::cout << "Setting up owned Alpha Dominion into a deck: " << cur_deck->alpha_dominion->m_name << std::endl;
}
if (!cur_deck->alpha_dominion && owned_alpha_dominion)
{
cur_deck->alpha_dominion = owned_alpha_dominion;
std::cout << "Setting up owned Alpha Dominion into a deck: " << cur_deck->alpha_dominion->m_name << std::endl;
}
}


Expand All @@ -1625,13 +1651,13 @@ void simulated_annealing(unsigned num_min_iterations, unsigned num_iterations, D
FinalResults<long double> prev_score = best_score;
FinalResults<long double> cur_score = best_score;

unsigned best_gap = cur_gap;
unsigned best_gap = cur_gap;

deck_cost = 0;

unsigned from_slot(freezed_cards);
unsigned from_slot_tmp(freezed_cards);
unsigned to_slot(1);
unsigned from_slot_tmp(freezed_cards);
unsigned to_slot(1);

if(debug_print >0)std::cout << "Starting Anneal" << std::endl;
while(temperature > 1 && !(best_score.points - target_score > -1e-9))
Expand Down Expand Up @@ -1698,10 +1724,10 @@ void simulated_annealing(unsigned num_min_iterations, unsigned num_iterations, D
best_deck = cur_deck->clone();
best_gap = cur_gap;
std::cout << "Deck improved: " << best_deck->hash() << ": (temp=" << temperature << ") :";
print_deck_inline(get_deck_cost(best_deck), best_score, best_deck);
print_deck_inline(get_deck_cost(best_deck), best_score, best_deck);
}
if(debug_print>0)std::cout << "UPDATED DECK: " << cur_deck->hash() << ": (temp=" << temperature << ") :";
if(debug_print>0)print_deck_inline(get_deck_cost(cur_deck), cur_score, cur_deck);
if(debug_print>0)print_deck_inline(get_deck_cost(cur_deck), cur_score, cur_deck);
prev_score = cur_score;
prev_deck = cur_deck->clone();
}
Expand All @@ -1713,7 +1739,7 @@ void simulated_annealing(unsigned num_min_iterations, unsigned num_iterations, D
std::cout << "Evaluated " << evaluated_decks.size() << " decks (" << simulations << " + " << skipped_simulations << " simulations)." << std::endl;
std::cout << "Optimized Deck: ";
print_deck_inline(get_deck_cost(best_deck), best_score, best_deck);

print_upgraded_cards(best_deck);
}


Expand Down Expand Up @@ -2215,6 +2241,10 @@ int main(int argc, char** argv)
confidence_level = atof(argv[argIndex+1]);
argIndex += 1;
}
else if (strcmp(argv[argIndex], "+uc") == 0)
{
print_upgraded = true;
}
else if (strcmp(argv[argIndex], "+ci") == 0)
{
show_ci = true;
Expand Down

2 comments on commit 1f721f5

@themacboy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very confused with all your changes. Whay they do?

Sincerekky I think we need a tuo wiki jajaja

@APN-Pucky
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new flag '+uc'.
It will add a line to the output, listing cards which are created with the used funds.

Please sign in to comment.